I get this error on the backend and the conditionals don't work for select fields:

 Warning: Invalid argument supplied for foreach() in Drupal\conditional_fields\Plugin\conditional_fields\handler\Select->statesHandler() (line 47 of modules/contrib/conditional_fields/src/Plugin/conditional_fields/handler/Select.php).
Drupal\conditional_fields\Plugin\conditional_fields\handler\Select->statesHandler(Array, NULL, Array) (Line: 265)
conditional_fields_get_state(Object, 'fdsn_we_type_of_emp_extra', Array, Array) (Line: 124)
conditional_fields_form_after_build(Array, Object)
call_user_func_array('conditional_fields_form_after_build', Array) (Line: 1053)
Drupal\Core\Form\FormBuilder->doBuildForm('node_work_experience_edit_form', Array, Object) (Line: 557)
Drupal\Core\Form\FormBuilder->processForm('node_work_experience_edit_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 611)
Drupal\conditional_fields\Form\ConditionalFieldEditForm->getDummyField('node', 'work_experience', Array, Object, Array) (Line: 141)
Drupal\conditional_fields\Form\ConditionalFieldEditForm->buildForm(Array, Object, 'node', 'work_experience', 'fdsn_we_started_founded', '8d436c03-46ba-42b4-9250-c4e07355fff5')
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('conditional_field_edit_form_tab', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Notice: Undefined variable: select_states in Drupal\conditional_fields\Plugin\conditional_fields\handler\Select->statesHandler() (line 57 of modules/contrib/conditional_fields/src/Plugin/conditional_fields/handler/Select.php).
Drupal\conditional_fields\Plugin\conditional_fields\handler\Select->statesHandler(Array, NULL, Array) (Line: 265)
conditional_fields_get_state(Object, 'fdsn_we_type_of_emp_extra', Array, Array) (Line: 124)
conditional_fields_form_after_build(Array, Object)
call_user_func_array('conditional_fields_form_after_build', Array) (Line: 1053)
Drupal\Core\Form\FormBuilder->doBuildForm('node_work_experience_edit_form', Array, Object) (Line: 557)
Drupal\Core\Form\FormBuilder->processForm('node_work_experience_edit_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 611)
Drupal\conditional_fields\Form\ConditionalFieldEditForm->getDummyField('node', 'work_experience', Array, Object, Array) (Line: 141)
Drupal\conditional_fields\Form\ConditionalFieldEditForm->buildForm(Array, Object, 'node', 'work_experience', 'fdsn_we_started_founded', '8d436c03-46ba-42b4-9250-c4e07355fff5')
call_user_func_array(Array, Array) (Line: 514)
Drupal\Core\Form\FormBuilder->retrieveForm('conditional_field_edit_form_tab', Object) (Line: 271)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 144)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 656)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Comments

nettantra created an issue. See original summary.

hyscaler’s picture

Status: Active » Patch (to be ported)
StatusFileSize
new3.04 KB
zviryatko’s picture

+++ b/conditional_fields.api.inc	Thu Apr 27 19:32:21 2017 +0530
@@ -660,9 +660,10 @@
+  kint($options['values']);exit;

Please remove debug functions.

zviryatko’s picture

Status: Patch (to be ported) » Needs work
hyscaler’s picture

Even getting rid of the Error doesn't solve the Select List Conditional Issue.

My use case:

Field 1 - Text Field
Field 2 - Select Field

Field 1 should show up when Field 2 has Value F2

The earlier version of conditional_fields used to work. When I updated to yesterday's updated version it stopped working for select fields.

chrlvclaudiu’s picture

Hi, looks like $select_states is not initialized and sometimes $options['values'] is empty.
This patch should solve this issue.

chrlvclaudiu’s picture

Status: Needs work » Needs review
robotjox’s picture

This latest patch unfortunately didn't really help. I'm still seeing the error in log, and OR/NOT-conditionals are not working.

chrlvclaudiu’s picture

Hi,

Indeed my latest patch didn't solved the whole problem. Please check this next one.
Hope it works this time, at least the warnings are not showing up now.

OlgaRabodzei’s picture

Status: Needs review » Postponed (maintainer needs more info)

Hello!

Is this bug actual? The select widget is supported. Could someone recheck on the latest version, please? (alpha2 or dev)
Also it would be grate to have steps to reproduce.

Regards Olga.

eric.napier’s picture

I have tested off the latest release and I can confirm this bug still exists. The issue is that the switch case for CONDITIONAL_FIELDS_DEPENDENCY_VALUES_OR in the Select handler class does not convert the $options['values'] string to an array before iterating through its values as is a precedent in other parts of this module (see OptionsButtons.php handler or conditional_fields.api.inc for other examples). As a result the Warnings appear and the statesHandler method does not return the expected array result for the Select class. In my use case the conditional field is still functional even though the Warnings appear and the array returned by the statesHandler method is blank. The attached patch fixes both issues.

Additionally I made a small change to the return array in order for this case to work (conditional fields UI is broken as is once $options['values'] is converted to an array and statesHandler method can iterate through).

My use case:

1 Select Field w/ 4 values. 2 values are set as dependencies for a Body field to display (Values Input Mode set to "OR"), and 2 values are set as dependencies for an Image field to display (Values Input Mode set to "OR").

eric.napier’s picture

Status: Postponed (maintainer needs more info) » Needs review
mikemadison’s picture

Status: Needs review » Reviewed & tested by the community

@eric's patch applies cleanly for me and removes the php warnings from the screen. I noticed that it does fail the tests, but it looks like it failed the same tests as the current dev (so I don't think that is any fault of the patch he is proposing).

see https://www.drupal.org/node/206178/qa

Alex Andrascu’s picture

Status: Reviewed & tested by the community » Needs work

Patch needs re-roll based on the latest version of dev

Alex Andrascu’s picture

Status: Needs work » Needs review
StatusFileSize
new1.04 KB
new1.04 KB

Issue still exists in the latest dev for NOT and OR cases. The attached patch fixes it.
Minor changes to coding standards.

Alex Andrascu’s picture

legolasbo’s picture

Assigned: hyscaler » Unassigned
StatusFileSize
new1.23 KB

While reviewing the patch I noticed that $options['values'] isn't guaranteed to be an array. Configuring a single value makes $options['values'] a string instead of an array. We therefore need to cast it to an array.

Patch updated.

Alex Andrascu’s picture

Nice catch!

eric.chenchao’s picture

The patch should work for those who want to use options

  • Regular expression...
  • Any of these values (OR)...
  • Only one of these values (XOR)...
  • None of these values (NOT)...

I have only tested with the option Any of these values (OR)...

It still does not work when using option All these values (AND).... It is discussed in #2873406: Conditional Fields not Showing up on Select Fields with option 'All these values (AND)...'

Here is my situation:
When we used to use dev version released in 7th Apri 2017, and the select state works fine. After upgrading conditional_fields module to the latest dev, the select state becomes broken. As in the old version, there is no Select handler and it always falls back to the default handler. In the latest dev, SelectMultiple handler has been renamed to the Select handler which handles select state and fails.

rootwork’s picture

  • colan committed 8912643 on 8.x-1.x authored by legolasbo
    Issue #2873350 by Alex Andrascu, chrlvclaudiu, nettantra, eric.napier,...
colan’s picture

Status: Needs review » Fixed

Thanks! Let's deal with the other issue over there.

The last hunk didn't apply, but we didn't need it as converting to the new array syntax was handled in #2881629: Convert module to use short array syntax (new coding standard)..

I added a newline to the end of the file.

Status: Fixed » Closed (fixed)

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