Hi,

when I hide the field in my node form, the state value is not saved in DB in the node__field_my_field table.

To reproduce :

  • Add a workflow
  • Add some state
  • Adjust transition and access
  • Add a field State to your content type Article
  • Go to /admin/structure/types/manage/article/form-display and choose hide to your field State
  • Add a new article

I don't find where it come from in the code, but I can help, if you can explain me where I can find the code with the Widget field

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

vanessakovalsky created an issue. See original summary.

johnv’s picture

Title: State not save in field entity when field hidden in form » State is not saved in Field of Entity when using the 'Hidden' widget
Category: Bug report » Feature request
Priority: Normal » Minor

This is how the module works at the moment. The 'Hidden' widget (added by core) does not by default call the Workflow code. Perhaps this will be corrected some time in the future.

johnv’s picture

Status: Active » Postponed

The functions FieldItemBase::preSave() and postSave() are called, when the Hidden widget is choosen, but only if the field already exists on the entity.

The following Core issues exist:
#2159951: Allow - Hidden - as a default widget type
#2060705: Remove the 'hidden widget' plugin, it is actually never used
#2378947: Hiding a field using form modes should not remove it from the form object

johnv’s picture

Category: Feature request » Bug report
Status: Postponed » Active

I located an error in (the call to) WorkflowManager::executeTransitionsOfEntity, in below code.
We could change something there, or in the calling code. I just added the line with continue, but it causes that the entity is created without any field value.

      // Transition is created in widget or WorkflowTransitionForm.
      /* @var $transition WorkflowTransitionInterface */
      $transition = $entity->$field_name->__get('workflow_transition');
      if (!$transition) {
        // We come from creating/editing an entity via entity_form, with core widget or hidden Workflow widget.
        // @todo D8: CommentForm : or from a Edit form with hidden widget.
        if ($entity->original) {
          // Editing a Node with hidden Widget. State change not possible, so bail out.
          $entity->$field_name->value = $entity->original->$field_name->value;
          continue;
        }

        // Creating a Node with hidden Workflow Widget. Generate valid first transition.
        // @todo D8: Test Creating a non-Node Entity with hidden Workflow widget.
        $comment = '';

willeaton’s picture

FileSize
1.01 KB

Hi, what about this solution? I attach a patch which now does not throw an error when saving an a new custom entity entry which has the workflow field hidden (which is normal for me as we have the workflow tab). The entity is already loaded and the field is already known so I just took advantage of it. Maybe this might fail for a Node entity though...

willeaton’s picture

FileSize
1.01 KB

Added with correct file extension

johnv’s picture

Title: State is not saved in Field of Entity when using the 'Hidden' widget » State is not saved for Entity Field with 'Hidden' widget

  • johnv committed 1c40415 on 8.x-1.x authored by willeaton
    Issue #2724107 by willeaton: State is not saved for Entity Field with '...
johnv’s picture

Version: 8.x-1.x-dev » 8.x-1.4
Status: Active » Fixed

Thanks, committed as-is.
In the mean time, we are working on D9. It seems that the Hidden widget does not exist anymore.

Status: Fixed » Closed (fixed)

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