I am using the Profile module 8.x-1.0-alpha5 and Conditional Fields 8.x-1.x-dev on Drupal 8.2.5. I am trying to make one field on the profile conditional on another, but when I do I get two exceptions:

Notice: Undefined offset: 0 in Drupal\file\Plugin\Field\FieldWidget\FileWidget->formMultipleElements() (line 196 of core/modules/file/src/Plugin/Field/FieldWidget/FileWidget.php).
Drupal\file\Plugin\Field\FieldWidget\FileWidget->formMultipleElements(Object, Array, Object) (Line: 84)
Drupal\image\Plugin\Field\FieldWidget\ImageWidget->formMultipleElements(Object, Array, Object) (Line: 104)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 168)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 54)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 115)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)

Notice: Undefined offset: 0 in Drupal\image\Plugin\Field\FieldWidget\ImageWidget->formMultipleElements() (line 90 of core/modules/image/src/Plugin/Field/FieldWidget/ImageWidget.php).
Drupal\image\Plugin\Field\FieldWidget\ImageWidget->formMultipleElements(Object, Array, Object) (Line: 104)
Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 168)
Drupal\Core\Entity\Entity\EntityFormDisplay->buildForm(Object, Array, Object) (Line: 54)
Drupal\Core\Entity\ContentEntityForm->form(Array, Object) (Line: 115)
Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 514)

The dependent is a text field and the dependee is a taxonomy term list.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

DarkstarTom created an issue. See original summary.

OlgaRabodzei’s picture

Status: Active » Postponed
Related issues: +#2867717: Support select

The plugin for a select widget is under developing.
If You had multiply select it was added in the last release (2017-Apr-07)
Regards.

OlgaRabodzei’s picture

Status: Postponed » Fixed

Resolved in the release 2017-Apr-26

DarkstarTom’s picture

I have upgraded to the 2017-Apr-26 version and I still have this error.

OlgaRabodzei’s picture

Status: Fixed » Needs work
Mars0test’s picture

I the problem is real when you don't create conditional field about date's field.
There isn't check if

$value[0]['value']

exist.

a simple isset() to check if array exist should be good.

Anhh sorry, I have not fix the problème from the issue. Because i can't reproduce the problem.

The problem solve by my patch is the notice :

Warning: Illegal string offset 'value' in Drupal\conditional_fields\Form\ConditionalFieldEditForm->submitForm() (line 327 of modules/contrib/conditional_fields/src/Form/ConditionalFieldEditForm.php).
Drupal\conditional_fields\Form\ConditionalFieldEditForm->submitForm(Array, Object) (Line: 29)
Drupal\conditional_fields\Form\ConditionalFieldEditFormTab->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('conditional_field_edit_form_tab', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('conditional_field_edit_form_tab', 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: 153)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
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)

and the notice :

Notice: Undefined offset: 0 in Drupal\conditional_fields\Form\ConditionalFieldEditForm->submitForm() (line 327 of modules/contrib/conditional_fields/src/Form/ConditionalFieldEditForm.php).
Drupal\conditional_fields\Form\ConditionalFieldEditForm->submitForm(Array, Object) (Line: 29)
Drupal\conditional_fields\Form\ConditionalFieldEditFormTab->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 585)
Drupal\Core\Form\FormBuilder->processForm('conditional_field_edit_form_tab', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('conditional_field_edit_form_tab', 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: 153)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
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)

darol100’s picture

Assigned: Mars0test » Unassigned
Status: Needs review » Needs work

The patch from #6 is not longer applicable.

darol100’s picture

Here is the update version of the patch.

colan’s picture

+++ b/src/Form/ConditionalFieldEditForm.php
@@ -313,14 +313,17 @@ class ConditionalFieldEditForm extends FormBase {
+        if (isset($value[0]['value'])) {
+          if (is_object($value[0]['value']) && $value[0]['value'] instanceof DrupalDateTime) {

Can we combine these into one line?


+++ b/src/Form/ConditionalFieldEditForm.php
@@ -313,14 +313,17 @@ class ConditionalFieldEditForm extends FormBase {
+                $value[$delta]['value'] = $date['value']->format('Y-m-d');

What's the reason for switching from a constant to a literal here? What's wrong with DATETIME_DATE_STORAGE_FORMAT?

colan’s picture

Status: Needs review » Needs work
colan’s picture

Status: Needs work » Closed (duplicate)

This issue is older, but #2908866: Undefined index value in ConditionalFieldEditForm->submitForm has a better patch, and it's already RTBC.

Road Kill’s picture