In my module, I have a custom entity LocationEntity
and it uses a custom field type CoordinateItem
which has 2 sub fields X
, Y
.
So what is the correct way of Drupal 8 to:
1) Render this LocationEntity
in a twig template?
- What I'm doing is just send the entity to twig template
'#loc1'
and manually render its each field value using getter method{{ loc1.getName() }}
. It works but I'm sure this is not the correct way to do.
2) If question 1 has another correct way then how to have more than one templates for rendering the entity?
- For example, one simple layout with less fields and one detail layout with all fields.
3) In the entity, I defined to use the custom field CoordinateItem
. But now what to do with its getter and setter, because it's not a single sub field inside?
- Getter if
$this->get('coord')
-> aFieldItemList
object. - Getter if
$this->get('coord')->value
->null
. - Setter? What type is the parameter?
3) I wrote a formatter for CoordinateItem
to show its sub fields. But again I don't know how to use this formatter to render this custom field in the main (entity) template?
- Maybe this is related to question 1 and 2?