本文整理汇总了PHP中Drupal\Core\Entity\EntityInterface::label方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityInterface::label方法的具体用法?PHP EntityInterface::label怎么用?PHP EntityInterface::label使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\EntityInterface
的用法示例。
在下文中一共展示了EntityInterface::label方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
/**
* {@inheritdoc}
*/
public function view(EntityInterface $entity)
{
if ($entity instanceof FileInterface) {
return ['#theme' => 'image_style', '#style_name' => $this->configuration['image_style'], '#title' => $entity->label(), '#alt' => $entity->label(), '#uri' => $entity->getFileUri()];
}
return $entity->label();
}
示例2: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/** @var \Drupal\embed\EmbedButtonInterface $entity */
$row = [];
$row['label'] = $entity->label();
$row['embed_type'] = $entity->getTypeLabel();
if ($icon_url = $entity->getIconUrl()) {
$row['icon']['data'] = ['#theme' => 'image', '#uri' => $icon_url, '#alt' => $this->t('Icon for the @label button.', ['@label' => $entity->label()])];
} else {
$row['icon'] = $this->t('None');
}
return $row + parent::buildRow($entity);
}
示例3: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/** @var $entity SearchApiPage */
$row['label'] = $entity->label();
$row['path'] = \Drupal::l($entity->getPath(), Url::fromRoute('search_api_page.' . $entity->id()));
return $row + parent::buildRow($entity);
}
示例4: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\drupal8_entity\Entity\Drupal8EntityItem */
$row['id'] = $entity->id();
$row['name'] = $this->l($entity->label(), new Url('entity.drupal8_entity_item.edit_form', array('drupal8_entity_item' => $entity->id())));
return $row + parent::buildRow($entity);
}
示例5: testLabelFormatter
/**
* Tests the label formatter.
*/
public function testLabelFormatter()
{
$formatter = 'entity_reference_label';
// The 'link' settings is TRUE by default.
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
$expected_item_1 = array('#type' => 'link', '#title' => $this->referencedEntity->label(), '#url' => $this->referencedEntity->urlInfo(), '#options' => $this->referencedEntity->urlInfo()->getOptions(), '#cache' => array('tags' => $this->referencedEntity->getCacheTags()));
$this->assertEqual(drupal_render($build[0]), drupal_render($expected_item_1), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
// The second referenced entity is "autocreated", therefore not saved and
// lacking any URL info.
$expected_item_2 = array('#markup' => $this->unsavedReferencedEntity->label(), '#cache' => array('tags' => $this->unsavedReferencedEntity->getCacheTags()));
$this->assertEqual($build[1], $expected_item_2, sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
// Test with the 'link' setting set to FALSE.
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter, array('link' => FALSE));
$this->assertEqual($build[0]['#markup'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual($build[1]['#markup'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
// Test an entity type that doesn't have any link templates, which means
// \Drupal\Core\Entity\EntityInterface::urlInfo() will throw an exception
// and the label formatter will output only the label instead of a link.
$field_storage_config = FieldStorageConfig::loadByName($this->entityType, $this->fieldName);
$field_storage_config->setSetting('target_type', 'entity_test_label');
$field_storage_config->save();
$referenced_entity_with_no_link_template = entity_create('entity_test_label', array('name' => $this->randomMachineName()));
$referenced_entity_with_no_link_template->save();
$build = $this->buildRenderArray([$referenced_entity_with_no_link_template], $formatter, array('link' => TRUE));
$this->assertEqual($build[0]['#markup'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter));
}
示例6: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\drupalbristol_sponsors\Entity\SponsorEntity */
$row['id'] = $entity->id();
$row['name'] = $this->l($entity->label(), new Url('entity.sponsor.edit_form', array('sponsor' => $entity->id())));
return $row + parent::buildRow($entity);
}
示例7: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row = [];
$row['name'] = $entity->label();
$row['type'] = $entity->id();
return $row + parent::buildRow($entity);
}
示例8: submitForm
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
/** @var \Drupal\entity_clone\EntityClone\EntityCloneInterface $entity_clone_handler */
$entity_clone_handler = $this->entityTypeManager->getHandler($this->entityTypeDefinition->id(), 'entity_clone');
if ($this->entityTypeManager->hasHandler($this->entityTypeDefinition->id(), 'entity_clone_form')) {
$entity_clone_form_handler = $this->entityTypeManager->getHandler($this->entityTypeDefinition->id(), 'entity_clone_form');
}
$properties = [];
if (isset($entity_clone_form_handler) && $entity_clone_form_handler) {
$properties = $entity_clone_form_handler->getNewValues($form_state);
}
$cloned_entity = $entity_clone_handler->cloneEntity($this->entity, $this->entity->createDuplicate(), $properties);
drupal_set_message($this->stringTranslationManager->translate('The entity <em>@entity (@entity_id)</em> of type <em>@type</em> was cloned', [
'@entity' => $this->entity->label(),
'@entity_id' => $this->entity->id(),
'@type' => $this->entity->getEntityTypeId(),
]));
if ($cloned_entity && $cloned_entity->hasLinkTemplate('canonical')) {
$form_state->setRedirect($cloned_entity->toUrl()
->getRouteName(), $cloned_entity->toUrl()->getRouteParameters());
}
$form_state->setRedirect('<front>');
}
示例9: testEntityFormatter
/**
* Tests the entity formatter.
*/
public function testEntityFormatter()
{
$formatter = 'entity_reference_entity_view';
$field_name = $this->fieldName;
// Create the entity that will have the entity reference field.
$referencing_entity = entity_create($this->entityType, array('name' => $this->randomMachineName()));
$referencing_entity->save();
$referencing_entity->{$field_name}->entity = $this->referencedEntity;
$referencing_entity->{$field_name}->access = TRUE;
// Build the renderable array for the entity reference field.
$items = $referencing_entity->get($field_name);
$build = $items->view(array('type' => $formatter));
$expected_rendered_name_field = '<div class="field field-entity-test--name field-name-name field-type-string field-label-hidden">
<div class="field-items">
<div class="field-item">' . $this->referencedEntity->label() . '</div>
</div>
</div>
';
$expected_rendered_body_field = '<div class="field field-entity-test--body field-name-body field-type-text field-label-above">
<div class="field-label">Body: </div>
<div class="field-items">
<div class="field-item"><p>Hello, world!</p></div>
</div>
</div>
';
drupal_render($build[0]);
$this->assertEqual($build[0]['#markup'], 'default | ' . $this->referencedEntity->label() . $expected_rendered_name_field . $expected_rendered_body_field, format_string('The markup returned by the @formatter formatter is correct.', array('@formatter' => $formatter)));
$expected_cache_tags = Cache::mergeTags(\Drupal::entityManager()->getViewBuilder($this->entityType)->getCacheTag(), $this->referencedEntity->getCacheTag(), FilterFormat::load('full_html')->getCacheTag());
$this->assertEqual($build[0]['#cache']['tags'], $expected_cache_tags, format_string('The @formatter formatter has the expected cache tags.', array('@formatter' => $formatter)));
}
示例10: getLabelAndConfig
/**
* Renders the Metatag defaults label plus its configuration.
*
* @param EntityInterface $entity
* The Metatag defaults entity.
*
* @return
* Render array for a table cell.
*/
public function getLabelAndConfig(EntityInterface $entity)
{
$output = '<div>';
$prefix = '';
$inherits = '';
if ($entity->id() != 'global') {
$prefix = '<div class="indentation"></div>';
$inherits .= 'Global';
}
if (strpos($entity->id(), '__') !== FALSE) {
$prefix .= '<div class="indentation"></div>';
list($entity_label, $bundle_label) = explode(': ', $entity->get('label'));
$inherits .= ', ' . $entity_label;
}
if (!empty($inherits)) {
$output .= '<div><p>' . t('Inherits meta tags from: @inherits', ['@inherits' => $inherits]) . '</p></div>';
}
$tags = $entity->get('tags');
if (count($tags)) {
$output .= '<table>
<tbody>';
foreach ($tags as $tag_id => $tag_value) {
$output .= '<tr><td>' . $tag_id . ':</td><td>' . $tag_value . '</td></tr>';
}
$output .= '</tbody></table>';
}
$output .= '</div></div>';
return ['data' => ['#type' => 'details', '#prefix' => $prefix, '#title' => $entity->label(), 'config' => ['#markup' => $output]]];
}
示例11: testLabelFormatter
/**
* Tests the label formatter.
*/
public function testLabelFormatter()
{
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = $this->container->get('renderer');
$formatter = 'entity_reference_label';
// The 'link' settings is TRUE by default.
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter);
$expected_field_cacheability = ['contexts' => [], 'tags' => [], 'max-age' => Cache::PERMANENT];
$this->assertEqual($build['#cache'], $expected_field_cacheability, 'The field render array contains the entity access cacheability metadata');
$expected_item_1 = array('#type' => 'link', '#title' => $this->referencedEntity->label(), '#url' => $this->referencedEntity->urlInfo(), '#options' => $this->referencedEntity->urlInfo()->getOptions(), '#cache' => array('contexts' => ['user.permissions'], 'tags' => $this->referencedEntity->getCacheTags()));
$this->assertEqual($renderer->renderRoot($build[0]), $renderer->renderRoot($expected_item_1), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual(CacheableMetadata::createFromRenderArray($build[0]), CacheableMetadata::createFromRenderArray($expected_item_1));
// The second referenced entity is "autocreated", therefore not saved and
// lacking any URL info.
$expected_item_2 = array('#plain_text' => $this->unsavedReferencedEntity->label(), '#cache' => array('contexts' => ['user.permissions'], 'tags' => $this->unsavedReferencedEntity->getCacheTags(), 'max-age' => Cache::PERMANENT));
$this->assertEqual($build[1], $expected_item_2, sprintf('The render array returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
// Test with the 'link' setting set to FALSE.
$build = $this->buildRenderArray([$this->referencedEntity, $this->unsavedReferencedEntity], $formatter, array('link' => FALSE));
$this->assertEqual($build[0]['#plain_text'], $this->referencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a saved entity.', $formatter));
$this->assertEqual($build[1]['#plain_text'], $this->unsavedReferencedEntity->label(), sprintf('The markup returned by the %s formatter is correct for an item with a unsaved entity.', $formatter));
// Test an entity type that doesn't have any link templates, which means
// \Drupal\Core\Entity\EntityInterface::urlInfo() will throw an exception
// and the label formatter will output only the label instead of a link.
$field_storage_config = FieldStorageConfig::loadByName($this->entityType, $this->fieldName);
$field_storage_config->setSetting('target_type', 'entity_test_label');
$field_storage_config->save();
$referenced_entity_with_no_link_template = EntityTestLabel::create(array('name' => $this->randomMachineName()));
$referenced_entity_with_no_link_template->save();
$build = $this->buildRenderArray([$referenced_entity_with_no_link_template], $formatter, array('link' => TRUE));
$this->assertEqual($build[0]['#plain_text'], $referenced_entity_with_no_link_template->label(), sprintf('The markup returned by the %s formatter is correct for an entity type with no valid link template.', $formatter));
}
示例12: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/* @var $entity \Drupal\scheduled_updates\Entity\ScheduledUpdate */
$row['name'] = $this->l($entity->label(), new Url('entity.scheduled_update.edit_form', array('scheduled_update' => $entity->id())));
$row['type'] = $this->updateUtils->getUpdateTypeLabel($entity);
return $row + parent::buildRow($entity);
}
示例13: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
/** @var \Drupal\commerce_tax\Entity\TaxTypeInterface $entity */
$row['name'] = $entity->label();
$row['tag'] = $entity->getTag();
return $row + parent::buildRow($entity);
}
示例14: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row['label'] = $entity->label();
$row['id'] = $entity->id();
// Render encryption method row.
if ($encryption_method = $entity->getEncryptionMethod()) {
$row['encryption_method'] = $encryption_method->getLabel();
} else {
$row['encryption_method'] = $this->t('Error loading encryption method');
}
// Render encryption key row.
if ($key = $entity->getEncryptionKey()) {
$row['key'] = $key->label();
} else {
$row['key'] = $this->t('Error loading key');
}
// Render status report row.
if ($this->config->get('check_profile_status')) {
$errors = $entity->validate();
if (!empty($errors)) {
$row['status']['data'] = array('#theme' => 'item_list', '#items' => $errors, '#attributes' => array("class" => array("color-error")));
} else {
$row['status'] = $this->t('OK');
}
}
return $row + parent::buildRow($entity);
}
示例15: buildRow
/**
* {@inheritdoc}
*/
public function buildRow(EntityInterface $entity)
{
$row['label'] = $entity->label();
$row['id'] = $entity->id();
// You probably want a few more properties here...
return $row + parent::buildRow($entity);
}