本文整理匯總了PHP中Drupal\Core\Field\FormatterBase::view方法的典型用法代碼示例。如果您正苦於以下問題:PHP FormatterBase::view方法的具體用法?PHP FormatterBase::view怎麽用?PHP FormatterBase::view使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Drupal\Core\Field\FormatterBase
的用法示例。
在下文中一共展示了FormatterBase::view方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: view
/**
* {@inheritdoc}
*
* @see ::prepareView()
* @see ::getEntitiestoView()
*/
public function view(FieldItemListInterface $items, $langcode = NULL)
{
$elements = parent::view($items, $langcode);
$field_level_access_cacheability = new CacheableMetadata();
// Try to map the cacheability of the access result that was set at
// _accessCacheability in getEntitiesToView() to the corresponding render
// subtree. If no such subtree is found, then merge it with the field-level
// access cacheability.
foreach ($items as $delta => $item) {
// Ignore items for which access cacheability could not be determined in
// prepareView().
if (!empty($item->_accessCacheability)) {
if (isset($elements[$delta])) {
CacheableMetadata::createFromRenderArray($elements[$delta])->merge($item->_accessCacheability)->applyTo($elements[$delta]);
} else {
$field_level_access_cacheability = $field_level_access_cacheability->merge($item->_accessCacheability);
}
}
}
// Apply the cacheability metadata for the inaccessible entities and the
// entities for which the corresponding render subtree could not be found.
// This causes the field to be rendered (and cached) according to the cache
// contexts by which the access results vary, to ensure only users with
// access to this field can view it. It also tags this field with the cache
// tags on which the access results depend, to ensure users that cannot view
// this field at the moment will gain access once any of those cache tags
// are invalidated.
$field_level_access_cacheability->applyTo($elements);
return $elements;
}
示例2: view
/**
* This method is the wrapper for the formatter.
*/
public function view(FieldItemListInterface $items, $langcode = NULL)
{
$elements = parent::view($items);
$types = $this->getRemoteTypes();
$elements['#prefix'] = '<p>The cover source is: ' . $types[$this->settings['cover_source']] . '</p>';
return $elements;
}