/** * {@inheritdoc} */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { parent::buildComponents($build, $entities, $displays, $view_mode, $langcode); foreach ($entities as $id => $entity) { $build[$id]['label'] = array('#weight' => -100, '#markup' => String::checkPlain($entity->label())); $build[$id]['separator'] = array('#weight' => -150, '#markup' => ' | '); $build[$id]['view_mode'] = array('#weight' => -200, '#markup' => String::checkPlain($view_mode)); } }
/** * Overrides Drupal\Core\Entity\EntityViewBuilder::buildComponents(). * * In addition to modifying the content key on entities, this implementation * will also set the comment entity key which all comments carry. * * @throws \InvalidArgumentException * Thrown when a comment is attached to an entity that no longer exists. */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { /** @var \Drupal\comment\CommentInterface[] $entities */ if (empty($entities)) { return; } // Pre-load associated users into cache to leverage multiple loading. $uids = array(); foreach ($entities as $entity) { $uids[] = $entity->getOwnerId(); } $this->entityManager->getStorage('user')->loadMultiple(array_unique($uids)); parent::buildComponents($build, $entities, $displays, $view_mode, $langcode); // Load all the entities that have comments attached. $commented_entity_ids = array(); $commented_entities = array(); foreach ($entities as $entity) { $commented_entity_ids[$entity->getCommentedEntityTypeId()][] = $entity->getCommentedEntityId(); } // Load entities in bulk. This is more performant than using // $comment->getCommentedEntity() as we can load them in bulk per type. foreach ($commented_entity_ids as $entity_type => $entity_ids) { $commented_entities[$entity_type] = $this->entityManager->getStorage($entity_type)->loadMultiple($entity_ids); } foreach ($entities as $id => $entity) { if (isset($commented_entities[$entity->getCommentedEntityTypeId()][$entity->getCommentedEntityId()])) { $commented_entity = $commented_entities[$entity->getCommentedEntityTypeId()][$entity->getCommentedEntityId()]; } else { throw new \InvalidArgumentException(t('Invalid entity for comment.')); } $build[$id]['#entity'] = $entity; $build[$id]['#theme'] = 'comment__' . $entity->getFieldName() . '__' . $commented_entity->bundle(); $callback = '\\Drupal\\comment\\CommentViewBuilder::renderLinks'; $context = array('comment_entity_id' => $entity->id(), 'view_mode' => $view_mode, 'langcode' => $langcode, 'commented_entity_type' => $commented_entity->getEntityTypeId(), 'commented_entity_id' => $commented_entity->id(), 'in_preview' => !empty($entity->in_preview)); $placeholder = drupal_render_cache_generate_placeholder($callback, $context); $build[$id]['links'] = array('#post_render_cache' => array($callback => array($context)), '#markup' => $placeholder); $account = comment_prepare_author($entity); if (\Drupal::config('user.settings')->get('signatures') && $account->getSignature()) { $build[$id]['signature'] = array('#type' => 'processed_text', '#text' => $account->getSignature(), '#format' => $account->getSignatureFormat(), '#langcode' => $entity->language()->getId()); // The signature will only be rendered in the theme layer, which means // its associated cache tags will not bubble up. Work around this for // now by already rendering the signature here. // @todo remove this work-around, see https://drupal.org/node/2273277 drupal_render($build[$id]['signature'], TRUE); } if (!isset($build[$id]['#attached'])) { $build[$id]['#attached'] = array(); } $build[$id]['#attached']['library'][] = 'comment/drupal.comment-by-viewer'; if ($this->moduleHandler->moduleExists('history') && \Drupal::currentUser()->isAuthenticated()) { $build[$id]['#attached']['library'][] = 'comment/drupal.comment-new-indicator'; // Embed the metadata for the comment "new" indicators on this node. $build[$id]['#post_render_cache']['history_attach_timestamp'] = array(array('node_id' => $commented_entity->id())); } } }
/** * {@inheritdoc} * * In addition to modifying the content key on entities, this implementation * will also set the comment entity key which all comments carry. * * @throws \InvalidArgumentException * Thrown when a comment is attached to an entity that no longer exists. */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode) { /** @var \Drupal\comment\CommentInterface[] $entities */ if (empty($entities)) { return; } // Pre-load associated users into cache to leverage multiple loading. $uids = array(); foreach ($entities as $entity) { $uids[] = $entity->getOwnerId(); } $this->entityManager->getStorage('user')->loadMultiple(array_unique($uids)); parent::buildComponents($build, $entities, $displays, $view_mode); // A counter to track the indentation level. $current_indent = 0; foreach ($entities as $id => $entity) { if ($build[$id]['#comment_threaded']) { $comment_indent = count(explode('.', $entity->getThread())) - 1; if ($comment_indent > $current_indent) { // Set 1 to indent this comment from the previous one (its parent). // Set only one extra level of indenting even if the difference in // depth is higher. $build[$id]['#comment_indent'] = 1; $current_indent++; } else { // Set zero if this comment is on the same level as the previous one // or negative value to point an amount indents to close. $build[$id]['#comment_indent'] = $comment_indent - $current_indent; $current_indent = $comment_indent; } } // Commented entities already loaded after self::getBuildDefaults(). $commented_entity = $entity->getCommentedEntity(); $build[$id]['#entity'] = $entity; $build[$id]['#theme'] = 'comment__' . $entity->getFieldName() . '__' . $commented_entity->bundle(); $display = $displays[$entity->bundle()]; if ($display->getComponent('links')) { $build[$id]['links'] = array('#lazy_builder' => ['comment.lazy_builders:renderLinks', [$entity->id(), $view_mode, $entity->language()->getId(), !empty($entity->in_preview)]], '#create_placeholder' => TRUE); } if (!isset($build[$id]['#attached'])) { $build[$id]['#attached'] = array(); } $build[$id]['#attached']['library'][] = 'comment/drupal.comment-by-viewer'; if ($this->moduleHandler->moduleExists('history') && $this->currentUser->isAuthenticated()) { $build[$id]['#attached']['library'][] = 'comment/drupal.comment-new-indicator'; // Embed the metadata for the comment "new" indicators on this node. $build[$id]['history'] = ['#lazy_builder' => ['history_attach_timestamp', [$commented_entity->id()]], '#create_placeholder' => TRUE]; } } if ($build[$id]['#comment_threaded']) { // The final comment must close up some hanging divs. $build[$id]['#comment_indent_final'] = $current_indent; } }
/** * {@inheritdoc} */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { parent::buildComponents($build, $entities, $displays, $view_mode, $langcode); foreach ($entities as $id => $entity) { // Add the message extra field, if enabled. $display = $displays[$entity->bundle()]; if ($entity->getMessage() && $display->getComponent('message')) { $build[$id]['message'] = array('#type' => 'item', '#title' => t('Message'), '#markup' => String::checkPlain($entity->getMessage())); } } }
/** * {@inheritdoc} */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { parent::buildComponents($build, $entities, $displays, $view_mode, $langcode); foreach ($entities as $id => $entity) { $bundle = $entity->bundle(); $display = $displays[$bundle]; if ($display->getComponent('description')) { $build[$id]['description'] = array('#markup' => aggregator_filter_xss($entity->getDescription()), '#prefix' => '<div class="item-description">', '#suffix' => '</div>'); } } }
/** * Overrides Drupal\Core\Entity\EntityViewBuilder::buildComponents(). * * In addition to modifying the content key on entities, this implementation * will also set the comment entity key which all comments carry. * * @throws \InvalidArgumentException * Thrown when a comment is attached to an entity that no longer exists. */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { /** @var \Drupal\comment\CommentInterface[] $entities */ if (empty($entities)) { return; } // Pre-load associated users into cache to leverage multiple loading. $uids = array(); foreach ($entities as $entity) { $uids[] = $entity->getOwnerId(); } $this->entityManager->getStorage('user')->loadMultiple(array_unique($uids)); parent::buildComponents($build, $entities, $displays, $view_mode, $langcode); // Load all the entities that have comments attached. $commented_entity_ids = array(); $commented_entities = array(); foreach ($entities as $entity) { $commented_entity_ids[$entity->getCommentedEntityTypeId()][] = $entity->getCommentedEntityId(); } // Load entities in bulk. This is more performant than using // $comment->getCommentedEntity() as we can load them in bulk per type. foreach ($commented_entity_ids as $entity_type => $entity_ids) { $commented_entities[$entity_type] = $this->entityManager->getStorage($entity_type)->loadMultiple($entity_ids); } foreach ($entities as $id => $entity) { if (isset($commented_entities[$entity->getCommentedEntityTypeId()][$entity->getCommentedEntityId()])) { $commented_entity = $commented_entities[$entity->getCommentedEntityTypeId()][$entity->getCommentedEntityId()]; } else { throw new \InvalidArgumentException(t('Invalid entity for comment.')); } $build[$id]['#entity'] = $entity; $build[$id]['#theme'] = 'comment__' . $entity->getFieldName() . '__' . $commented_entity->bundle(); $display = $displays[$entity->bundle()]; if ($display->getComponent('links')) { $callback = 'comment.post_render_cache:renderLinks'; $context = array('comment_entity_id' => $entity->id(), 'view_mode' => $view_mode, 'langcode' => $langcode, 'commented_entity_type' => $commented_entity->getEntityTypeId(), 'commented_entity_id' => $commented_entity->id(), 'in_preview' => !empty($entity->in_preview)); $placeholder = drupal_render_cache_generate_placeholder($callback, $context); $build[$id]['links'] = array('#post_render_cache' => array($callback => array($context)), '#markup' => $placeholder); } if (!isset($build[$id]['#attached'])) { $build[$id]['#attached'] = array(); } $build[$id]['#attached']['library'][] = 'comment/drupal.comment-by-viewer'; if ($this->moduleHandler->moduleExists('history') && \Drupal::currentUser()->isAuthenticated()) { $build[$id]['#attached']['library'][] = 'comment/drupal.comment-new-indicator'; // Embed the metadata for the comment "new" indicators on this node. $build[$id]['#post_render_cache']['history_attach_timestamp'] = array(array('node_id' => $commented_entity->id())); } } }
/** * {@inheritdoc} */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode) { /** @var \Drupal\node\NodeInterface[] $entities */ if (empty($entities)) { return; } parent::buildComponents($build, $entities, $displays, $view_mode); foreach ($entities as $id => $entity) { $bundle = $entity->bundle(); $display = $displays[$bundle]; if ($display->getComponent('links')) { $build[$id]['links'] = array('#lazy_builder' => [get_called_class() . '::renderLinks', [$entity->id(), $view_mode, $entity->language()->getId(), !empty($entity->in_preview)]]); } // Add Language field text element to node render array. if ($display->getComponent('langcode')) { $build[$id]['langcode'] = array('#type' => 'item', '#title' => t('Language'), '#markup' => $entity->language()->getName(), '#prefix' => '<div id="field-language-display">', '#suffix' => '</div>'); } } }
/** * {@inheritdoc} */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode) { parent::buildComponents($build, $entities, $displays, $view_mode); foreach ($entities as $id => $entity) { $bundle = $entity->bundle(); $display = $displays[$bundle]; if ($display->getComponent('items')) { // When in summary view mode, respect the list_max setting. $limit = $view_mode == 'summary' ? $this->config->get('source.list_max') : 20; // Retrieve the items attached to this feed. $items = $this->entityManager->getStorage('aggregator_item')->loadByFeed($entity->id(), $limit); $build[$id]['items'] = $this->entityManager->getViewBuilder('aggregator_item')->viewMultiple($items, $view_mode, $entity->language()->getId()); if ($view_mode == 'full') { // Also add the pager. $build[$id]['pager'] = array('#type' => 'pager'); } } if ($display->getComponent('description')) { $build[$id]['description'] = array('#markup' => $entity->getDescription(), '#allowed_tags' => _aggregator_allowed_tags(), '#prefix' => '<div class="feed-description">', '#suffix' => '</div>'); } if ($display->getComponent('image')) { $image_link = array(); // Render the image as link if it is available. $image = $entity->getImage(); $label = $entity->label(); $link_href = $entity->getWebsiteUrl(); if ($image && $label && $link_href) { $link_title = array('#theme' => 'image', '#uri' => $image, '#alt' => $label); $image_link = array('#type' => 'link', '#title' => $link_title, '#url' => Url::fromUri($link_href), '#options' => array('attributes' => array('class' => array('feed-image')))); } $build[$id]['image'] = $image_link; } if ($display->getComponent('feed_icon')) { $build[$id]['feed_icon'] = array('#theme' => 'feed_icon', '#url' => $entity->getUrl(), '#title' => t('@title feed', array('@title' => $entity->label()))); } if ($display->getComponent('more_link')) { $title_stripped = strip_tags($entity->label()); $build[$id]['more_link'] = array('#type' => 'link', '#title' => t('More<span class="visually-hidden"> posts about @title</span>', array('@title' => $title_stripped)), '#url' => Url::fromRoute('entity.aggregator_feed.canonical', ['aggregator_feed' => $entity->id()]), '#options' => array('attributes' => array('title' => $title_stripped))); } } }
/** * {@inheritdoc} */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode) { parent::buildComponents($build, $entities, $displays, $view_mode); $panes = $this->orderPaneManager->getPanes(); $components = $displays['uc_order']->getComponents(); foreach ($entities as $id => $order) { foreach ($panes as $pane_id => $pane) { // Skip panes that are hidden in "Manage display". if (!isset($components[$pane_id])) { continue; } if ($contents = $pane->view($order, $view_mode)) { $build[$id][$pane_id] = array('#prefix' => '<div class="order-pane ' . $pane->getClasses() . '" id="order-pane-' . $pane_id . '">', '#suffix' => '</div>'); if ($title = $pane->getTitle()) { $build[$id][$pane_id]['title'] = array('#prefix' => '<div class="order-pane-title">', '#markup' => $title . ':', '#suffix' => '</div>'); } $build[$id][$pane_id]['pane'] = $contents; } } } }
/** * {@inheritdoc} */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { /** @var \Drupal\node\NodeInterface[] $entities */ if (empty($entities)) { return; } // Attach user account. user_attach_accounts($build, $entities); parent::buildComponents($build, $entities, $displays, $view_mode, $langcode); foreach ($entities as $id => $entity) { $bundle = $entity->bundle(); $display = $displays[$bundle]; $callback = '\\Drupal\\node\\NodeViewBuilder::renderLinks'; $context = array('node_entity_id' => $entity->id(), 'view_mode' => $view_mode, 'langcode' => $langcode, 'in_preview' => !empty($entity->in_preview)); $placeholder = drupal_render_cache_generate_placeholder($callback, $context); $build[$id]['links'] = array('#post_render_cache' => array($callback => array($context)), '#markup' => $placeholder); // Add Language field text element to node render array. if ($display->getComponent('langcode')) { $build[$id]['langcode'] = array('#type' => 'item', '#title' => t('Language'), '#markup' => $entity->language()->name, '#prefix' => '<div id="field-language-display">', '#suffix' => '</div>'); } } }
/** * {@inheritdoc} */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { parent::buildComponents($build, $entities, $displays, $view_mode, $langcode); // TODO: Change the autogenerated stub foreach ($entities as $id => $order) { $panes = _uc_order_pane_list($view_mode); foreach ($panes as $pane) { if (in_array($view_mode, $pane['show'])) { $func = $pane['callback']; if (function_exists($func) && ($contents = $func($view_mode, $order)) != NULL) { $title = isset($pane['display title']) ? $pane['display title'] : $pane['title']; if ($title) { $title = array('#markup' => $pane['title'] . ':', '#prefix' => '<div class="order-pane-title">', '#suffix' => '</div>'); } else { $title = array(); } $build[$id][$pane['id']] = array('#prefix' => '<div class="order-pane ' . $pane['class'] . '" id="order-pane-' . $pane['id'] . '">', '#suffix' => '</div>'); $build[$id][$pane['id']]['title'] = $title; $build[$id][$pane['id']]['pane'] = $contents; } } } } }