Incompatible with custom entities whose ids contain colons (:)

Created on 10 April 2018, over 7 years ago
Updated 19 August 2025, 24 days ago

In many areas of the module an item id is formed using [entity_type]:[entity_id]. To handle this, there are variations on the following code:

list($entity_type, $entity_id) = explode(':', $item);
return \Drupal::entityTypeManager()->getStorage($entity_type)->load($entity_id);

The issue I have is that I have custom entities that use colons in their ids, so the explode command is returning a partial entity id.

The patch I am submitting tweaks the explodes to limit them to two items like this:

list($entity_type, $entity_id) = explode(':', $item, 2);
return \Drupal::entityTypeManager()->getStorage($entity_type)->load($entity_id);

It's certainly an edge case, but a simple fix. There are other explode calls in the module that do similar things, such as the following, but I left them alone. Perhaps we should limit those as well?

if (!empty($values['view'])) {
      list($view_id, $display_id) = explode('.', $values['view']);
      $this->configuration['view'] = $view_id;
      $this->configuration['view_display'] = $display_id;
}

And

// Remove weight of entity being removed.
      foreach ($entity_ids as $entity_info) {
        $entity_id_info = explode('_', $entity_info['entity_id']);

        $form_state->unsetValue([
          'selected',
          $entity_info['entity_id'],
        ]);

        // Remove entity itself.
        $selected_entities = &$form_state->get(['entity_browser', 'selected_entities']);
        unset($selected_entities[$entity_id_info[2]]);
      }
πŸ› Bug report
Status

Needs work

Version

2.0

Component

Miscellaneous

Created by

πŸ‡ΊπŸ‡ΈUnited States steel-track

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