3 namespace Drupal\contextual\Element;
5 use Drupal\Core\Template\Attribute;
6 use Drupal\Core\Render\Element\RenderElement;
7 use Drupal\Component\Utility\SafeMarkup;
10 * Provides a contextual_links_placeholder element.
12 * @RenderElement("contextual_links_placeholder")
14 class ContextualLinksPlaceholder extends RenderElement {
19 public function getInfo() {
20 $class = get_class($this);
23 [$class, 'preRenderPlaceholder'],
30 * Pre-render callback: Renders a contextual links placeholder into #markup.
32 * Renders an empty (hence invisible) placeholder div with a data-attribute
33 * that contains an identifier ("contextual id"), which allows the JavaScript
34 * of the drupal.contextual-links library to dynamically render contextual
37 * @param array $element
38 * A structured array with #id containing a "contextual id".
41 * The passed-in element with a contextual link placeholder in '#markup'.
43 * @see _contextual_links_to_id()
45 public static function preRenderPlaceholder(array $element) {
46 $element['#markup'] = SafeMarkup::format('<div@attributes></div>', ['@attributes' => new Attribute(['data-contextual-id' => $element['#id']])]);