Ejemplo n.º 1
0
 /**
  * {@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']);
 }
Ejemplo n.º 2
0
 /**
  * {@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;
 }
Ejemplo n.º 3
0
 /**
  * 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());
 }
Ejemplo n.º 4
0
 /**
  * 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;
 }
Ejemplo n.º 5
0
 /**
  * {@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'));
     }
 }
Ejemplo n.º 6
0
 /**
  * {@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 [];
 }
Ejemplo n.º 7
0
 /**
  * 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;
 }
Ejemplo n.º 8
0
 /**
  * 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;
 }
Ejemplo n.º 9
0
 /**
  * {@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;
 }
Ejemplo n.º 10
0
 /**
  * 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);
     }
 }
Ejemplo n.º 11
0
 /**
  * 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);
     }
 }
Ejemplo n.º 12
0
 /**
  * {@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 [];
 }
Ejemplo n.º 13
0
 /**
  * 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);
     }
 }
 /**
  * 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;
 }
Ejemplo n.º 15
0
 /**
  * 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;
 }
Ejemplo n.º 16
0
 /**
  * {@inheritdoc}
  */
 public function view(EntityInterface $entity)
 {
     return $this->entityManager->getViewBuilder($this->configuration['entity_type'])->view($entity, $this->configuration['view_mode']);
 }