當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ContentEntityInterface::getFields方法代碼示例

本文整理匯總了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;
 }
開發者ID:krknth,項目名稱:d8p,代碼行數:27,代碼來源:MetatagManager.php

示例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);
     }
 }
開發者ID:nerdstein,項目名稱:field_encrypt,代碼行數:18,代碼來源:FieldEncryptProcessEntities.php


注:本文中的Drupal\Core\Entity\ContentEntityInterface::getFields方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。