function ContextualLinksSerializer::idToLinks

Unserializes the result of ::linksToId().

Note that $id is user input. Before calling this method the ID should be checked against the token stored in the 'data-contextual-token' attribute which is passed via the 'tokens' request parameter to \Drupal\contextual\ContextualController::render().

Parameters

string $id: A serialized representation of a #contextual_links property value array.

Return value

array The value for a #contextual_links property.

See also

self::linksToId()

\Drupal\contextual\ContextualController::render()

File

core/modules/contextual/src/ContextualLinksSerializer.php, line 76

Class

ContextualLinksSerializer
Helper methods to handle contextual links <-> ID conversion.

Namespace

Drupal\contextual

Code

public function idToLinks(string $id) : array {
  $contextualLinks = [];
  foreach (explode('|', $id) as $context) {
    [$group, $routeParametersRaw, $metadataRaw] = explode(':', $context);
    parse_str($routeParametersRaw, $routeParameters);
    $metadata = [];
    parse_str($metadataRaw, $metadata);
    $contextualLinks[$group] = [
      'route_parameters' => $routeParameters,
      'metadata' => $metadata,
    ];
  }
  return $contextualLinks;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.