本文整理匯總了PHP中Drupal\Core\Entity\ContentEntityInterface::getFieldDefinitions方法的典型用法代碼示例。如果您正苦於以下問題:PHP ContentEntityInterface::getFieldDefinitions方法的具體用法?PHP ContentEntityInterface::getFieldDefinitions怎麽用?PHP ContentEntityInterface::getFieldDefinitions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Drupal\Core\Entity\ContentEntityInterface
的用法示例。
在下文中一共展示了ContentEntityInterface::getFieldDefinitions方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getEmbeddableFields
/**
* Returns fields that should be embedded into the data for the given entity.
*
* Includes explicitly enabled fields and composite entities that are
* implicitly included to the translatable data.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity to get the translatable data from.
*
* @return array $embeddable_fields
* Translatable data.
*/
public function getEmbeddableFields(ContentEntityInterface $entity)
{
// Get the configurable embeddable references.
$field_definitions = $entity->getFieldDefinitions();
$embeddable_field_names = \Drupal::config('tmgmt_content.settings')->get('embedded_fields');
$embeddable_fields = array_filter($field_definitions, function (FieldDefinitionInterface $field_definition) use($embeddable_field_names) {
return !$field_definition->isTranslatable() && isset($embeddable_field_names[$field_definition->getTargetEntityTypeId()][$field_definition->getName()]);
});
// Get always embedded references.
$content_translation_manager = \Drupal::service('content_translation.manager');
foreach ($field_definitions as $field_name => $field_definition) {
$storage_definition = $field_definition->getFieldStorageDefinition();
$property_definitions = $storage_definition->getPropertyDefinitions();
foreach ($property_definitions as $property_definition) {
// Look for entity_reference properties where the storage definition
// has a target type setting and that is enabled for content
// translation.
if (in_array($property_definition->getDataType(), ['entity_reference', 'entity_revision_reference']) && $storage_definition->getSetting('target_type') && $content_translation_manager->isEnabled($storage_definition->getSetting('target_type'))) {
// Include field if the target entity has the parent type field key
// set, which is defined by entity_reference_revisions.
$target_entity_type = \Drupal::entityTypeManager()->getDefinition($storage_definition->getSetting('target_type'));
if ($target_entity_type->get('entity_revision_parent_type_field')) {
$embeddable_fields[$field_name] = $field_definition;
}
}
}
}
return $embeddable_fields;
}
示例2: getFields
/**
* Returns a list of the metatag fields on an entity.
*/
protected function getFields(ContentEntityInterface $entity)
{
$field_list = [];
if ($entity instanceof ContentEntityInterface) {
// Get a list of the metatag field types.
$field_types = $this->fieldTypes();
// Get a list of the field definitions on this entity.
$definitions = $entity->getFieldDefinitions();
// Iterate through all the fields looking for ones in our list.
foreach ($definitions as $field_name => $definition) {
// Get the field type, ie: metatag.
$field_type = $definition->getType();
// Check the field type against our list of fields.
if (isset($field_type) && in_array($field_type, $field_types)) {
$field_list[$field_name] = $definition;
}
}
}
return $field_list;
}
示例3: getChangedFieldName
/**
* Finds the field name for the field carrying the changed timestamp, if any.
*
* @param \Drupal\Core\Entity\ContentEntityInterface $entity
* The entity.
*
* @return string|null
* The name of the field found or NULL if not found.
*/
protected function getChangedFieldName(ContentEntityInterface $entity)
{
foreach ($entity->getFieldDefinitions() as $field) {
if ($field->getType() == 'changed') {
return $field->getName();
}
}
}