class NodeViewController in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/modules/node/src/Controller/NodeViewController.php \Drupal\node\Controller\NodeViewController
Defines a controller to render a single node.
Hierarchy
- class \Drupal\Core\Entity\Controller\EntityViewController implements ContainerInjectionInterface
- class \Drupal\node\Controller\NodeViewController
Expanded class hierarchy of NodeViewController
File
- core/
modules/ node/ src/ Controller/ NodeViewController.php, line 16 - Contains \Drupal\node\Controller\NodeViewController.
Namespace
Drupal\node\ControllerView source
class NodeViewController extends EntityViewController {
/**
* {@inheritdoc}
*/
public function view(EntityInterface $node, $view_mode = 'full', $langcode = NULL) {
$build = parent::view($node, $view_mode, $langcode);
foreach ($node
->uriRelationships() as $rel) {
// Set the node path as the canonical URL to prevent duplicate content.
$build['#attached']['html_head_link'][] = array(
array(
'rel' => $rel,
'href' => $node
->url($rel),
),
TRUE,
);
if ($rel == 'canonical') {
// Set the non-aliased canonical path as a default shortlink.
$build['#attached']['html_head_link'][] = array(
array(
'rel' => 'shortlink',
'href' => $node
->url($rel, array(
'alias' => TRUE,
)),
),
TRUE,
);
}
}
return $build;
}
/**
* The _title_callback for the page that renders a single node.
*
* @param \Drupal\Core\Entity\EntityInterface $node
* The current node.
*
* @return string
* The page title.
*/
public function title(EntityInterface $node) {
return $this->entityManager
->getTranslationFromContext($node)
->label();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityViewController:: |
protected | property | The entity manager | |
EntityViewController:: |
protected | property | The renderer service. | |
EntityViewController:: |
public | function | Pre-render callback to build the page title. | |
EntityViewController:: |
public static | function |
Instantiates a new instance of this class. Overrides ContainerInjectionInterface:: |
|
EntityViewController:: |
public | function | Creates an EntityViewController object. | |
NodeViewController:: |
public | function | The _title_callback for the page that renders a single node. | |
NodeViewController:: |
public | function |
Provides a page to render a single entity. Overrides EntityViewController:: |