本文整理汇总了PHP中Drupal\Core\Entity\ContentEntityInterface::getFields方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentEntityInterface::getFields方法的具体用法?PHP ContentEntityInterface::getFields怎么用?PHP ContentEntityInterface::getFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Entity\ContentEntityInterface
的用法示例。
在下文中一共展示了ContentEntityInterface::getFields方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFields
/**
* Returns a list of the metatag fields on an entity.
*/
protected function getFields(ContentEntityInterface $entity)
{
$field_list = array();
if ($entity instanceof ContentEntityInterface) {
// Get a list of the metatag field types.
$field_types = $this->fieldTypes();
// Get a list of the fields on this entity.
$fields = $entity->getFields();
// Iterate through all the fields looking for ones in our list.
foreach ($fields as $key => $field) {
// Get the field definition which holds the type.
$field_info = $field->getFieldDefinition();
// Get the field type, ie: metatag.
$field_type = $field_info->getType();
// Check the field type against our list of fields.
if (isset($field_type) && in_array($field_type, $field_types)) {
// Get the machine name of the field.
$field_name = $field->getName();
$field_list[$field_name] = $field_info;
}
}
}
return $field_list;
}
示例2: process_entity
/**
* Process an entity to either encrypt or decrypt its fields.
*
* Both processes are very similar, so we bundle the field processing part.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* @param string $op
*/
protected function process_entity(\Drupal\Core\Entity\ContentEntityInterface $entity, $op = 'encrypt')
{
// Make sure we can get fields.
if (!is_callable([$entity, 'getFields'])) {
return;
}
foreach ($entity->getFields() as $field) {
$this->process_field($field, $op);
}
}