本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityInterface::hasLinkTemplate方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityInterface::hasLinkTemplate方法的具体用法?PHP ContentEntityInterface::hasLinkTemplate怎么用?PHP ContentEntityInterface::hasLinkTemplate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\ContentEntityInterface
的用法示例。
在下文中一共展示了ContentEntityInterface::hasLinkTemplate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: overviewRow
/**
* Builds a table row for overview form.
*
* @param array ContentEntityInterface $entity
* Data needed to build the list row.
* @param array $bundles
* The array of bundles.
*
* @return array
*/
public function overviewRow(ContentEntityInterface $entity, array $bundles)
{
$label = $entity->label() ?: $this->t('@type: @id', array('@type' => $entity->getEntityTypeId(), '@id' => $entity->id()));
// Get existing translations and current job items for the entity
// to determine translation statuses
$translations = $entity->getTranslationLanguages();
$source_lang = $entity->language()->getId();
$current_job_items = tmgmt_job_item_load_latest('content', $entity->getEntityTypeId(), $entity->id(), $source_lang);
$row = array('id' => $entity->id(), 'title' => $entity->hasLinkTemplate('canonical') ? $entity->toLink($label, 'canonical')->toString() : ($entity->label() ?: $entity->id()));
if (count($bundles) > 1) {
$row['bundle'] = isset($bundles[$entity->bundle()]) ? $bundles[$entity->bundle()] : t('Unknown');
}
// Load entity translation specific data.
$manager = \Drupal::service('content_translation.manager');
foreach (\Drupal::languageManager()->getLanguages() as $langcode => $language) {
$translation_status = 'current';
if ($langcode == $source_lang) {
$translation_status = 'original';
} elseif (!isset($translations[$langcode])) {
$translation_status = 'missing';
} elseif ($translation = $entity->getTranslation($langcode)) {
$metadata = $manager->getTranslationMetadata($translation);
if ($metadata->isOutdated()) {
$translation_status = 'outofdate';
}
}
$build = $this->buildTranslationStatus($translation_status, isset($current_job_items[$langcode]) ? $current_job_items[$langcode] : NULL);
$row['langcode-' . $langcode] = ['data' => \Drupal::service('renderer')->render($build), 'class' => array('langstatus-' . $langcode)];
}
return $row;
}