本文整理汇总了PHP中Drupal\Core\Field\FieldItemListInterface::count方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldItemListInterface::count方法的具体用法?PHP FieldItemListInterface::count怎么用?PHP FieldItemListInterface::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Field\FieldItemListInterface
的用法示例。
在下文中一共展示了FieldItemListInterface::count方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: viewElements
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode)
{
$element = [];
// As the Field API only applies the "field default value" to newly created
// entities, we'll apply the default value for existing entities.
if ($items->count() == 0) {
$field_default_value = $items->getFieldDefinition()->getDefaultValue($items->getEntity());
$items->status = $field_default_value[0]['status'];
}
if ($items->status == 1 && $this->currentUser->hasPermission('view disqus comments')) {
$element[] = ['#type' => 'disqus', '#url' => $items->getEntity()->toUrl('canonical', ['absolute' => TRUE])->toString(), '#title' => (string) $items->getEntity()->label(), '#identifier' => $items->identifier ?: "{$items->getEntity()->getEntityTypeId()}/{$items->getEntity()->id()}"];
}
return $element;
}
示例2: viewElements
/**
* {@inheritdoc}
*/
public function viewElements(FieldItemListInterface $items, $langcode)
{
$elements = array();
// Only collect allowed options if there are actually items to display.
if ($items->count()) {
$provider = $items->getFieldDefinition()->getFieldStorageDefinition()->getOptionsProvider('value', $items->getEntity());
// Flatten the possible options, to support opt groups.
$options = OptGroup::flattenOptions($provider->getPossibleOptions());
foreach ($items as $delta => $item) {
$value = $item->value;
// If the stored value is in the current set of allowed values, display
// the associated label, otherwise just display the raw value.
$output = isset($options[$value]) ? $options[$value] : $value;
$elements[$delta] = array('#markup' => $output, '#allowed_tags' => FieldFilteredMarkup::allowedTags());
}
}
return $elements;
}