当前位置: 首页>>代码示例>>PHP>>正文


PHP ContentEntityInterface::getFieldDefinitions方法代码示例

本文整理汇总了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;
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:41,代码来源:ContentEntitySource.php

示例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;
 }
开发者ID:eric-shell,项目名称:eric-shell-d8,代码行数:23,代码来源:MetatagManager.php

示例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();
         }
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:17,代码来源:QuickEditFieldForm.php


注:本文中的Drupal\Core\Entity\ContentEntityInterface::getFieldDefinitions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。