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


PHP EntityInterface::getFields方法代碼示例

本文整理匯總了PHP中Drupal\Core\Entity\EntityInterface::getFields方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityInterface::getFields方法的具體用法?PHP EntityInterface::getFields怎麽用?PHP EntityInterface::getFields使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Drupal\Core\Entity\EntityInterface的用法示例。


在下文中一共展示了EntityInterface::getFields方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getProperties

 /**
  * {@inheritdoc}
  */
 public function getProperties($include_computed = FALSE)
 {
     if (!isset($this->entity)) {
         throw new MissingDataException('Unable to get properties as no entity has been provided.');
     }
     if (!$this->entity instanceof FieldableEntityInterface) {
         // @todo: Add support for config entities in
         // https://www.drupal.org/node/1818574.
         return array();
     }
     return $this->entity->getFields($include_computed);
 }
開發者ID:ddrozdik,項目名稱:dmaps,代碼行數:15,代碼來源:EntityAdapter.php

示例2: getHostConfiguration

 function getHostConfiguration(EntityInterface $entity, $prefix = 'field_ran_')
 {
     // TODO: This can't be right... there must be an easier way to access a
     // field collection's fields.
     $field_collection = $entity->getFields()['field_ran_host_configuration']->getIterator()[0];
     $fields = $field_collection->getFieldCollectionItem()->getFields();
     $vars = array();
     $len = strlen($prefix);
     foreach ($fields as $name => $field) {
         if (substr($name, 0, $len) == $prefix) {
             $vars[substr($name, $len)] = array();
             foreach ($field->getIterator() as $object) {
                 $vars[substr($name, $len)][] = $object->getString();
             }
             $vars[substr($name, $len)] = array_filter($vars[substr($name, $len)]);
         }
     }
     return $vars;
 }
開發者ID:ergonlogic,項目名稱:ran,代碼行數:19,代碼來源:Task.php

示例3: get

 /**
  * Responds to entity GET requests.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity object.
  *
  * @return \Drupal\rest\ResourceResponse
  *   The response containing the entity with its accessible fields.
  *
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  */
 public function get(EntityInterface $entity)
 {
     if (!$entity->access('view')) {
         throw new AccessDeniedHttpException();
     }
     $fields = $entity->getFields();
     $display_id = $entity->getEntityTypeId() . '.' . $entity->bundle() . '.restx';
     // Remove hidden fields (Display mode 'default').
     $view_display = \Drupal::entityManager()->getStorage('entity_view_display')->load($display_id);
     if ($view_display) {
         $content = $view_display->get('content');
         foreach ($fields as $field_name => $field) {
             if (!$field->access('view') || substr($field_name, 0, 6) === 'field_' && !isset($content[$field_name])) {
                 unset($fields[$field_name]);
             }
         }
     }
     $output = array('data' => $fields);
     $response = new ResourceResponse($output, ResourceResponse::HTTP_OK);
     $response->addCacheableDependency($output);
     return $response;
 }
開發者ID:nuxy,項目名稱:restx,代碼行數:33,代碼來源:EntityResource.php


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