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


PHP EntityViewDisplay::collectRenderDisplays方法代码示例

本文整理汇总了PHP中Drupal\Core\Entity\Entity\EntityViewDisplay::collectRenderDisplays方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityViewDisplay::collectRenderDisplays方法的具体用法?PHP EntityViewDisplay::collectRenderDisplays怎么用?PHP EntityViewDisplay::collectRenderDisplays使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Core\Entity\Entity\EntityViewDisplay的用法示例。


在下文中一共展示了EntityViewDisplay::collectRenderDisplays方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: buildMultiple

 /**
  * Builds multiple entities' views; augments entity defaults.
  *
  * This function is assigned as a #pre_render callback in ::viewMultiple().
  *
  * By delaying the building of an entity until the #pre_render processing in
  * drupal_render(), the processing cost of assembling an entity's renderable
  * array is saved on cache-hit requests.
  *
  * @param array $build_list
  *   A renderable  array containing build information and context for an
  *   entity view.
  *
  * @return array
  *   The updated renderable array.
  *
  * @see drupal_render()
  */
 public function buildMultiple(array $build_list)
 {
     // Build the view modes and display objects.
     $view_modes = array();
     $langcode = $build_list['#langcode'];
     $entity_type_key = "#{$this->entityTypeId}";
     $view_hook = "{$this->entityTypeId}_view";
     // Find the keys for the ContentEntities in the build; Store entities for
     // rendering by view_mode.
     $children = Element::children($build_list);
     foreach ($children as $key) {
         if (isset($build_list[$key][$entity_type_key])) {
             $entity = $build_list[$key][$entity_type_key];
             if ($entity instanceof FieldableEntityInterface) {
                 $view_modes[$build_list[$key]['#view_mode']][$key] = $entity;
             }
         }
     }
     // Build content for the displays represented by the entities.
     foreach ($view_modes as $view_mode => $view_mode_entities) {
         $displays = EntityViewDisplay::collectRenderDisplays($view_mode_entities, $view_mode);
         $this->buildComponents($build_list, $view_mode_entities, $displays, $view_mode, $langcode);
         foreach (array_keys($view_mode_entities) as $key) {
             // Allow for alterations while building, before rendering.
             $entity = $build_list[$key][$entity_type_key];
             $display = $displays[$entity->bundle()];
             $this->moduleHandler()->invokeAll($view_hook, array(&$build_list[$key], $entity, $display, $view_mode, $langcode));
             $this->moduleHandler()->invokeAll('entity_view', array(&$build_list[$key], $entity, $display, $view_mode, $langcode));
             $this->alterBuild($build_list[$key], $entity, $display, $view_mode, $langcode);
             // Assign the weights configured in the display.
             // @todo: Once https://drupal.org/node/1875974 provides the missing API,
             //   only do it for 'extra fields', since other components have been
             //   taken care of in EntityViewDisplay::buildMultiple().
             foreach ($display->getComponents() as $name => $options) {
                 if (isset($build_list[$key][$name])) {
                     $build_list[$key][$name]['#weight'] = $options['weight'];
                 }
             }
             // Allow modules to modify the render array.
             $this->moduleHandler()->alter(array($view_hook, 'entity_view'), $build_list[$key], $entity, $display);
         }
     }
     return $build_list;
 }
开发者ID:brstde,项目名称:gap1,代码行数:62,代码来源:EntityViewBuilder.php

示例2: viewMultiple

 /**
  * {@inheritdoc}
  */
 public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL)
 {
     $displays = EntityViewDisplay::collectRenderDisplays($entities, $view_mode);
     $panelized_entities = [];
     $fallback_entities = [];
     foreach ($entities as $id => $entity) {
         $display = $displays[$entity->bundle()];
         if ($this->isPanelizerEnabled($display)) {
             $panelized_entities[$id] = $entity;
         } else {
             $fallback_entities[$id] = $entity;
         }
     }
     $result = [];
     if (!empty($fallback_entities)) {
         $result += $this->getFallbackViewBuilder()->viewMultiple($fallback_entities, $view_mode, $langcode);
     }
     if (!empty($panelized_entities)) {
         $result += $this->buildMultiplePanelized($entities, $displays, $view_mode, $langcode);
     }
     return $result;
 }
开发者ID:mglaman,项目名称:panelizer-d8-prototype,代码行数:25,代码来源:PanelizerEntityViewBuilder.php


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