function EntityDisplayBase::set

Attributes

#[ActionMethod(adminLabel: new TranslatableMarkup('Set a value'), pluralize: 'setMultiple')]

Overrides ConfigEntityBase::set

1 call to EntityDisplayBase::set()
EntityDisplayBase::setTargetBundle in core/lib/Drupal/Core/Entity/EntityDisplayBase.php
Sets the bundle to be displayed.

File

core/lib/Drupal/Core/Entity/EntityDisplayBase.php, line 604

Class

EntityDisplayBase
Provides a common base class for entity view and form displays.

Namespace

Drupal\Core\Entity

Code

public function set($property_name, $value) : static {
  // If changing the entity ID, also update the target entity type, bundle,
  // and view mode.
  if ($this->isNew() && $property_name === $this->getEntityType()
    ->getKey('id')) {
    if (substr_count($value, '.') !== 2) {
      throw new \InvalidArgumentException("'{$value}' is not a valid entity display ID.");
    }
    [
      $this->targetEntityType,
      $this->bundle,
      $this->mode,
    ] = explode('.', $value);
  }
  parent::set($property_name, $value);
  return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.