TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in implode()

Created on 27 June 2022, over 2 years ago
Updated 9 January 2024, 11 months ago

Dear all,
getting an error when try to open
view -> edit-> Advanced -> Query settings -> settings

The website encountered an unexpected error. Please try again later.
TypeError: implode(): Argument #1 ($pieces) must be of type array, string given in implode() (line 319 of core/modules/views/src/Plugin/views/query/Sql.php).
implode() (Line: 319)
Drupal\views\Plugin\views\query\Sql->buildOptionsForm() (Line: 1618)
Drupal\views\Plugin\views\display\DisplayPluginBase->buildOptionsForm() (Line: 440)
Drupal\views\Plugin\views\display\PathPluginBase->buildOptionsForm() (Line: 257)
Drupal\views\Plugin\views\display\Page->buildOptionsForm() (Line: 74)
Drupal\views_ui\Form\Ajax\Display->buildForm()
call_user_func_array() (Line: 531)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 278)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 215)
Drupal\views_ui\Form\Ajax\ViewsFormBase->Drupal\views_ui\Form\Ajax\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 217)
Drupal\views_ui\Form\Ajax\ViewsFormBase->ajaxFormWrapper() (Line: 127)
Drupal\views_ui\Form\Ajax\ViewsFormBase->getForm() (Line: 46)
Drupal\views_ui\Form\Ajax\Display->getForm()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 158)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 708)
Drupal\Core\DrupalKernel->handle() (Line: 19)

🐛 Bug report
Status

Postponed: needs info

Version

9.5

Component
Other 

Last updated about 7 hours ago

Created by

🇮🇳India Toby_toby

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • I am assuming this is outdated. Re-open it if needed.

  • 🇩🇪Germany e5sego

    Hi, I run into the exact same issue as described.

  • Status changed to Postponed: needs info over 1 year ago
  • I think we are seeking precise reproduction steps. Those belong in the issue summary.

  • 🇳🇱Netherlands Marceldeb

    Subscribing. Having the same issue.

    i also upgraded the Drupal version and php version (from 7.x to 8.x). Currently on Drupal 9.5 and still having the issue.

    On my site only the REST Export view type seems to be affected.

  • 🇳🇱Netherlands Marceldeb

    I could not reproduce this issue but i would like to share a fix. Apparently something in the database is not correct in some of the views / displays.

    How to fix:

    319 of core/modules/views/src/Plugin/views/query/Sql.php:

        $form['query_tags'] = [
          '#type' => 'textfield',
          '#title' => $this->t('Query Tags'),
          '#description' => $this->t('If set, these tags will be appended to the query and can be used to identify the query in a module. This can be helpful for altering queries.'),
          '#default_value' => implode(', ', $this->options['query_tags']),
          '#element_validate' => ['views_element_validate_tags'],
        ];
    

    Then remove the following line:

          '#default_value' => implode(', ', $this->options['query_tags']),
    

    Open your display / view. Open the query settings. Re-save the view.

    Now restore the 319 of core/modules/views/src/Plugin/views/query/Sql.php back to original state.

    My guess is that for some reason $this->options['query_tags'] sometimes returns a string. Which is strange because in my case the value was empty. Maybe something old in the database? Who knows. I did a check using kint($this->options['query_tags']) and the value was empty / null.

    Anyway, i did not see any bug in the Drupal code.

  • 🇳🇱Netherlands Marceldeb

    I checked my config to see what changed after my above fix. It seems that the query tags were first saved as object in the database, and now as an null.

    So the bug is in the Drupal config which changed..and probably during upgrades core devs forgot to handle this.

    See image.

  • 🇺🇸United States xeiro

    I can confirm the same issue as @Marceldeb. Steps to reproduce were making a switch from Other>Caching>"Tag based" to "None". Then switching back to "Tag based". After those two changes, the query errors out when trying to access Query.

    Error:
    implode(): Argument #1 ($pieces) must be of type array, string given in implode() (line 319 of /code/web/core/modules/views/src/Plugin/views/query/Sql.php)

  • 🇧🇪Belgium DuneBL

    I got the same issue... could not find the steps to reproduce.
    As a quick dirty fix, I have changed line 320 of web/core/modules/views/src/Plugin/views/query/Sql.php
    into
    '#default_value' => isset($this->options['query_tags']) ? implode(', ', $this->options['query_tags']) : NULL,

Production build 0.71.5 2024