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)| Comment | File | Size | Author |
|---|---|---|---|
| #17 | warning_invalid-2873350-17.patch | 1.23 KB | legolasbo |
| #15 | conditional_fields-warnings-notices-2873350-15.patch | 1.04 KB | Alex Andrascu |
Comments
Comment #2
hyscaler commentedComment #3
zviryatko commentedPlease remove debug functions.
Comment #4
zviryatko commentedComment #5
hyscaler commentedEven 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.
Comment #6
chrlvclaudiu commentedHi, looks like
$select_statesis not initialized and sometimes$options['values']is empty.This patch should solve this issue.
Comment #7
chrlvclaudiu commentedComment #8
robotjox commentedThis latest patch unfortunately didn't really help. I'm still seeing the error in log, and OR/NOT-conditionals are not working.
Comment #9
chrlvclaudiu commentedHi,
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.
Comment #10
OlgaRabodzei commentedHello!
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.
Comment #11
eric.napier commentedI 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").
Comment #12
eric.napier commentedComment #13
mikemadison commented@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
Comment #14
Alex Andrascu commentedPatch needs re-roll based on the latest version of dev
Comment #15
Alex Andrascu commentedIssue still exists in the latest dev for NOT and OR cases. The attached patch fixes it.
Minor changes to coding standards.
Comment #16
Alex Andrascu commentedComment #17
legolasboWhile 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.
Comment #18
Alex Andrascu commentedNice catch!
Comment #19
eric.chenchao commentedThe patch should work for those who want to use options
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.
Comment #20
rootworkComment #22
colanThanks! 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.
Comment #23
colan