Chris@0: [ Chris@0: [$class, 'preRenderPlaceholder'], Chris@0: ], Chris@0: '#id' => NULL, Chris@0: ]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Pre-render callback: Renders a contextual links placeholder into #markup. Chris@0: * Chris@0: * Renders an empty (hence invisible) placeholder div with a data-attribute Chris@0: * that contains an identifier ("contextual id"), which allows the JavaScript Chris@0: * of the drupal.contextual-links library to dynamically render contextual Chris@0: * links. Chris@0: * Chris@0: * @param array $element Chris@0: * A structured array with #id containing a "contextual id". Chris@0: * Chris@0: * @return array Chris@0: * The passed-in element with a contextual link placeholder in '#markup'. Chris@0: * Chris@0: * @see _contextual_links_to_id() Chris@0: */ Chris@0: public static function preRenderPlaceholder(array $element) { Chris@17: $token = Crypt::hmacBase64($element['#id'], Settings::getHashSalt() . \Drupal::service('private_key')->get()); Chris@17: $attribute = new Attribute([ Chris@17: 'data-contextual-id' => $element['#id'], Chris@17: 'data-contextual-token' => $token, Chris@17: ]); Chris@17: $element['#markup'] = new FormattableMarkup('', ['@attributes' => $attribute]); Chris@0: Chris@0: return $element; Chris@0: } Chris@0: Chris@0: }