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


PHP EntityManagerInterface::getViewBuilder方法代码示例

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


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

示例1: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     /** @var $entity \Drupal\Core\Entity\EntityInterface */
     $entity = $this->getContextValue('entity');
     $view_builder = $this->entityManager->getViewBuilder($entity->getEntityTypeId());
     return $view_builder->view($entity, $this->configuration['view_mode']);
 }
开发者ID:AllieRays,项目名称:debugging-drupal-8,代码行数:10,代码来源:EntityView.php

示例2: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     /** @var $entity \Drupal\Core\Entity\EntityInterface */
     $entity = $this->getContextValue('entity');
     $view_builder = $this->entityManager->getViewBuilder($entity->getEntityTypeId());
     $build = $view_builder->view($entity, $this->configuration['view_mode']);
     CacheableMetadata::createFromObject($this->getContext('entity'))->applyTo($build);
     return $build;
 }
开发者ID:Wylbur,项目名称:gj,代码行数:12,代码来源:EntityView.php

示例3: __construct

 /**
  * Creates a NodeBlock instance.
  *
  * @param array $configuration
  * @param string $plugin_id
  * @param mixed $plugin_definition
  * @param EntityManagerInterface $entity_manager
  */
 public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityManagerInterface $entity_manager)
 {
     parent::__construct($configuration, $plugin_id, $plugin_definition);
     $this->viewBuilder = $entity_manager->getViewBuilder('node');
     $this->nodeStorage = $entity_manager->getStorage('node');
     $this->node = $entity_manager->getStorage('node')->load($this->getDerivativeId());
 }
开发者ID:louhichi,项目名称:d8-demo-modules,代码行数:15,代码来源:NodeBlock.php

示例4: view

 /**
  * Provides a page to render a single entity.
  *
  * @param \Drupal\Core\Entity\EntityInterface $_entity
  *   The Entity to be rendered. Note this variable is named $_entity rather
  *   than $entity to prevent collisions with other named placeholders in the
  *   route.
  * @param string $view_mode
  *   (optional) The view mode that should be used to display the entity.
  *   Defaults to 'full'.
  * @param string $langcode
  *   (optional) For which language the entity should be rendered, defaults to
  *   the current content language.
  *
  * @return array
  *   A render array as expected by drupal_render().
  */
 public function view(EntityInterface $_entity, $view_mode = 'full', $langcode = NULL)
 {
     $page = $this->entityManager->getViewBuilder($_entity->getEntityTypeId())->view($_entity, $view_mode, $langcode);
     $page['#pre_render'][] = [$this, 'buildTitle'];
     $page['#entity_type'] = $_entity->getEntityTypeId();
     return $page;
 }
开发者ID:jeyram,项目名称:camp-gdl,代码行数:24,代码来源:EntityViewController.php

示例5: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     if ($block = $this->getEntity()) {
         return $this->entityManager->getViewBuilder($block->getEntityTypeId())->view($block, $this->configuration['view_mode']);
     } else {
         return array('#markup' => $this->t('Block with uuid %uuid does not exist. <a href="!url">Add custom block</a>.', array('%uuid' => $this->getDerivativeId(), '!url' => $this->urlGenerator->generate('block_content.add_page'))), '#access' => $this->account->hasPermission('administer blocks'));
     }
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:11,代码来源:BlockContentBlock.php

示例6: render

 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $entity = $this->getEntityTranslation($this->getEntity($values), $values);
     if (isset($entity) && $entity->access('view')) {
         $view_builder = $this->entityManager->getViewBuilder($this->getEntityTypeId());
         return $view_builder->view($entity, $this->options['view_mode']);
     }
     return [];
 }
开发者ID:darrylri,项目名称:protovbmwmo,代码行数:12,代码来源:RenderedEntity.php

示例7: view

 /**
  * Provides a page to render a single entity.
  *
  * @param \Drupal\Core\Entity\EntityInterface $_entity
  *   The Entity to be rendered. Note this variable is named $_entity rather
  *   than $entity to prevent collisions with other named placeholders in the
  *   route.
  * @param string $view_mode
  *   (optional) The view mode that should be used to display the entity.
  *   Defaults to 'full'.
  * @param string $langcode
  *   (optional) For which language the entity should be rendered, defaults to
  *   the current content language.
  *
  * @return array
  *   A render array as expected by drupal_render().
  */
 public function view(EntityInterface $_entity, $view_mode = 'full', $langcode = NULL)
 {
     $page = $this->entityManager->getViewBuilder($_entity->getEntityTypeId())->view($_entity, $view_mode, $langcode);
     // If the entity's label is rendered using a field formatter, set the
     // rendered title field formatter as the page title instead of the default
     // plain text title. This allows attributes set on the field to propagate
     // correctly (e.g. RDFa, in-place editing).
     if ($_entity instanceof ContentEntityInterface) {
         $label_field = $_entity->getEntityType()->getKey('label');
         if ($label_field && $_entity->getFieldDefinition($label_field)->getDisplayOptions('view')) {
             // We must render the label field, because rendering the entity may be
             // a cache hit, in which case we can't extract the rendered label field
             // from the $page renderable array.
             $build = $this->entityManager->getTranslationFromContext($_entity)->get($label_field)->view($view_mode);
             $page['#title'] = drupal_render($build, TRUE);
         }
     }
     return $page;
 }
开发者ID:anatalsceo,项目名称:en-classe,代码行数:36,代码来源:EntityViewController.php

示例8: view

 /**
  * Build the view draft page.
  *
  * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
  *   The route match.
  *
  * @return array
  *   Render array.
  *
  * @throws \Exception
  *   Thrown when the entity is not found in the given graph.
  */
 public function view(RouteMatchInterface $route_match)
 {
     $parameter_name = $route_match->getRouteObject()->getOption('entity_type_id');
     /** @var \Drupal\Core\Entity\EntityInterface $entity */
     $entity = $route_match->getParameter($parameter_name);
     $storage = $this->entityManager->getStorage($entity->getEntityTypeId());
     $graph_name = $route_match->getRouteObject()->getOption('graph_name');
     $storage->setRequestGraphs($entity->id(), [$graph_name]);
     $draft_entity = $storage->load($entity->id());
     if (!$draft_entity) {
         // Should not occur: RdfGraphAccessCheck validates that the entity exists.
         throw new \Exception('Entity not loaded from graph');
     }
     $page = $this->entityManager->getViewBuilder($entity->getEntityTypeId())->view($draft_entity, 'full');
     $page['#pre_render'][] = [$this, 'buildTitle'];
     $page['#entity_type'] = $entity->getEntityTypeId();
     $page['#' . $page['#entity_type']] = $draft_entity;
     return $page;
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:31,代码来源:RdfController.php

示例9: render

 /**
  * {@inheritdoc}
  */
 public function render(ResultRow $values)
 {
     $entity = $this->getEntityTranslation($this->getEntity($values), $values);
     $build = [];
     if (isset($entity)) {
         $access = $entity->access('view', NULL, TRUE);
         $build['#access'] = $access;
         if ($access->isAllowed()) {
             $view_builder = $this->entityManager->getViewBuilder($this->getEntityTypeId());
             $build += $view_builder->view($entity, $this->options['view_mode']);
         }
     }
     return $build;
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:17,代码来源:RenderedEntity.php

示例10: indexNode

 /**
  * Indexes a single node.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node to index.
  */
 protected function indexNode(NodeInterface $node)
 {
     $languages = $node->getTranslationLanguages();
     $node_render = $this->entityManager->getViewBuilder('node');
     foreach ($languages as $language) {
         $node = $node->getTranslation($language->getId());
         // Render the node.
         $build = $node_render->view($node, 'search_index', $language->getId());
         unset($build['#theme']);
         $rendered = $this->renderer->renderPlain($build);
         $text = '<h1>' . SafeMarkup::checkPlain($node->label($language->getId())) . '</h1>' . $rendered;
         // Fetch extra data normally not visible.
         $extra = $this->moduleHandler->invokeAll('node_update_index', array($node, $language->getId()));
         foreach ($extra as $t) {
             $text .= $t;
         }
         // Update index, using search index "type" equal to the plugin ID.
         search_index($this->getPluginId(), $node->id(), $language->getId(), $text);
     }
 }
开发者ID:nsp15,项目名称:Drupal8,代码行数:26,代码来源:NodeSearch.php

示例11: indexNode

 /**
  * Indexes a single node.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node to index.
  */
 protected function indexNode(NodeInterface $node)
 {
     $languages = $node->getTranslationLanguages();
     $node_render = $this->entityManager->getViewBuilder('node');
     foreach ($languages as $language) {
         $node = $node->getTranslation($language->getId());
         // Render the node.
         $build = $node_render->view($node, 'search_index', $language->getId());
         unset($build['#theme']);
         // Add the title to text so it is searchable.
         $build['search_title'] = ['#prefix' => '<h1>', '#plain_text' => $node->label(), '#suffix' => '</h1>', '#weight' => -1000];
         $text = $this->renderer->renderPlain($build);
         // Fetch extra data normally not visible.
         $extra = $this->moduleHandler->invokeAll('node_update_index', [$node]);
         foreach ($extra as $t) {
             $text .= $t;
         }
         // Update index, using search index "type" equal to the plugin ID.
         search_index($this->getPluginId(), $node->id(), $language->getId(), $text);
     }
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:27,代码来源:NodeSearch.php

示例12: render

 /**
  * {@inheritdoc}
  */
 public function render($empty = FALSE)
 {
     if (!$empty || !empty($this->options['empty'])) {
         // @todo Use a method to check for tokens in
         //   https://www.drupal.org/node/2396607.
         if (strpos($this->options['target'], '{{') !== FALSE || strpos($this->options['target'], '!') !== FALSE || strpos($this->options['target'], '%') !== FALSE || strpos($this->options['target'], '[') !== FALSE) {
             $target_id = $this->tokenizeValue($this->options['target']);
             if ($entity = $this->entityManager->getStorage($this->entityType)->load($target_id)) {
                 $target_entity = $entity;
             }
         } else {
             if ($entity = $this->entityManager->loadEntityByConfigTarget($this->entityType, $this->options['target'])) {
                 $target_entity = $entity;
             }
         }
         if (isset($target_entity) && (!empty($this->options['bypass_access']) || $target_entity->access('view'))) {
             $view_builder = $this->entityManager->getViewBuilder($this->entityType);
             return $view_builder->view($target_entity, $this->options['view_mode']);
         }
     }
     return [];
 }
开发者ID:nstielau,项目名称:drops-8,代码行数:25,代码来源:Entity.php

示例13: indexNode

 /**
  * Indexes a single node.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node to index.
  */
 protected function indexNode(NodeInterface $node)
 {
     // Save the changed time of the most recent indexed node, for the search
     // results half-life calculation.
     $this->state->set('node.cron_last', $node->getChangedTime());
     $languages = $node->getTranslationLanguages();
     $node_render = $this->entityManager->getViewBuilder('node');
     foreach ($languages as $language) {
         $node = $node->getTranslation($language->id);
         // Render the node.
         $build = $node_render->view($node, 'search_index', $language->id);
         unset($build['#theme']);
         $node->rendered = drupal_render($build);
         $text = '<h1>' . String::checkPlain($node->label($language->id)) . '</h1>' . $node->rendered;
         // Fetch extra data normally not visible.
         $extra = $this->moduleHandler->invokeAll('node_update_index', array($node, $language->id));
         foreach ($extra as $t) {
             $text .= $t;
         }
         // Update index.
         search_index($node->id(), $this->getPluginId(), $text, $language->id);
     }
 }
开发者ID:alnutile,项目名称:drunatra,代码行数:29,代码来源:NodeSearch.php

示例14: __construct

 /**
  * Constructs a new CommentDefaultFormatter.
  *
  * @param string $plugin_id
  *   The plugin_id for the formatter.
  * @param mixed $plugin_definition
  *   The plugin implementation definition.
  * @param \Drupal\Core\Field\FieldDefinitionInterface $field_definition
  *   The definition of the field to which the formatter is associated.
  * @param array $settings
  *   The formatter settings.
  * @param string $label
  *   The formatter label display setting.
  * @param string $view_mode
  *   The view mode.
  * @param array $third_party_settings
  *   Third party settings.
  * @param \Drupal\Core\Session\AccountInterface $current_user
  *   The current user.
  * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
  *   The entity manager
  * @param \Drupal\Core\Entity\EntityFormBuilderInterface $entity_form_builder
  *   The entity form builder.
  */
 public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, AccountInterface $current_user, EntityManagerInterface $entity_manager, EntityFormBuilderInterface $entity_form_builder)
 {
     parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings);
     $this->viewBuilder = $entity_manager->getViewBuilder('comment');
     $this->storage = $entity_manager->getStorage('comment');
     $this->currentUser = $current_user;
     $this->entityManager = $entity_manager;
     $this->entityFormBuilder = $entity_form_builder;
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:33,代码来源:CommentDefaultFormatter.php

示例15: __construct

 /**
  * Constructs a BookExport object.
  *
  * @param \Drupal\Core\Entity\EntityManagerInterface $entityManager
  *   The entity manager.
  * @param \Drupal\book\BookManagerInterface $book_manager
  *   The book manager.
  */
 public function __construct(EntityManagerInterface $entityManager, BookManagerInterface $book_manager)
 {
     $this->nodeStorage = $entityManager->getStorage('node');
     $this->viewBuilder = $entityManager->getViewBuilder('node');
     $this->bookManager = $book_manager;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:14,代码来源:BookExport.php


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