Bundles element doesn't update when changing the entity type

Created on 16 February 2024, 10 months ago
Updated 4 June 2024, 7 months ago

Problem/Motivation

When the "Entity type" is changed to product the "Bundle" options don't change to the available Commerce Product types. See attached screenshots.

Steps to reproduce

Drupal core is 10.2.3 & Commerce Core is 8.x-2.38

  • Install Metatag Import Export CSV 8.x-1.2
  • At /admin/config/search/metatag/download set "Entity type" to Product. The "Bundle" options don't change to the "Product types".
  • If you select any of the "Bundle" options and "Tags" and Export the page breaks.

Proposed resolution

not sure

Remaining tasks

none

User interface changes

none

API changes

none

Data model changes

none

πŸ› Bug report
Status

Fixed

Version

1.2

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States Jared Nolt

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

Comments & Activities

  • Issue created by @Jared Nolt
  • πŸ‡ΊπŸ‡ΈUnited States Jared Nolt
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Could you do some debugging to see what's causing the error?

    BTW, please don't add random tags to issues; tags have specific purposes. And it's better to copy-paste error text rather than take screenshots, as then the error text can be used to search the codebase.

  • πŸ‡ΊπŸ‡ΈUnited States Jared Nolt

    Thanks for replying! I know this wasn't the right thing to do but there was a discussion on the Drupal SEO Slack channel

    Summary from Slack:

    • There isn't anything in the browser console after I changed the "Entity type" selector to "Product".
    • When the selector is changed there is no AJAX callback to the server to get the list of bundles.
    • I installed Metatags Import Export csv on 2 other sites. The "Bundle" on the one site only show node types. The other new test site I built only has 5 products and "bundle" is empty.

    This is the error message that shows after I click to download the csv. "The website encountered an unexpected error. Try again later."

    This is the log messages:

    Type	php
    Date	Tuesday, February 27, 2024 - 06:37
    User	Drupal Jared Admin
    Location	https://www.horningmfg.com/batch?id=556&op=finished
    Referrer	https://www.horningmfg.com/batch?id=556&op=start
    Message	TypeError: array_unshift(): Argument #1 ($array) must be of type array, null given in array_unshift() (line 80 of /home/horningmfg/public_html/horning/web/modules/contrib/metatag_import_export_csv/src/MetatagExport.php).
    Severity	Error
    Operations	
    
    Backtrace
    #0 /home/horningmfg/public_html/horning/web/modules/contrib/metatag_import_export_csv/src/MetatagExport.php(80): array_unshift(NULL, 'entity_id', 'entity_title', 'entity_bundle', 'entity_type', 'field_machine_n...', 'alias')
    #1 /home/horningmfg/public_html/horning/web/core/includes/batch.inc(457): Drupal\metatag_import_export_csv\MetatagExport::downloadCsv(true, Array, Array, Object(Drupal\Core\StringTranslation\TranslatableMarkup))
    #2 /home/horningmfg/public_html/horning/web/core/includes/batch.inc(99): _batch_finished()
    #3 /home/horningmfg/public_html/horning/web/core/modules/system/src/Controller/BatchController.php(52): _batch_page(Object(Symfony\Component\HttpFoundation\Request))
    #4 [internal function]: Drupal\system\Controller\BatchController->batchPage(Object(Symfony\Component\HttpFoundation\Request))
    #5 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array(Array, Array)
    #6 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #7 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(124): Drupal\Core\Render\Renderer->executeInRenderContext(Object(Drupal\Core\Render\RenderContext), Object(Closure))
    #8 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array)
    #9 /home/horningmfg/public_html/horning/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #10 /home/horningmfg/public_html/horning/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
    #11 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #12 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #13 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #14 /home/horningmfg/public_html/horning/web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #15 /home/horningmfg/public_html/horning/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #16 /home/horningmfg/public_html/horning/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #17 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #18 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #19 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #20 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #21 /home/horningmfg/public_html/horning/web/core/lib/Drupal/Core/DrupalKernel.php(704): Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
    #22 /home/horningmfg/public_html/horning/web/index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
    #23 {main}
    
  • πŸ‡¬πŸ‡§United Kingdom joachim

    Could you put a debug breakpoint in getBundlesList() and see what happens when Product is selected?

  • πŸ‡ΊπŸ‡ΈUnited States Jared Nolt

    I'm sorry, debugging like that is new for me. I have been trying awhile but I'm not sure what I should look for.

    This message showed on the Metatage export page of my test site:

    Warning: Undefined variable $bundle_options in Drupal\metatag_import_export_csv\Form\MetaTagDownloadForm->buildForm() (line 106 of modules/contrib/metatag_import_export_csv/src/Form/MetaTagDownloadForm.php).
    Drupal\metatag_import_export_csv\Form\MetaTagDownloadForm->buildForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm('metatag_import_export_download', Object) (Line: 283)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
    Drupal\Core\Controller\FormController->getContentResult(Object, Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 592)
    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: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    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: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • πŸ‡ΊπŸ‡ΈUnited States Jared Nolt

    I added 2 screenshots. One of where I added the breakpoint and the other of what happens when I click the product tab. Please let me know if I should provide this info in some other format.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    I meant PHP breakpoints.

    And just the lines where it goes wrong will do.

    When you change the entity type, there's an AJAX callback which should be returning bundles.

  • πŸ‡ΊπŸ‡ΈUnited States Jared Nolt

    Does this help? This is what shows when I click export now:

    The website encountered an unexpected error. Try again later.
    
    TypeError: array_unshift(): Argument #1 ($array) must be of type array, null given in array_unshift() (line 80 of modules/contrib/metatag_import_export_csv/src/MetatagExport.php).
    Drupal\metatag_import_export_csv\MetatagExport::downloadCsv(1, Array, Array, Object) (Line: 457)
    _batch_finished() (Line: 99)
    _batch_page(Object) (Line: 52)
    Drupal\system\Controller\BatchController->batchPage(Object)
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    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: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->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: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • πŸ‡¬πŸ‡§United Kingdom joachim

    No, that's a false error because the form gets submitted with broken values.

    I need the error that causes an empty list of bundles for products.

  • πŸ‡ΊπŸ‡ΈUnited States Jared Nolt

    I'm still working at getting the error but I did notice that when I changed the default_value on the MetaTagDownloadForm.php from "node" to "commerce_product" it shows the commerce "Bundle". But it didn't export all of the Metatag fields.

     /**
       * {@inheritdoc}
       */
      public function buildForm(array $form, FormStateInterface $form_state) {
        $form['entity_type'] = [
          '#title' => $this->t('Entity type'),
          '#type' => 'select',
          '#required' => TRUE,
          '#options' => $this->getEntityTypes(),
          '#default_value' => isset($this->getEntityTypes()['commerce_product']) ? 'commerce_product' : '',
          '#ajax' => [
            'callback' => '::getBundlesList',
            'event' => 'change',
          ],
        ];
    
  • πŸ‡ΊπŸ‡ΈUnited States Jared Nolt

    On comment #10 - The ajax progress wheel spins when the Entity type is switched from content to products but nothing changes in the Bundle field.

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Yes, because this callback is failing somehow:

    > 'callback' => '::getBundlesList',

    That's the bit that needs debugging.

  • πŸ‡ΊπŸ‡ΈUnited States Jared Nolt

    joachim, I don't think I'm getting anything you can use. Could you give me tips on how to get the errors please? Or where is the best place that I could go to learn about debugging?

  • πŸ‡¬πŸ‡§United Kingdom joachim

    I can reproduce this -- the AJAX is broken.

  • Status changed to Needs work 10 months ago
  • πŸ‡¬πŸ‡§United Kingdom joachim

    I've got it working *better*, but I can only change the entity type ONCE. I can't change it back! Leaving this for now, I hate debugging ajax forms :/

  • πŸ‡¬πŸ‡§United Kingdom joachim

    Fixed.

  • Status changed to Fixed 7 months ago
    • joachim β†’ committed 427baee6 on 8.x-1.x
      Issue #3421982 by joachim: Fixed export form bundles element doesn't...
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024