/**
  * Overrides \Drupal\Core\Entity\label().
  */
 public function label()
 {
     $field_label = $this->getHost()->getFieldDefinition($this->bundle())->label();
     if (empty($field_label)) {
         return parent::label();
     } else {
         return t('@label @delta of @host', array('@label' => $field_label, '@delta' => $this->getDelta(), '@host' => $this->getHost()->label()));
     }
 }
 /**
  * @covers ::label
  */
 public function testLabel()
 {
     // Make a mock with one method that we use as the entity's label callback.
     // We check that it is called, and that the entity's label is the callback's
     // return value.
     $callback_label = $this->randomMachineName();
     $callback_container = $this->getMock(get_class());
     $callback_container->expects($this->once())->method(__FUNCTION__)->will($this->returnValue($callback_label));
     $this->entityType->expects($this->once())->method('getLabelCallback')->will($this->returnValue(array($callback_container, __FUNCTION__)));
     $this->assertSame($callback_label, $this->entity->label());
 }
Пример #3
0
 /**
  * {@inheritdoc}
  */
 public function label()
 {
     $label = parent::label();
     if (empty($label)) {
         $label = t('Nameless #@id', ['@id' => $this->id()]);
     }
     return $label;
 }