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


PHP EntityTypeManagerInterface::getViewBuilder方法代码示例

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


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

示例1: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     /** @var \Drupal\Core\Entity\EntityInterface $group */
     $group = $this->getContext('og')->getContextValue();
     $view_builder = $this->entityTypeManager->getViewBuilder($group->getEntityTypeId());
     // We render the related view mode only in this block. Additional modules,
     // like collection and solution, will add more elements directly.
     $build['group'] = $view_builder->view($group, 'group_header');
     return $build;
 }
开发者ID:ec-europa,项目名称:joinup-dev,代码行数:13,代码来源:GroupHeaderBlock.php

示例2: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $view_mode = $this->getSetting('view_mode');
     $elements = array();
     foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
         // Protect ourselves from recursive rendering.
         static $depth = 0;
         $depth++;
         if ($depth > 20) {
             $this->loggerFactory->get('entity')->error('Recursive rendering detected when rendering entity @entity_type @entity_id. Aborting rendering.', array('@entity_type' => $entity->getEntityTypeId(), '@entity_id' => $entity->id()));
             return $elements;
         }
         if ($entity->id()) {
             $view_builder = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId());
             $elements[$delta] = $view_builder->view($entity, $view_mode, $entity->language()->getId());
             // Add a resource attribute to set the mapping property's value to the
             // entity's url. Since we don't know what the markup of the entity will
             // be, we shouldn't rely on it for structured data such as RDFa.
             if (!empty($items[$delta]->_attributes)) {
                 $items[$delta]->_attributes += array('resource' => $entity->url());
             }
         } else {
             // This is an "auto_create" item.
             $elements[$delta] = array('#markup' => $entity->label());
         }
         $depth = 0;
     }
     return $elements;
 }
开发者ID:ravibarnwal,项目名称:laraitassociate.in,代码行数:32,代码来源:EntityReferenceEntityFormatter.php

示例3: viewElements

 /**
  * {@inheritdoc}
  */
 public function viewElements(FieldItemListInterface $items, $langcode)
 {
     $view_mode = $this->getSetting('view_mode');
     $elements = array();
     foreach ($this->getEntitiesToView($items, $langcode) as $delta => $entity) {
         // Due to render caching and delayed calls, the viewElements() method
         // will be called later in the rendering process through a '#pre_render'
         // callback, so we need to generate a counter that takes into account
         // all the relevant information about this field and the referenced
         // entity that is being rendered.
         $recursive_render_id = $items->getFieldDefinition()->getTargetEntityTypeId() . $items->getFieldDefinition()->getTargetBundle() . $items->getName() . $entity->id();
         if (isset(static::$recursiveRenderDepth[$recursive_render_id])) {
             static::$recursiveRenderDepth[$recursive_render_id]++;
         } else {
             static::$recursiveRenderDepth[$recursive_render_id] = 1;
         }
         // Protect ourselves from recursive rendering.
         if (static::$recursiveRenderDepth[$recursive_render_id] > static::RECURSIVE_RENDER_LIMIT) {
             $this->loggerFactory->get('entity')->error('Recursive rendering detected when rendering entity %entity_type: %entity_id, using the %field_name field on the %bundle_name bundle. Aborting rendering.', ['%entity_type' => $entity->getEntityTypeId(), '%entity_id' => $entity->id(), '%field_name' => $items->getName(), '%bundle_name' => $items->getFieldDefinition()->getTargetBundle()]);
             return $elements;
         }
         $view_builder = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId());
         $elements[$delta] = $view_builder->view($entity, $view_mode, $entity->language()->getId());
         // Add a resource attribute to set the mapping property's value to the
         // entity's url. Since we don't know what the markup of the entity will
         // be, we shouldn't rely on it for structured data such as RDFa.
         if (!empty($items[$delta]->_attributes) && !$entity->isNew() && $entity->hasLinkTemplate('canonical')) {
             $items[$delta]->_attributes += array('resource' => $entity->toUrl()->toString());
         }
     }
     return $elements;
 }
开发者ID:DrupalCamp-NYC,项目名称:dcnyc16,代码行数:35,代码来源:EntityReferenceEntityFormatter.php

示例4: preview

 /**
  * Preview job item entity data.
  *
  * @param \Drupal\tmgmt\JobItemInterface $tmgmt_job_item
  *   Job item to be previewed.
  * @param string $view_mode
  *   The view mode that should be used to display the entity.
  *
  * @return array
  *   A render array as expected by drupal_render().
  */
 public function preview(JobItemInterface $tmgmt_job_item, $view_mode)
 {
     // Load entity.
     $entity = $this->entityTypeManager->getStorage($tmgmt_job_item->getItemType())->load($tmgmt_job_item->getItemId());
     // We cannot show the preview for non-existing entities.
     if (!$entity) {
         throw new NotFoundHttpException();
     }
     $data = $tmgmt_job_item->getData();
     $target_langcode = $tmgmt_job_item->getJob()->getTargetLangcode();
     // Populate preview with target translation data.
     $preview = $this->makePreview($entity, $data, $target_langcode);
     // Build view for entity.
     $page = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId())->view($preview, $view_mode, $preview->language()->getId());
     // The preview is not cacheable.
     $page['#cache']['max-age'] = 0;
     return $page;
 }
开发者ID:andrewl,项目名称:andrewlnet,代码行数:29,代码来源:ContentTranslationPreviewController.php

示例5: drupalEntity

 /**
  * Returns the render array for an entity.
  *
  * @param string $entity_type
  *   The entity type.
  * @param mixed $id
  *   The ID of the entity to render.
  * @param string $view_mode
  *   (optional) The view mode that should be used to render the entity.
  * @param string $langcode
  *   (optional) For which language the entity should be rendered, defaults to
  *   the current content language.
  *
  * @return null|array
  *   A render array for the entity or NULL if the entity does not exist.
  */
 public function drupalEntity($entity_type, $id = NULL, $view_mode = NULL, $langcode = NULL)
 {
     $entity = $id ? $this->entityTypeManager->getStorage($entity_type)->load($id) : $this->routeMatch->getParameter($entity_type);
     if ($entity) {
         $render_controller = $this->entityTypeManager->getViewBuilder($entity_type);
         return $render_controller->view($entity, $view_mode, $langcode);
     }
     return NULL;
 }
开发者ID:nicolaspoulain,项目名称:bb8,代码行数:25,代码来源:TwigExtension.php

示例6: build

 /**
  * {@inheritdoc}
  */
 public function build()
 {
     // Load one advertisement node.
     $nids = $this->entityQuery->get('node')->condition('type', 'ad')->range(0, 1)->condition('status', 1)->condition('field_ad_expiration', REQUEST_TIME, '>')->sort('created', 'DESC')->execute();
     // Quick and dirty exit if no ad was created.
     if (empty($nids)) {
         return 'Create an Ad first.';
     }
     // Build the ad teaser.
     /** @var \Drupal\node\Entity\Node $node */
     $node = $this->entityTypeManager->getStorage('node')->load(reset($nids));
     $teaser = $this->entityTypeManager->getViewBuilder('node')->view($node, 'teaser');
     $build['ad'] = $teaser;
     $build['cart_link'] = array('#type' => 'link', '#url' => Url::fromRoute('cacheit.shopping_cart', array(), ['query' => ['product_id' => $node->id()]]), '#title' => t('Add to cart'), '#attributes' => ['class' => ['button']], '#weight' => 10);
     $build['conditions_link'] = array('#type' => 'link', '#url' => Url::fromUri('entity:node/2'), '#title' => t('Conditions'), '#weight' => 11, '#cache' => ['tags' => ['node:2'], 'max-age' => 3600]);
     // Dynamic content added using a placeholder.
     $build['validity'] = ['#lazy_builder' => ['cacheit.lazy_builders:renderAdValidity', [$node->id()]], '#create_placeholder' => TRUE];
     return $build;
 }
开发者ID:wizzlern,项目名称:cacheit,代码行数:22,代码来源:AdBlock.php

示例7: getHtml

 /**
  * Generate the HTML for our entity.
  *
  * @param \Drupal\Core\Entity\ContentEntityInterface $entity
  *   The entity we're rendering.
  * @param bool $use_default_css
  *   TRUE if we should inject our default CSS otherwise FALSE.
  * @param bool $optimize_css
  *   TRUE if we should compress the CSS otherwise FALSE.
  *
  * @return string
  *   The generated HTML.
  *
  * @throws \Exception
  */
 protected function getHtml(ContentEntityInterface $entity, $use_default_css, $optimize_css)
 {
     $render_controller = $this->entityTypeManager->getViewBuilder($entity->getEntityTypeId());
     $render = ['#theme' => 'entity_print__' . $entity->getEntityTypeId() . '__' . $entity->id(), '#entity' => $entity, '#entity_array' => $render_controller->view($entity, 'pdf'), '#attached' => []];
     // Inject some generic CSS across all templates.
     if ($use_default_css) {
         $render['#attached']['library'][] = 'entity_print/default';
     }
     // Allow other modules to add their own CSS.
     $this->moduleHandler->alter('entity_print_css', $render, $entity);
     // Inject CSS from the theme info files and then render the CSS.
     $render = $this->addCss($render, $entity);
     $css_assets = $this->assetResolver->getCssAssets(AttachedAssets::createFromRenderArray($render), $optimize_css);
     $rendered_css = $this->cssRenderer->render($css_assets);
     $render['#entity_print_css'] = $this->renderer->render($rendered_css);
     return $this->renderer->render($render);
 }
开发者ID:gerbreown1,项目名称:calvaryfree,代码行数:32,代码来源:EntityPrintPdfBuilder.php


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