Notice: Undefined offset: 2 in _contextual_id_to_links()

Created on 6 May 2020, over 4 years ago
Updated 26 February 2024, 11 months ago

We got an:

Notice: Undefined offset: 2 in _contextual_id_to_links() (line 213 in /web/core/modules/contextual/contextual.module).

If we use it like this:

{{ contextual_links('block_content:block_content=' ~ block_id) }}

It works fine, but the notice appears randomly.

This is the function throwing the error:

/**
 * Unserializes the result of _contextual_links_to_id().
 *
 * 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().
 *
 * @param string $id
 *   A serialized representation of a #contextual_links property value array.
 *
 * @return array
 *   The value for a #contextual_links property.
 *
 * @see _contextual_links_to_id()
 * @see \Drupal\contextual\ContextualController::render()
 */
function _contextual_id_to_links($id) {
  $contextual_links = [];
  $contexts = explode('|', $id);
  foreach ($contexts as $context) {
    list($group, $route_parameters_raw, $metadata_raw) = explode(':', $context);
    parse_str($route_parameters_raw, $route_parameters);
    $metadata = [];
    parse_str($metadata_raw, $metadata);
    $contextual_links[$group] = [
      'route_parameters' => $route_parameters,
      'metadata' => $metadata,
    ];
  }
  return $contextual_links;
}
🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024