class ContextualLinksPlaceholder
Same name and namespace in other branches
- 11.x core/modules/contextual/src/Element/ContextualLinksPlaceholder.php \Drupal\contextual\Element\ContextualLinksPlaceholder
- 10 core/modules/contextual/src/Element/ContextualLinksPlaceholder.php \Drupal\contextual\Element\ContextualLinksPlaceholder
- 9 core/modules/contextual/src/Element/ContextualLinksPlaceholder.php \Drupal\contextual\Element\ContextualLinksPlaceholder
- 8.9.x core/modules/contextual/src/Element/ContextualLinksPlaceholder.php \Drupal\contextual\Element\ContextualLinksPlaceholder
Provides a contextual_links_placeholder element.
Attributes
#[RenderElement('contextual_links_placeholder')]
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\DependencyInjection\AutowiredInstanceTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
- class \Drupal\Core\Render\Element\RenderElementBase implements \Drupal\Core\Render\Element\ElementInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\contextual\Element\ContextualLinksPlaceholder extends \Drupal\Core\Render\Element\RenderElementBase
- class \Drupal\Core\Render\Element\RenderElementBase implements \Drupal\Core\Render\Element\ElementInterface extends \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\DependencyInjection\AutowiredInstanceTrait, \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait extends \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of ContextualLinksPlaceholder
1 file declares its use of ContextualLinksPlaceholder
- ContextualUnitTest.php in core/
modules/ contextual/ tests/ src/ Kernel/ ContextualUnitTest.php
3 #type uses of ContextualLinksPlaceholder
- ContextualLinks::render in core/
modules/ contextual/ src/ Plugin/ views/ field/ ContextualLinks.php - Overrides \Drupal\views\Plugin\views\field\FieldPluginBase::render().
- ContextualThemeHooks::preprocess in core/
modules/ contextual/ src/ Hook/ ContextualThemeHooks.php - Implements hook_preprocess().
- ContextualUnitTest::testThemePlaceholder in core/
modules/ contextual/ tests/ src/ Kernel/ ContextualUnitTest.php - Tests the placeholder of contextual links in a specific theme.
File
-
core/
modules/ contextual/ src/ Element/ ContextualLinksPlaceholder.php, line 16
Namespace
Drupal\contextual\ElementView source
class ContextualLinksPlaceholder extends RenderElementBase {
/**
* {@inheritdoc}
*/
public function getInfo() {
return [
'#pre_render' => [
[
static::class,
'preRenderPlaceholder',
],
],
'#id' => NULL,
];
}
/**
* Pre-render callback: Renders a contextual links placeholder into #markup.
*
* Renders an empty (hence invisible) placeholder div with a data-attribute
* that contains an identifier ("contextual id"), which allows the JavaScript
* of the drupal.contextual-links library to dynamically render contextual
* links.
*
* @param array $element
* A structured array with #id containing a "contextual id".
*
* @return array
* The passed-in element with a contextual link placeholder in '#markup'.
*
* @see \Drupal\contextual\ContextualLinksSerializer::linksToId()
*/
public static function preRenderPlaceholder(array $element) {
$token = Crypt::hmacBase64($element['#id'], Settings::getHashSalt() . \Drupal::service('private_key')->get());
$attribute = new Attribute([
'data-contextual-id' => $element['#id'],
'data-contextual-token' => $token,
'data-drupal-ajax-container' => '',
]);
$element['#markup'] = new FormattableMarkup('<div@attributes></div>', [
'@attributes' => $attribute,
]);
$element['#attached']['drupalSettings']['contextual']['theme'] = \Drupal::service('theme.manager')->getActiveTheme()
->getName();
$cache = CacheableMetadata::createFromRenderArray($element);
$cache->addCacheContexts([
'theme',
]);
$cache->applyTo($element);
return $element;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.