class MasqueradeCallbacks in Masquerade 8.2
Masquerade callbacks.
Hierarchy
- class \Drupal\masquerade\MasqueradeCallbacks implements TrustedCallbackInterface
Expanded class hierarchy of MasqueradeCallbacks
1 string reference to 'MasqueradeCallbacks'
1 service uses MasqueradeCallbacks
File
- src/
MasqueradeCallbacks.php, line 12
Namespace
Drupal\masqueradeView source
class MasqueradeCallbacks implements TrustedCallbackInterface {
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The masquerade service.
*
* @var \Drupal\masquerade\Masquerade
*/
protected $masquerade;
/**
* MasqueradeCallbacks constructor.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\masquerade\Masquerade $masquerade
* The masuerade.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, Masquerade $masquerade) {
$this->entityTypeManager = $entity_type_manager;
$this->masquerade = $masquerade;
}
/**
* {@inheritdoc}
*/
public static function trustedCallbacks() {
return [
'renderCacheLink',
];
}
/**
* #post_render_cache callback; replaces placeholder with masquerade link.
*
* @param int $account_id
* The account ID.
*
* @return array
* A renderable array containing the masquerade link if allowed.
*/
public function renderCacheLink($account_id) {
/** @var \Drupal\user\UserInterface $account */
$account = $this->entityTypeManager
->getStorage('user')
->load($account_id);
if (masquerade_target_user_access($account)) {
// @todo Attaching a CSS class to this would be nice.
return [
'masquerade' => [
'#type' => 'link',
'#title' => new TranslatableMarkup('Masquerade as @name', [
'@name' => $account
->getDisplayName(),
]),
'#url' => $account
->toUrl('masquerade'),
],
];
}
return [
'#markup' => '',
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MasqueradeCallbacks:: |
protected | property | The entity type manager. | |
MasqueradeCallbacks:: |
protected | property | The masquerade service. | |
MasqueradeCallbacks:: |
public | function | #post_render_cache callback; replaces placeholder with masquerade link. | |
MasqueradeCallbacks:: |
public static | function |
Lists the trusted callbacks provided by the implementing class. Overrides TrustedCallbackInterface:: |
|
MasqueradeCallbacks:: |
public | function | MasqueradeCallbacks constructor. | |
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. |