IEF: entity_type not observed

Created on 31 August 2023, about 1 year ago
Updated 31 October 2023, about 1 year ago

Problem/Motivation

I have a form with more than one IEF of different entity types. If I have two plugins, each specifying its own entity_type, both will be called regardless of the actual type. Actually, I couldn't find anything in the code that actually uses the entity_type of the annotation for any decision at all.

As the handlers in the .module file don't pass $context to the plugins, we can't make a single plugin working on different types, with a switch statement branching one those types, either (which would be nothing more than the equivalent of the original alter hooks, anyway, so there wouldn't be any reason to do so even if it worked).

Proposed resolution

Only call the plugin of the matching type.

🐛 Bug report
Status

Fixed

Version

1.5

Component

Code

Created by

🇭🇺Hungary djg_tram

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

Comments & Activities

  • Issue created by @djg_tram
  • 🇭🇺Hungary djg_tram

    A quick solution would be to change the condition near the end of InlineEntityFormAlterManager::getInstance() to:

          if (
            (($options['type'] == 'table_fields') && !empty($configuration) && $options['entity_type'] == $definition['entity_type'] && $options['parent_entity_type'] == $definition['parent_entity_type'])
          ) {
    

    Actually, I can't decide what the optional part comparing the counts of the two array was intended to do in the first place...

  • 🇭🇺Hungary djg_tram

    A better way that, I think, handless all cases:

    switch ($options['type']) {
      case 'table_fields':
        if (!empty($configuration) && $options['entity_type'] == $definition['entity_type'] && $options['parent_entity_type'] == $definition['parent_entity_type'])
          $plugins[$plugin_id] = $this->createInstance($plugin_id, $configuration);
        break;
      default:
        if (!empty($configuration) && $options['entity_type'] == $definition['entity_type'] && $options['bundle'] == $definition['bundle'])
        $plugins[$plugin_id] = $this->createInstance($plugin_id, $configuration);
        break;
    }
    
  • 🇮🇹Italy aronne

    Hi @djg_tram,
    could you try this patch and let me know if it works correctly for you?
    Thanks.

  • Status changed to Needs review about 1 year ago
  • Status changed to Active about 1 year ago
    • aronne authored 5b180e5c on 8.x-1.x
      Issue #3384561 by djg_tram, aronne: IEF: entity_type not observed
      
  • Status changed to Fixed about 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024