_contextual_links_to_id($contextual_links)
Serializes #contextual_links property value array to a string.
Examples:
- node:node=1:langcode=en
- views_ui_edit:view=frontpage:location=page&view_name=frontpage&view_display_id=page_1&langcode=en
- menu:menu=tools:langcode=en|block:block=bartik.tools:langcode=en
So, expressed in a pattern: <group>:<route parameters>:<metadata>
The route parameters and options are encoded as query strings.
Parameters
array $contextual_links: The $element['#contextual_links'] value for some render element.
Return value
string A serialized representation of a #contextual_links property value array for use in a data- attribute.
File
- core/modules/contextual/contextual.module, line 174
- Adds contextual links to perform actions related to elements on a page.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | function _contextual_links_to_id( $contextual_links ) { $ids = array (); $langcode = \Drupal::languageManager()->getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(); foreach ( $contextual_links as $group => $args ) { $route_parameters = UrlHelper::buildQuery( $args [ 'route_parameters' ]); $args += [ 'metadata' => []]; // Add the current URL language to metadata so a different ID will be // computed when URLs vary by language. This allows to store different // language-aware contextual links on the client side. $args [ 'metadata' ] += [ 'langcode' => $langcode ]; $metadata = UrlHelper::buildQuery( $args [ 'metadata' ]); $ids [] = "{$group}:{$route_parameters}:{$metadata}" ; } return implode( '|' , $ids ); } |
Please login to continue.