comparison core/modules/contextual/src/Element/ContextualLinksPlaceholder.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2 2
3 namespace Drupal\contextual\Element; 3 namespace Drupal\contextual\Element;
4 4
5 use Drupal\Component\Utility\Crypt;
6 use Drupal\Core\Site\Settings;
5 use Drupal\Core\Template\Attribute; 7 use Drupal\Core\Template\Attribute;
6 use Drupal\Core\Render\Element\RenderElement; 8 use Drupal\Core\Render\Element\RenderElement;
7 use Drupal\Component\Utility\SafeMarkup; 9 use Drupal\Component\Render\FormattableMarkup;
8 10
9 /** 11 /**
10 * Provides a contextual_links_placeholder element. 12 * Provides a contextual_links_placeholder element.
11 * 13 *
12 * @RenderElement("contextual_links_placeholder") 14 * @RenderElement("contextual_links_placeholder")
41 * The passed-in element with a contextual link placeholder in '#markup'. 43 * The passed-in element with a contextual link placeholder in '#markup'.
42 * 44 *
43 * @see _contextual_links_to_id() 45 * @see _contextual_links_to_id()
44 */ 46 */
45 public static function preRenderPlaceholder(array $element) { 47 public static function preRenderPlaceholder(array $element) {
46 $element['#markup'] = SafeMarkup::format('<div@attributes></div>', ['@attributes' => new Attribute(['data-contextual-id' => $element['#id']])]); 48 $token = Crypt::hmacBase64($element['#id'], Settings::getHashSalt() . \Drupal::service('private_key')->get());
49 $attribute = new Attribute([
50 'data-contextual-id' => $element['#id'],
51 'data-contextual-token' => $token,
52 ]);
53 $element['#markup'] = new FormattableMarkup('<div@attributes></div>', ['@attributes' => $attribute]);
47 54
48 return $element; 55 return $element;
49 } 56 }
50 57
51 } 58 }