1 node.entity.inc public NodeStorageController::buildContent(EntityInterface $node, $view_mode = 'full', $langcode = NULL)

Implements EntityControllerInterface::buildContent().

Overrides DefaultEntityController::buildContent

File

core/modules/node/node.entity.inc, line 711
Entity controller and class for nodes.

Class

NodeStorageController
Controller class for nodes.

Code

public function buildContent(EntityInterface $node, $view_mode = 'full', $langcode = NULL) {
  global $language_content;
  $langcode = $langcode ? $langcode : $language_content->langcode;

  // Remove previously built content, if exists.
  $node->content = array();

  // Allow modules to change the display mode.
  $view_mode = key(entity_view_mode_prepare('node', array($node->nid => $node), $view_mode, $langcode));

  // The 'view' hook can be implemented to overwrite the default function
  // to display nodes.
  if (node_hook($node, 'view')) {
    $node = node_invoke($node, 'view', $view_mode, $langcode);
  }

  // Build fields content.
  // In case of a multiple view, node_view_multiple() already ran the
  // 'prepare_view' step. An internal flag prevents the operation from running
  // twice.
  field_attach_prepare_view('node', array($node->nid => $node), $view_mode, $langcode);
  entity_prepare_view('node', array($node->nid => $node));
  $node->content += field_attach_view('node', $node, $view_mode, $langcode);

  // Always display a read more link on teasers because we have no way
  // to know when a teaser view is different than a full view.
  $links = array();
  $node->content['links'] = array(
    '#theme' => 'links__node',
    '#pre_render' => array('backdrop_pre_render_links'),
    '#attributes' => array('class' => array('links', 'inline')),
  );
  if ($view_mode == 'teaser') {
    $type = node_type_get_type($node);
    // Don't add the "read more" link to the node if the type has a hidden path.
    if (!($type->settings['hidden_path'] && !user_access('view hidden paths'))) {
      $node_title_stripped = strip_tags($node->title);
      $links['node-readmore'] = array(
        'title' => t('Read more<span class="element-invisible"> about @title</span>', array('@title' => $node_title_stripped)),
        'href' => 'node/' . $node->nid,
        'html' => TRUE,
        'attributes' => array('rel' => 'tag', 'title' => $node_title_stripped),
      );
    }
  }
  $node->content['links']['node'] = array(
    '#theme' => 'links__node__node',
    '#links' => $links,
    '#attributes' => array('class' => array('links', 'inline')),
  );

  // Allow modules to make their own additions to the node.
  module_invoke_all('node_view', $node, $view_mode, $langcode);
  module_invoke_all('entity_view', $node, 'node', $view_mode, $langcode);

  // Make sure the current display mode is stored if no module has already
  // populated the related key.
  $node->content += array('#view_mode' => $view_mode);
}