Crash if the workflow have no state when field added

Created on 31 March 2022, about 2 years ago
Updated 17 April 2024, 2 months ago

You can add a field with a workflow that have no state yet, but it will crash when you arrive at the field config page. Certainly because you cannot add a "default" value. But a blank page crash could certainly be avoided.

🐛 Bug report
Status

RTBC

Version

2.1

Component

Code

Created by

🇨🇭Switzerland gagarine

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • 🇩🇪Germany tstoeckler Essen, Germany

    Pretty sure this broke even worse with Drupal 10.2.x because with https://www.drupal.org/node/3386675 the default value form can now be built (and, thus, WorkflowsFieldItem::getSettableOptions() can be called) without the field storage even being saved.

    Thus, whether or not the workflow has a state is now not the only failure condition, also there may be no workflow selected and also the entity may not have the respective field yet.

    Will create a merge request to fix that. Hope it's OK to use that issue for this slightly expanded scope.

    Noticed two things, that are related, that may warrant separate issues:

    1. The if ($value) check will fail for a state with the ID '0' which is not ideal
    2. I had initially thought that if the value cannot be determined from the entity, that we should fall back to the initial state that the workflow has configured. That would need a check, as well, however, because the initial state may not be configured initially (no pun inteded) when creating a workflow. Since that's currently not done, though, either if the value is explcitly not set for an entity, that would be a separate issue, if we want to change that.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update 4 months ago
    Composer require failure
  • Pipeline finished with Success
    4 months ago
    Total: 151s
    #106902
  • Status changed to Needs review 4 months ago
  • 🇩🇪Germany tstoeckler Essen, Germany
  • 🇮🇹Italy kopeboy Mainland

    I can confirm creating new workflows fields is broken on latest Drupal (10.3.x-dev 7622e3b) too.

    The website encountered an unexpected error. Try again later.
    
    InvalidArgumentException: Field field_test is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 616 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
    Drupal\Core\Entity\ContentEntityBase->get('field_test') (Line: 125)
    Drupal\workflows_field\Plugin\Field\FieldType\WorkflowsFieldItem->getSettableOptions(Object) (Line: 143)
    Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions(Object) (Line: 35)
    Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget->formElement(Object, 0, Array, Array, Object) (Line: 459)
    Drupal\Core\Field\WidgetBase->formSingleElement(Object, 0, Array, Array, Object) (Line: 101)
    Drupal\Core\Field\WidgetBase->form(Object, Array, Object) (Line: 287)
    Drupal\Core\Field\FieldItemList->defaultValuesForm(Array, Object) (Line: 230)
    Drupal\field_ui\Form\FieldConfigEditForm->form(Array, Object) (Line: 107)
    Drupal\Core\Entity\EntityForm->buildForm(Array, Object)
    call_user_func_array(Array, Array) (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm('field_config_edit_form', Object) (Line: 284)
    Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 48)
    Drupal\Core\Entity\EntityFormBuilder->getForm(Object, 'default', Array) (Line: 63)
    Drupal\field_ui\Controller\FieldConfigAddController->fieldConfigAddConfigureForm('node', 'field_test')
    call_user_func_array(Array, Array) (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 637)
    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: 53)
    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: 736)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
  • Status changed to RTBC 2 months ago
  • 🇮🇹Italy kopeboy Mainland

    So, the module was unusable even on 2.1: this is the error when trying to add a workflow field on a fresh install of Drupal 10.2.5:

    The website encountered an unexpected error. Try again later.
    
    InvalidArgumentException: Field field_status is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 616 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).
    Drupal\Core\Entity\ContentEntityBase->get() (Line: 125)
    Drupal\workflows_field\Plugin\Field\FieldType\WorkflowsFieldItem->getSettableOptions() (Line: 143)
    Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsWidgetBase->getOptions() (Line: 34)
    Drupal\Core\Field\Plugin\Field\FieldWidget\OptionsSelectWidget->formElement() (Line: 459)
    Drupal\Core\Field\WidgetBase->formSingleElement() (Line: 101)
    Drupal\Core\Field\WidgetBase->form() (Line: 287)
    Drupal\Core\Field\FieldItemList->defaultValuesForm() (Line: 230)
    Drupal\field_ui\Form\FieldConfigEditForm->form() (Line: 107)
    Drupal\Core\Entity\EntityForm->buildForm()
    call_user_func_array() (Line: 536)
    Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 283)
    Drupal\Core\Form\FormBuilder->buildForm() (Line: 48)
    Drupal\Core\Entity\EntityFormBuilder->getForm() (Line: 62)
    Drupal\field_ui\Controller\FieldConfigAddController->fieldConfigAddConfigureForm()
    call_user_func_array() (Line: 123)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 627)
    Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
    Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
    Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
    Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
    Drupal\big_pipe\StackMiddleware\ContentLength->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: 36)
    Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
    Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 704)
    Drupal\Core\DrupalKernel->handle() (Line: 19)

    Fortunately MR 12 applies to 2.1 as well, and it seems to work fine! Thank you @tstoeckler

Production build 0.69.0 2024