ProfileViewController.php in Profile 2 8
File
src/Controller/ProfileViewController.php
View source
<?php
namespace Drupal\profile\Controller;
use Drupal\Component\Utility\String;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Controller\EntityViewController;
class ProfileViewController extends EntityViewController {
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) {
$build['#attached']['drupal_add_html_head_link'][] = array(
array(
'rel' => $rel,
'href' => $profile
->url($rel),
),
TRUE,
);
if ($rel == 'canonical') {
$build['#attached']['drupal_add_html_head_link'][] = array(
array(
'rel' => 'shortlink',
'href' => $profile
->url($rel, array(
'alias' => TRUE,
)),
),
TRUE,
);
}
}
return $build;
}
public function title(EntityInterface $profile) {
return String::checkPlain($this->entityManager
->getTranslationFromContext($profile)
->label());
}
}