public function ProfileViewController::view in Profile 2 8
Provides a page to render a single entity.
Parameters
\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.
string $view_mode: (optional) The view mode that should be used to display the entity. Defaults to 'full'.
Return value
array A render array as expected by \Drupal\Core\Render\RendererInterface::render().
Overrides EntityViewController::view
1 string reference to 'ProfileViewController::view'
File
- src/
Controller/ ProfileViewController.php, line 22 - Contains \Drupal\profile\Controller\ProfileViewController.
Class
- ProfileViewController
- Defines a controller to render a single profile entity.
Namespace
Drupal\profile\ControllerCode
public function view(EntityInterface $profile, $view_mode = 'full', $langcode = NULL) {
$build = array(
'profiles' => \Drupal::entityManager()
->getViewBuilder($profile
->getEntityTypeId())
->view($profile, $view_mode, $langcode),
);
$build['#title'] = $profile
->label();
foreach ($profile
->uriRelationships() as $rel) {
// Set the profile path as the canonical URL to prevent duplicate content.
$build['#attached']['drupal_add_html_head_link'][] = array(
array(
'rel' => $rel,
'href' => $profile
->url($rel),
),
TRUE,
);
if ($rel == 'canonical') {
// Set the non-aliased canonical path as a default shortlink.
$build['#attached']['drupal_add_html_head_link'][] = array(
array(
'rel' => 'shortlink',
'href' => $profile
->url($rel, array(
'alias' => TRUE,
)),
),
TRUE,
);
}
}
return $build;
}