Problem/Motivation

After creating a new index and saving it without any fields, I get the following message.
Note: This message is displayed only if I click the save button when in the "Fields" tab (/admin/config/search/search-api/index/node_index/fields).

Notice: Undefined index: fields in Drupal\search_api\Form\IndexFieldsForm->validateForm() (line 417 of modules/contrib/search_api/src/Form/IndexFieldsForm.php).
Drupal\search_api\Form\IndexFieldsForm->validateForm(Array, Object)
call_user_func_array(Array, Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 273)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'search_api_index_fields') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('search_api_index_fields', Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('search_api_index_fields', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
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}() (Line: 151)
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Warning: Invalid argument supplied for foreach() in Drupal\search_api\Form\IndexFieldsForm->validateForm() (line 420 of modules/contrib/search_api/src/Form/IndexFieldsForm.php).
Drupal\search_api\Form\IndexFieldsForm->validateForm(Array, Object)
call_user_func_array(Array, Array) (Line: 82)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 273)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'search_api_index_fields') (Line: 118)
Drupal\Core\Form\FormValidator->validateForm('search_api_index_fields', Array, Object) (Line: 589)
Drupal\Core\Form\FormBuilder->processForm('search_api_index_fields', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 91)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 573)
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}() (Line: 151)
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 708)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

Steps to reproduce

Add a new index of type Content. Save it.

Proposed resolution

Remaining tasks

Comments

Amir Simantov created an issue. See original summary.

amir simantov’s picture

Issue summary: View changes
drunken monkey’s picture

Version: 8.x-1.18 » 8.x-1.x-dev
Status: Active » Needs review
StatusFileSize
new4.04 KB

Thanks a lot for reporting this problem, and sorry it took me a while to reply.
I could easily reproduce the buggy behavior, and the fix seems simple. At a quick search, I also found similar (potentially buggy) code in other parts of the module, so I’m fixing this all at once.

Patch attached, please test/review!

drunken monkey’s picture

Committed. Thanks again!

  • drunken monkey committed d30cf41 on 8.x-1.x
    Issue #3190751 by drunken monkey: Fixed unsafe form value access in...
drunken monkey’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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