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


PHP EntityViewDisplay::collectRenderDisplay方法代码示例

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


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

示例1: generateFieldMetadata

 /**
  * {@inheritdoc}
  */
 public function generateFieldMetadata(FieldItemListInterface $items, $view_mode)
 {
     $entity = $items->getEntity();
     $field_name = $items->getFieldDefinition()->getName();
     // Early-return if user does not have access.
     $access = $this->accessChecker->accessEditEntityField($entity, $field_name);
     if (!$access) {
         return array('access' => FALSE);
     }
     // Early-return if no editor is available.
     $formatter_id = EntityViewDisplay::collectRenderDisplay($entity, $view_mode)->getRenderer($field_name)->getPluginId();
     $editor_id = $this->editorSelector->getEditor($formatter_id, $items);
     if (!isset($editor_id)) {
         return array('access' => FALSE);
     }
     // Gather metadata, allow the editor to add additional metadata of its own.
     $label = $items->getFieldDefinition()->getLabel();
     $editor = $this->editorManager->createInstance($editor_id);
     $metadata = array('label' => String::checkPlain($label), 'access' => TRUE, 'editor' => $editor_id, 'aria' => t('Entity @type @id, field @field', array('@type' => $entity->getEntityTypeId(), '@id' => $entity->id(), '@field' => $label)));
     $custom_metadata = $editor->getMetadata($items);
     if (count($custom_metadata)) {
         $metadata['custom'] = $custom_metadata;
     }
     return $metadata;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:28,代码来源:MetadataGenerator.php

示例2: testSeparatorTranslation

 /**
  * Tests the translation of the range separator.
  */
 public function testSeparatorTranslation()
 {
     // Create an entity.
     $entity = EntityTest::create(['name' => $this->randomString(), $this->fieldStorage->getName() => ['value' => '2016-09-20', 'end_value' => '2016-09-21']]);
     // Verify the untranslated separator.
     $display = EntityViewDisplay::collectRenderDisplay($entity, 'default');
     $build = $display->build($entity);
     $output = $this->container->get('renderer')->renderRoot($build);
     $this->verbose($output);
     $this->assertContains('UNTRANSLATED', (string) $output);
     // Translate the separator.
     ConfigurableLanguage::createFromLangcode('nl')->save();
     /** @var \Drupal\language\ConfigurableLanguageManagerInterface $language_manager */
     $language_manager = $this->container->get('language_manager');
     $language_manager->getLanguageConfigOverride('nl', 'core.entity_view_display.entity_test.entity_test.default')->set('content.' . $this->fieldStorage->getName() . '.settings.separator', 'NL_TRANSLATED!')->save();
     $this->container->get('language.config_factory_override')->setLanguage(new Language(['id' => 'nl']));
     $this->container->get('cache_tags.invalidator')->invalidateTags($entity->getCacheTags());
     $display = EntityViewDisplay::collectRenderDisplay($entity, 'default');
     $build = $display->build($entity);
     $output = $this->container->get('renderer')->renderRoot($build);
     $this->verbose($output);
     $this->assertContains('NL_TRANSLATED!', (string) $output);
 }
开发者ID:Greg-Boggs,项目名称:electric-dev,代码行数:26,代码来源:SeparatorTranslationTest.php

示例3: renderTestEntity

 /**
  * Renders a entity_test and sets the output in the internal browser.
  *
  * @param int $id
  *   The entity_test ID to render.
  * @param string $view_mode
  *   (optional) The view mode to use for rendering. Defaults to 'full'.
  * @param bool $reset
  *   (optional) Whether to reset the entity_test controller cache. Defaults to
  *   TRUE to simplify testing.
  */
 protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE)
 {
     if ($reset) {
         \Drupal::entityManager()->getStorage('entity_test')->resetCache(array($id));
     }
     $entity = entity_load('entity_test', $id);
     $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
     $build = $display->build($entity);
     $output = \Drupal::service('renderer')->renderRoot($build);
     $this->setRawContent($output);
     $this->verbose($output);
 }
开发者ID:papillon-cendre,项目名称:d8,代码行数:23,代码来源:DateTimeFieldTest.php

示例4: getSingleFieldDisplay

 /**
  * Returns an EntityViewDisplay for rendering an individual field.
  *
  * @param \Drupal\Core\Entity\EntityInterface $entity
  *   The entity.
  * @param string $field_name
  *   The field name.
  * @param string|array $display_options
  *   The display options passed to the viewField() method.
  *
  * @return \Drupal\Core\Entity\Display\EntityViewDisplayInterface
  */
 protected function getSingleFieldDisplay($entity, $field_name, $display_options)
 {
     if (is_string($display_options)) {
         // View mode: use the Display configured for the view mode.
         $view_mode = $display_options;
         $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
         // Hide all fields except the current one.
         foreach (array_keys($entity->getFieldDefinitions()) as $name) {
             if ($name != $field_name) {
                 $display->removeComponent($name);
             }
         }
     } else {
         // Array of custom display options: use a runtime Display for the
         // '_custom' view mode. Persist the displays created, to reduce the number
         // of objects (displays and formatter plugins) created when rendering a
         // series of fields individually for cases such as views tables.
         $entity_type_id = $entity->getEntityTypeId();
         $bundle = $entity->bundle();
         $key = $entity_type_id . ':' . $bundle . ':' . $field_name . ':' . crc32(serialize($display_options));
         if (!isset($this->singleFieldDisplays[$key])) {
             $this->singleFieldDisplays[$key] = EntityViewDisplay::create(array('targetEntityType' => $entity_type_id, 'bundle' => $bundle, 'status' => TRUE))->setComponent($field_name, $display_options);
         }
         $display = $this->singleFieldDisplays[$key];
     }
     return $display;
 }
开发者ID:brstde,项目名称:gap1,代码行数:39,代码来源:EntityViewBuilder.php

示例5: viewField

 /**
  * {@inheritdoc}
  */
 public function viewField(FieldItemListInterface $items, $display_options = array())
 {
     $output = array();
     $entity = $items->getEntity();
     $field_name = $items->getFieldDefinition()->getName();
     // Get the display object.
     if (is_string($display_options)) {
         $view_mode = $display_options;
         $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
         // Hide all fields except the current one.
         foreach (array_keys($entity->getFieldDefinitions()) as $name) {
             if ($name != $field_name) {
                 $display->removeComponent($name);
             }
         }
     } else {
         $view_mode = '_custom';
         $display = entity_create('entity_view_display', array('targetEntityType' => $entity->getEntityTypeId(), 'bundle' => $entity->bundle(), 'mode' => $view_mode, 'status' => TRUE));
         $display->setComponent($field_name, $display_options);
     }
     $build = $display->build($entity);
     if (isset($build[$field_name])) {
         $output = $build[$field_name];
     }
     return $output;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:29,代码来源:EntityViewBuilder.php

示例6: renderTestEntity

 /**
  * Renders a entity_test and sets the output in the internal browser.
  *
  * @param int $id
  *   The entity_test ID to render.
  * @param string $view_mode
  *   (optional) The view mode to use for rendering. Defaults to 'full'.
  * @param bool $reset
  *   (optional) Whether to reset the entity_test controller cache. Defaults to
  *   TRUE to simplify testing.
  */
 protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE)
 {
     if ($reset) {
         $this->container->get('entity_type.manager')->getStorage('entity_test')->resetCache([$id]);
     }
     $entity = EntityTest::load($id);
     $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
     $build = $display->build($entity);
     $output = $this->container->get('renderer')->renderRoot($build);
     $this->setRawContent($output);
     $this->verbose($output);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:23,代码来源:DateTestBase.php

示例7: formElement

 /**
  * {@inheritdoc}
  */
 public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
 {
     $entity = $items->getEntity();
     $entity_type_id = $entity->getEntityTypeId();
     $entity_view_modes = $this->getEntityDisplayRepository()->getViewModes($entity_type_id);
     // Get the current values from the entity.
     $values = [];
     /** @var \Drupal\Core\Field\FieldItemInterface $item */
     foreach ($items as $item) {
         $values[$item->view_mode] = ['default' => $item->default, 'panels_display' => $item->panels_display];
     }
     /** @var \Drupal\panelizer\Plugin\PanelizerEntityInterface $panelizer_plugin */
     $panelizer_plugin = $this->getPanelizerManager()->createInstance($entity_type_id, []);
     // If any view modes are missing, then set the default.
     foreach ($entity_view_modes as $view_mode => $view_mode_info) {
         if (!isset($values[$view_mode])) {
             $display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
             if ($display->getThirdPartySetting('panelizer', 'enable', FALSE)) {
                 $panels_display = $panelizer_plugin->getDefaultDisplay($display, $entity->bundle(), $view_mode);
                 $values[$view_mode] = ['default' => 'default', 'panels_display' => $this->getPanelsManager()->exportDisplay($panels_display)];
             }
         }
     }
     // Add elements to the form for each view mode.
     $delta = 0;
     foreach ($values as $view_mode => $value) {
         $element[$delta]['view_mode'] = ['#type' => 'value', '#value' => $view_mode];
         if (!empty($this->getSetting('allow_panel_choice'))) {
             $element[$delta]['default'] = ['#type' => 'select', '#options' => [], '#default_value' => $value['default']];
         } else {
             $element[$delta]['default'] = ['#type' => 'value', '#value' => $value['default']];
         }
         $element[$delta]['panels_display'] = ['#type' => 'value', '#value' => $value['panels_display']];
         $delta++;
     }
     return $element;
 }
开发者ID:mglaman,项目名称:panelizer-d8-prototype,代码行数:40,代码来源:PanelizerWidget.php


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