Custom entity reference field always renders taxonomy term as a link

Created on 10 August 2022, about 2 years ago
Updated 29 November 2023, 9 months ago

Problem/Motivation

I can't seem to update the view display options in a custom taxonomy term entity reference field so that terms are printed without a link to the referenced term.

Steps to reproduce

  1. Create a taxonomy vocab with a couple of terms to reference.
  2. Create a custom entity.
  3. Add an entity_reference field similar to this:
    $fields['region'] = BaseFieldDefinition::create('entity_reference')
      ->setLabel(t('Region'))
      ->setDescription(t('The geographic region of the study.'))
      ->setRequired(TRUE)
      ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED)
      ->setSettings([
        'target_type' => 'taxonomy_term',
        'handler' => 'default:taxonomy_term',
        'handler_settings' => [
          'target_bundles' => [
            'region' => 'region'
          ]
        ]
      ])
      ->setDisplayOptions('form', [
        'type' => 'options_shs',
        'settings' => [
          'force_deepest' => 0,
        ],
        'weight' => 30,
      ])
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayOptions('view', [
        'label' => 'above',
        'type' => 'label',
        'settings' => [
          'link' => 0,
        ],
        'weight' => 30,
      ])
      ->setDisplayConfigurable('view', TRUE);

Note that "setDisplayOptions - view" contains a setting for link = 0.
If you create a piece of content of this entity type, I expect the term to be displayed in plain text, but it is always rendering as a link. I believe my structure is correct but perhaps it's not - it's hard to find relevant documentation.

Please inform me of the correct structure, or flag it as bug to be investigated if need be. Thanks.

🐛 Bug report
Status

Postponed: needs info

Version

11.0 🔥

Component
Field 

Last updated 1 day ago

Created by

🇦🇺Australia jaydee1818 Melbourne

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇺Australia acbramley

    'type' => 'label',
    This is incorrect, this should be the id of the field formatter, i.e entity_reference_label

    My guess is that it's falling back to the default because the configured formatter doesn't exist. If not, it may be overrides in an entity_view_display config.

    If not, please provide steps to reproduce from a fresh Drupal core installation.

Production build 0.71.5 2024