core/modules/contextual/contextual.module | 12 +++++++++ .../Plugin/views/field/ContextualLinks.php | 27 ++++++++++++-------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/core/modules/contextual/contextual.module b/core/modules/contextual/contextual.module index d9a0461..24c18db 100644 --- a/core/modules/contextual/contextual.module +++ b/core/modules/contextual/contextual.module @@ -236,6 +236,18 @@ function contextual_pre_render_links($element) { } /** + * Implements hook_contextual_links_view_alter(). + * + * @see \Drupal\contextual\Plugin\views\field\ContextualLinks::render() + */ +function contextual_contextual_links_view_alter(&$element, $items) { + if (isset($element['#contextual_links']['contextual'])) { + $encoded_links = $element['#contextual_links']['contextual'][2]['contextual-views-field-links']; + $element['#links'] = drupal_json_decode(rawurldecode($encoded_links)); + } +} + +/** * Serializes #contextual_links property metadata to a "contextual id". * * Examples: diff --git a/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php b/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php index 5ef7df0..ea3f6cd 100644 --- a/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php +++ b/core/modules/contextual/lib/Drupal/contextual/Plugin/views/field/ContextualLinks.php @@ -67,6 +67,9 @@ function pre_render(&$values) { /** * Render the contextual fields. + * + * @see contextual_preprocess() + * @see contextual_contextual_links_view_alter() */ function render($values) { $links = array(); @@ -95,19 +98,21 @@ function render($values) { } } + // The code belows duplicates part of contextual_preprocess(). This is + // essential because if we use drupal_render() here, then hook_process() is + // not invoked, and consequently contextual_preprocess() isn't either. if (!empty($links)) { - $build = array( - '#prefix' => '
', - '#suffix' => '
', - '#theme' => 'links__contextual', - '#links' => $links, - '#attributes' => array('class' => array('contextual-links')), - '#attached' => array( - 'library' => array(array('contextual', 'contextual-links')), - ), - '#access' => user_access('access contextual links'), + $contextual_links = array( + 'contextual' => array( + '', + array(), + array( + 'contextual-views-field-links' => drupal_encode_path(drupal_json_encode($links)), + ) + ) ); - return drupal_render($build); + $id = _contextual_links_to_id($contextual_links); + return '
'; } else { return '';