Not compatible with config_split module

Created on 10 January 2024, 8 months ago
Updated 7 August 2024, about 1 month ago

Problem/Motivation

Error: Call to a member function bundle() on null in Drupal\conditional_fields\ConditionalFieldsElementAlterHelper->afterBuild() (line 64 of modules/contrib/conditional_fields/src/ConditionalFieldsElementAlterHelper.php).
conditional_fields_element_after_build(Array, Object)
call_user_func_array('conditional_fields_element_after_build', Array) (Line: 1083)

Steps to reproduce

Install config_split module composer require 'drupal/config_split:^2.0'
Go to admin/config/development/configuration/config-split/add

Not sure if it's a config_split or conditional_fields bug. I also logged a ticket in config_split module https://www.drupal.org/project/config_split/issues/3413597 ๐Ÿ› Not compatible with conditional_fields module Active

๐Ÿ› Bug report
Status

Closed: cannot reproduce

Version

4.0

Component

Code

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States khaldoon_masud

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

Merge Requests

Comments & Activities

  • Issue created by @khaldoon_masud
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia abhishek_virasat

    abhishek_gupta1 โ†’ made their first commit to this issueโ€™s fork.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 8 months ago
    130 pass
  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia abhishek_virasat

    @khaldoon_masud, I have fixed the issue. Please kindly review the MR

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States khaldoon_masud

    @abhishek_gupta1 That patch did not fix the issue, because the error is thrown in the upper IF condition not in the ELSE condition:

    if ($inline_entity_form_parents = ConditionalFieldsFormHelper::findInlineEntityFormParentsForElement($full_form, $field)) {
              $form = &NestedArray::getValue($full_form, $inline_entity_form_parents['element_parents']);
    
              // Remove outer forms from field parents arrays.
              $field = ConditionalFieldsFormHelper::fieldRemoveInlineEntityFormParents($field, $inline_entity_form_parents);
    
              $ief_entity = $form["#entity"];
              $bundle = $ief_entity->bundle();
              $entity_type = $ief_entity->getEntityTypeId();
            }
            else {
              $form = &$full_form;
              $bundle = $entity->bundle();
              $entity_type = $entity->getEntityTypeId();
    
              /**
               * @deprecated Not actual from Drupal 8.7.0.
               * Media entity returns the actual bundle object, rather than id
               */
              if (is_object($bundle) && method_exists($bundle, 'getPluginId')) {
                $bundle = $bundle->getPluginId();
              } elseif (is_object($bundle) && method_exists($bundle, 'bundle')) {
                $bundle = $bundle->bundle();
              }
            }
    

    $ief_entity is NULL cause $form["#entity"] is NULL, thus $ief_entity->bundle() throws an error.

    The fix should be something like:

    if (!isset($form["#entity"])) {
     return;
    }
  • ๐Ÿ‡จ๐Ÿ‡ฆCanada Liam Morland Ontario, CA ๐Ÿ‡จ๐Ÿ‡ฆ

    On a site with both conditional_fields and config_split installed, I visited admin/config/development/configuration/config-split/add and did not see any error message. There must be more required to generate the error.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sumit-k

    Upon attempting to replicate the reported issue, I have followed the outlined steps, which involved installing both the Config Split and Conditional Field modules and navigating to the specified configuration page at "admin/config/development/configuration/config-split/add." However, I was unable to encounter the issue as described.
    Should have any additional details or steps to provide.

  • ๐Ÿ‡ช๐Ÿ‡ธSpain dcimorra

    This problem is caused by having applied the patch (in my case) https://www.drupal.org/files/issues/2023-10-30/2856720-support-for-inlin... โ†’ .

    Removed the patch, it works correctly.

  • Status changed to Closed: cannot reproduce 6 months ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany diqidoq Berlin | Hamburg | New York | London | Paris

    As of #6/#7 and me testing I cannot reproduce this issue. All other reports rather tend to make clear that this issue is caused by other circumstances. Feel free to reopen if more/better information to reprocude this issue can be provided. Thanks for all the efforts in here!

  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany diqidoq Berlin | Hamburg | New York | London | Paris

    And also, please provide patches and MR always against latest dev. Thanks for understanding.

  • Install modules:
    drupal/conditional_fields
    drupal/entity_translation_sync

    Set a conditional field to some Content Type.
    Then go to edit page to create/edit some Node and in a tab Entity Translation Sync you can see error:

    The website encountered an unexpected error. Try again later.
    
    Error: Call to protected method Drupal\entity_translation_sync\Form\EntityTranslationSyncForm::getEntity() from scope Drupal\conditional_fields\ConditionalFieldsElementAlterHelper in Drupal\conditional_fields\ConditionalFieldsElementAlterHelper->afterBuild() (line 53 of modules/contrib/conditional_fields/src/ConditionalFieldsElementAlterHelper.php). 
Production build 0.71.5 2024