When I visit http://my-site.local/admin/structure/conditional_fields/taxonomy_term/VO... I get the following error:

Warning: Undefined variable $entity_type in Drupal\conditional_fields\Form\ConditionalFieldForm->buildTable() (line 297 of modules/contrib/conditional_fields/src/Form/ConditionalFieldForm.php)

Link to code line:
https://git.drupalcode.org/project/conditional_fields/-/blob/8.x-1.x/src...

So $entity_type and also $bundle_name which is used a little further down are not declared in this method/function. This can't work. I don't understand how this module works so I am not able to fix this on my own.

    if (empty($form_display_entity) && $entity_type == 'taxonomy_term') {
      $form_display_entity = $this->entityTypeManager->getStorage('entity_form_display')->create([
        'targetEntityType' => 'taxonomy_term',
        'bundle' => $bundle_name,
        'mode' => 'default',
        'status' => TRUE,
      ]);
    }

Steps:

  • Got to /admin/structure/conditional_fields/taxonomy_term/YOUR_TAXONOMY
  • Notice that it will not show the option to add a new dependency and it will show an message at the log messages.

Comments

kitikonti created an issue. See original summary.

kitikonti’s picture

Status: Active » Needs review
StatusFileSize
new818 bytes

Ok maybe I found the solution. But someone who knows what he is doing should confirm this :-).

coaston’s picture

Hello,

I found this issue when i tried to visit different bundle, not taxonomy, but schedule (business rules module) and i had the same error, after that I found it does not matter which bundle I select in conditional fields - i am getting the same error. So I tried to apply you path and it seems it works fine and no warnings.

Looks good. thx

hmendes’s picture

Version: 8.x-1.x-dev » 4.x-dev
Issue summary: View changes
StatusFileSize
new818 bytes

Re-rolling patch from #2 for the 4.x-dev version.

gabriel.abdalla’s picture

Steps performed:

1. Installed dev version of module using composer: lando composer require 'drupal/conditional_fields:4.x-dev@dev'
2. Created a "Test Vocabulary" (machine name: test_vocabulary)
3. Added few test terms to "Test Vocabolary" (Image attached).
4. Accessed path /admin/structure/conditional_fields/taxonomy_term/test_vocabulary
5. Checked logs at Reports -> Recent log messages. Error was reproduced (images attached).
6. Applied patch 3191870-4.patch.
7. Code review performed on changed file.
8. Run phpcs for standards Drupal and DrupalPractice against changed file.
9. Deleted log messages at "Reports -> Recent log messages".
10. Tested again (steps 4 and 5). Issue was fixed with patch (images attached).

Few phpcs fixes are required in file src/Form/ConditionalFieldForm (image attached) but they are not related to changes in 3191870-4.patch.
Thus they can be addressed in other issues.

dianacastillo’s picture

Status: Reviewed & tested by the community » Needs work

Using drupal 9.37 after this patch i get

Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException: You have requested a non-existent service "conditional_fields.element_alter_helper". Did you mean this: "conditional_fields.form_helper"? in Drupal\Component\DependencyInjection\Container->get() (line 156 of core/lib/Drupal/Component/DependencyInjection/Container.php).
landure’s picture

@dianacastillo : the ServiceNotFoundException is solved by running `drush cr`.

lucienchalom’s picture

StatusFileSize
new161.09 KB

I was looking into the module and this same problem happens in:
Contact message, Content moderation state, File, custom menu links, url alias, shortcut links and taxonomy.
all of them I found in /admin/structure/conditional_fields

attached a print of one of the errors, as an example.

bruno.bicudo’s picture

Status: Needs work » Reviewed & tested by the community

#4 applied smoothly, no errors on patch application.

It indeed requires a drush cr to solve the service DI pointed in #7.

I tested with every item on the list to check what #8 pointed, also created some random conditionals for different targets, and still no errors on the log after the patch.

Moving to RTBC :)

crutch’s picture

experienced this issue at /config/people/accounts/conditionals

patch works thank you

  • kitikonti authored a91da3d9 on 4.x
    Issue #3191870 by kitikonti, hmendes: Warning: Undefined variable $...
saurabh-2k17’s picture

Status: Reviewed & tested by the community » Fixed

Thank you everyone for your efforts.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.