W3cubDocs

/Drupal 8

public function EntityDisplayBase::__construct

public EntityDisplayBase::__construct(array $values, $entity_type)

Constructs an Entity object.

Parameters

array $values: An array of values to set, keyed by property name. If the entity type has bundles, the bundle key has to be specified.

string $entity_type: The type of the entity to create.

Overrides ConfigEntityBase::__construct

File

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

Class

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

Namespace

Drupal\Core\Entity

Code

public function __construct(array $values, $entity_type) {
  if (!isset($values['targetEntityType']) || !isset($values['bundle'])) {
    throw new \InvalidArgumentException('Missing required properties for an EntityDisplay entity.');
  }

  if (!$this->entityManager()->getDefinition($values['targetEntityType'])->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) {
    throw new \InvalidArgumentException('EntityDisplay entities can only handle fieldable entity types.');
  }

  $this->renderer = \Drupal::service('renderer');

  // A plugin manager and a context type needs to be set by extending classes.
  if (!isset($this->pluginManager)) {
    throw new \RuntimeException('Missing plugin manager.');
  }
  if (!isset($this->displayContext)) {
    throw new \RuntimeException('Missing display context type.');
  }

  parent::__construct($values, $entity_type);

  $this->originalMode = $this->mode;

  $this->init();
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Entity!EntityDisplayBase.php/function/EntityDisplayBase::__construct/8.1.x