Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294274

fields which aren't display configurable should complain when you try to configure them

$
0
0

Problem/Motivation

I was doing this in a kernel test:

    $view_display = \Drupal::service('entity_display.repository')->getViewDisplay('node', 'page');
    $view_display->removeComponent('created');
    $view_display->save();

and found myself down a rabbithole trying to figure out why the display settings for 'created' were coming back as soon as I saved display.

The reason is here:

        if (!$definition->isDisplayConfigurable($this->displayContext) || (!isset($this->content[$name]) && !isset($this->hidden[$name]))) {

and here:

    $fields['created'] = BaseFieldDefinition::create('created')
      ->setLabel(t('Authored on'))
      ->setDescription(t('The time that the node was created.'))
      ->setRevisionable(TRUE)
      ->setTranslatable(TRUE)
      ->setDisplayOptions('view', [
        'label' => 'hidden',
        'type' => 'timestamp',
        'weight' => 0,
      ])
      ->setDisplayOptions('form', [
        'type' => 'datetime_timestamp',
        'weight' => 10,
      ])
      ->setDisplayConfigurable('form', TRUE);

-- the field wasn't configurable for view displays!

Steps to reproduce

Proposed resolution

removeComponent() and setComponent() should throw an exception or do an assert() if you call them for a field that isn't configurable.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 294274

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>