Mercurial > hg > isophonics-drupal-site
annotate core/modules/contextual/src/Element/ContextualLinksPlaceholder.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\contextual\Element; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Core\Template\Attribute; |
Chris@0 | 6 use Drupal\Core\Render\Element\RenderElement; |
Chris@0 | 7 use Drupal\Component\Utility\SafeMarkup; |
Chris@0 | 8 |
Chris@0 | 9 /** |
Chris@0 | 10 * Provides a contextual_links_placeholder element. |
Chris@0 | 11 * |
Chris@0 | 12 * @RenderElement("contextual_links_placeholder") |
Chris@0 | 13 */ |
Chris@0 | 14 class ContextualLinksPlaceholder extends RenderElement { |
Chris@0 | 15 |
Chris@0 | 16 /** |
Chris@0 | 17 * {@inheritdoc} |
Chris@0 | 18 */ |
Chris@0 | 19 public function getInfo() { |
Chris@0 | 20 $class = get_class($this); |
Chris@0 | 21 return [ |
Chris@0 | 22 '#pre_render' => [ |
Chris@0 | 23 [$class, 'preRenderPlaceholder'], |
Chris@0 | 24 ], |
Chris@0 | 25 '#id' => NULL, |
Chris@0 | 26 ]; |
Chris@0 | 27 } |
Chris@0 | 28 |
Chris@0 | 29 /** |
Chris@0 | 30 * Pre-render callback: Renders a contextual links placeholder into #markup. |
Chris@0 | 31 * |
Chris@0 | 32 * Renders an empty (hence invisible) placeholder div with a data-attribute |
Chris@0 | 33 * that contains an identifier ("contextual id"), which allows the JavaScript |
Chris@0 | 34 * of the drupal.contextual-links library to dynamically render contextual |
Chris@0 | 35 * links. |
Chris@0 | 36 * |
Chris@0 | 37 * @param array $element |
Chris@0 | 38 * A structured array with #id containing a "contextual id". |
Chris@0 | 39 * |
Chris@0 | 40 * @return array |
Chris@0 | 41 * The passed-in element with a contextual link placeholder in '#markup'. |
Chris@0 | 42 * |
Chris@0 | 43 * @see _contextual_links_to_id() |
Chris@0 | 44 */ |
Chris@0 | 45 public static function preRenderPlaceholder(array $element) { |
Chris@0 | 46 $element['#markup'] = SafeMarkup::format('<div@attributes></div>', ['@attributes' => new Attribute(['data-contextual-id' => $element['#id']])]); |
Chris@0 | 47 |
Chris@0 | 48 return $element; |
Chris@0 | 49 } |
Chris@0 | 50 |
Chris@0 | 51 } |