class ProfileViewController in Profile 2 8
Defines a controller to render a single profile entity.
Hierarchy
- class \Drupal\Core\Entity\Controller\EntityViewController implements ContainerInjectionInterface, TrustedCallbackInterface uses DeprecatedServicePropertyTrait
- class \Drupal\profile\Controller\ProfileViewController
Expanded class hierarchy of ProfileViewController
File
- src/
Controller/ ProfileViewController.php, line 17 - Contains \Drupal\profile\Controller\ProfileViewController.
Namespace
Drupal\profile\ControllerView source
class ProfileViewController extends EntityViewController {
/**
* {@inheritdoc}
*/
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;
}
/**
* The _title_callback for the page that renders a profile entity.
*
* @param \Drupal\Core\Entity\EntityInterface $profile
* The current profile.
*
* @return string
* The page title.
*/
public function title(EntityInterface $profile) {
return String::checkPlain($this->entityManager
->getTranslationFromContext($profile)
->label());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeprecatedServicePropertyTrait:: |
public | function | Allows to access deprecated/removed properties. | |
EntityViewController:: |
protected | property | ||
EntityViewController:: |
protected | property | The entity type 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:: |
2 |
EntityViewController:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
EntityViewController:: |
public | function | Provides a page to render a single entity revision. | |
EntityViewController:: |
public | function | Creates an EntityViewController object. | 2 |
ProfileViewController:: |
public | function | The _title_callback for the page that renders a profile entity. | |
ProfileViewController:: |
public | function |
Provides a page to render a single entity. Overrides EntityViewController:: |
|
TrustedCallbackInterface:: |
constant | Untrusted callbacks throw exceptions. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger silenced E_USER_DEPRECATION errors. | ||
TrustedCallbackInterface:: |
constant | Untrusted callbacks trigger E_USER_WARNING errors. |