diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php index 01fefaf..a13c61b 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayModeBase.php @@ -20,14 +20,14 @@ * * @var string */ - public $id; + protected $id; /** * The human-readable name of the form or view mode. * * @var string */ - public $label; + protected $label; /** * The entity type this form or view mode is used for. @@ -37,7 +37,7 @@ * * @var string */ - public $targetEntityType; + protected $targetEntityType; /** * Whether or not this form or view mode has custom settings by default. @@ -56,7 +56,7 @@ * * @var bool */ - public $cache = TRUE; + protected $cache = TRUE; /** * {@inheritdoc} @@ -65,8 +65,8 @@ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $a */ /** @var \Drupal\Core\Entity\EntityDisplayModeInterface $b */ // Sort by the type of entity the view mode is used for. - $a_type = $a->getTargetType(); - $b_type = $b->getTargetType(); + $a_type = $a->getTargetEntityTypeId(); + $b_type = $b->getTargetEntityTypeId(); $type_order = strnatcasecmp($a_type, $b_type); return $type_order != 0 ? $type_order : parent::sort($a, $b); } @@ -74,16 +74,32 @@ public static function sort(ConfigEntityInterface $a, ConfigEntityInterface $b) /** * {@inheritdoc} */ - public function getTargetType() { + public function getTargetEntityTypeId() { return $this->targetEntityType; } /** * {@inheritdoc} */ + public function setTargetEntityTypeId($target_entity_type_id) { + $this->set('targetEntityType', $target_entity_type_id); + return $this; + } + + /** + * {@inheritdoc} + */ + public function setLabel($label) { + $this->set('label', $label); + return $this; + } + + /** + * {@inheritdoc} + */ public function calculateDependencies() { parent::calculateDependencies(); - $target_entity_type = \Drupal::entityManager()->getDefinition($this->targetEntityType); + $target_entity_type = \Drupal::entityManager()->getDefinition($this->getTargetEntityTypeId()); $this->addDependency('module', $target_entity_type->getProvider()); return $this->dependencies; } diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayModeInterface.php b/core/lib/Drupal/Core/Entity/EntityDisplayModeInterface.php index bf21c93..8b696da 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayModeInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayModeInterface.php @@ -20,6 +20,26 @@ * @return string * The entity type name. */ - public function getTargetType(); + public function getTargetEntityTypeId(); + + /** + * Sets the target entity type to be displayed. + * + * @param string target_entity_type_id + * The entity type to be displayed. + * + * @return $this + */ + public function setTargetEntityTypeId($target_entity_type_id); + + /** + * Sets the label. + * + * @param string $label + * The label to be set for the display mode. + * + * @return $this + */ + public function setLabel($label); } diff --git a/core/modules/field_ui/src/EntityDisplayModeListBuilder.php b/core/modules/field_ui/src/EntityDisplayModeListBuilder.php index 6056508..56ff68e 100644 --- a/core/modules/field_ui/src/EntityDisplayModeListBuilder.php +++ b/core/modules/field_ui/src/EntityDisplayModeListBuilder.php @@ -78,7 +78,7 @@ public function buildRow(EntityInterface $entity) { public function load() { $entities = array(); foreach (parent::load() as $entity) { - $entities[$entity->getTargetType()][] = $entity; + $entities[$entity->getTargetEntityTypeId()][] = $entity; } return $entities; } diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php index cd207de..19ecefa 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeAddForm.php @@ -53,7 +53,7 @@ protected function prepareEntity() { throw new NotFoundHttpException(); } - $this->entity->targetEntityType = $this->targetEntityTypeId; + $this->entity->setTargetEntityTypeId($this->targetEntityTypeId); } } diff --git a/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php index 9b7fdd2..b2e6bdb 100644 --- a/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php +++ b/core/modules/field_ui/src/Form/EntityDisplayModeFormBase.php @@ -86,7 +86,7 @@ public function form(array $form, FormStateInterface $form_state) { '#description' => t('A unique machine-readable name. Can only contain lowercase letters, numbers, and underscores.'), '#disabled' => !$this->entity->isNew(), '#default_value' => $this->entity->id(), - '#field_prefix' => $this->entity->isNew() ? $this->entity->getTargetType() . '.' : '', + '#field_prefix' => $this->entity->isNew() ? $this->entity->getTargetEntityTypeId() . '.' : '', '#machine_name' => array( 'exists' => array($this, 'exists'), 'replace_pattern' => '[^a-z0-9_.]+', diff --git a/core/modules/field_ui/src/Form/EntityFormModeAddForm.php b/core/modules/field_ui/src/Form/EntityFormModeAddForm.php index d7864ca..6b33fd4 100644 --- a/core/modules/field_ui/src/Form/EntityFormModeAddForm.php +++ b/core/modules/field_ui/src/Form/EntityFormModeAddForm.php @@ -23,7 +23,7 @@ protected function prepareEntity() { throw new NotFoundHttpException(); } - $this->entity->targetEntityType = $this->targetEntityTypeId; + $this->entity->setTargetEntityTypeId($this->targetEntityTypeId); } } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php index 4e62f11..4f14454 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/EntityDisplayModeBaseUnitTest.php @@ -104,4 +104,35 @@ public function testCalculateDependencies() { } + /** + * @covers ::setTargetEntityTypeId() + * @covers ::getTargetEntityTypeId() + */ + public function testGetTargetEntityTypeId() { + $display = $this->getMockForAbstractClass('Drupal\Core\Entity\EntityDisplayModeBase', array(array(), $this->entityType)); + $display->setTargetEntityTypeId('test'); + $this->assertEquals('test', $display->getTargetEntityTypeId()); + } + + /** + * @covers ::setLabel() + * @covers ::label() + */ + public function testSetLabel() { + $this->entityManager->expects($this->once()) + ->method('getDefinition') + ->with($this->entityType) + ->will($this->returnValue($this->entityInfo)); + $this->entityInfo->expects($this->any()) + ->method('getLabelCallback') + ->will($this->returnValue(NULL)); + $this->entityInfo->expects($this->any()) + ->method('getKey') + ->with('label') + ->will($this->returnValue('label')); + $display = $this->getMockForAbstractClass('Drupal\Core\Entity\EntityDisplayModeBase', array(array(), $this->entityType)); + $display->setLabel('test'); + $this->assertEquals('test', $display->label()); + } + }