- Issue created by @cedewey
- πΊπΈUnited States mlncn Minneapolis, MN, USA
This is a Drupal-caused bug in my estimation. We extend (for example) EntityReferenceLabelFormatter which extends EntityReferenceFormatterBase which extends FormatterBase, and that has a view function which we should not need to override which does something really weird:
public function view(FieldItemListInterface $items, $langcode = NULL) { // If there are actual renderable children, use #theme => field, otherwise, // let access cacheability metadata pass through for correct bubbling. if (Element::children($elements)) { $entity = $items->getEntity(); $entity_type = $entity->getEntityTypeId(); $field_name = $this->fieldDefinition->getName(); $info = [ '#theme' => 'field', '#title' => $this->fieldDefinition->getLabel(), '#label_display' => $this->label, '#view_mode' => $this->viewMode, '#language' => $items->getLangcode(), '#field_name' => $field_name, '#field_type' => $this->fieldDefinition->getType(), '#field_translatable' => $this->fieldDefinition->isTranslatable(), '#entity_type' => $entity_type, '#bundle' => $entity->bundle(), '#object' => $entity, '#items' => $items, '#formatter' => $this->getPluginId(), '#is_multiple' => $this->fieldDefinition->getFieldStorageDefinition()->isMultiple(), '#third_party_settings' => $this->getThirdPartySettings(), ]; $elements = array_merge($info, $elements); } return $elements; }
That's a barely truncated excerpt, but you can see the weirdness. Why would what we return from viewElements, so long as it is present and renderable at all, which what we return most definitely is, affect whether the field wrapper and field label get applied?
- Status changed to Fixed
over 1 year ago 4:20pm 6 June 2023 - πΊπΈUnited States cedewey Denver, CO
Confirmed that the fix worked. There is now a field wrapper there. Thanks!
- Status changed to Needs work
over 1 year ago 4:28pm 6 June 2023 - πΊπΈUnited States cedewey Denver, CO
Spoke too soon.
The fix holds for term reference fields, but is still present for List (string, integer and float) fields.
- Status changed to Needs review
over 1 year ago 4:37pm 6 June 2023 - πΊπΈUnited States mlncn Minneapolis, MN, USA
Yes! There's List formatter which is one of the ones applying to terms (and any entity reference), and then there is also Sequential terms formatter and also OptionsList which applies to text type lists so your observations hold (don't blame me those names are from core).
Sorry i tend to stop thinking once the fix is identified, who knew you also needed to apply it.
- Status changed to Fixed
over 1 year ago 6:07pm 6 June 2023 - πΊπΈUnited States cedewey Denver, CO
Confirmed this is now working for all fields and field formatters that In Other Words is compatible with. Thanks!
- Status changed to Fixed
over 1 year ago 11:53pm 6 June 2023