So, instead of simply having the option to turn on or off a comment field with each workflow status update, I think it would be ideal to be able to setup fields for each workflow so that we could have values for check boxes, signatures, agent name, approval codes, confirmation #'s, etc. (as well as comment fields) stored with each workflow update. Of course this would also require the workflow history records to become entities, but that probably wouldn't be a bad thing.

Whether or not there's eventually some integration between Workflow, Workbench Moderation, State Machine, etc., I thought it would be good to have this issue here in the Workflow module issue queue.

Status for D7-version (updated up to #35):
- Patch #13 --> #29 --> #30 --> #35
- Remarks in #27, #28

Status for D8-version (updated up to #35):
- #18: now supports Fieldable Workflow Transitions.
- #18: limitation: Not on the widget, only on the form (Block and the History tab)
- #18: limitation: Fields are added, but when editing a Transition, the added field cannot be changed.
- #18: todo: baseField definitions should be used, so you do not need to define them in the element.
- #18: todo: the WorkflowTransitionElement should be used.
- #26: adds the fieldability to the Workflow Widget and Workflow Form.
- #26: It still doesn't work for scheduled transitions.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NancyDru’s picture

Status: Active » Postponed (maintainer needs more info)

This sounds like it would be a prerequisite to any chance of moving into core, so I like the idea. Have you done any work on this?

NancyDru’s picture

johnv’s picture

Status: Postponed (maintainer needs more info) » Active

Setting this as active again, since the next task on my list is to make workflow_node_history compliant with Field API.
This includes implementing an accompanying class WorkflowExecutedTransition / WorkflowHistoricTransition / WorkflowTransitionHistory (inspirational comments requested!) .

It is above my competencies to make a fieldable entity out of it, but you can build upon this.

@videographics, I invite you to test the new Workflow Field submodule!

johnv’s picture

@videographics,
adding a new field to a transition would automatically add a new field to the Workflow form? If so, how?

johnv’s picture

In the meantime 3 OO-classes have been introduces, localizing Workflow, State and Transition. Now, Entity metadata wrappers can be contructed. Patches are welcome!

johnv’s picture

"Changed Transitions into Entity. Views support enabled." is committed here.

The WorkflowScheduledTransition is crippled, since is does not have an ID.
You can now make Views of the entities. Relationships are still to do.

Next stop: adding view modes, so each of the following can have its own settings:
- node view
- tab page
- vbo page

johnv’s picture

Title: Make workflow history records fieldable entities » Make Transitions fieldable entities
Issue summary: View changes
Parent issue: » #2229347: Altering the workflow form (adding #states)

Adding it to the new META issue.

This would include all 3 types of Transitions (?)
- ConfigTransition
- ScheduledTransition
- EntityTransition

Should they be bundle of the sma 'abstract' Transition entity? ATM the ScheduledTransition inherits from EntityTransition.

johnv’s picture

  • johnv committed b44fc85 on 7.x-2.x
    Issue #1559680: Make Transitions fieldable entities -1-
    
johnv’s picture

Version: 7.x-1.x-dev » 7.x-2.5
Assigned: Unassigned » johnv
Status: Active » Needs work

This first commit adds fieldability to WorkflowTransition via the Workflow Admin UI pages.
It still doesn't save fields, and needs:
- adding function defaultUri() , e.g., /node/15/workflow/%workflow_transition (for every entity_type)
- uncommenting function call to field_attach_form('WorkflowTransition', $transition, $element['workflow'], $form_state);
- moving the 'edit comment' Views link into this form.
- testing the new code for non-entity pages: // - the VBO action form; // - the Advance Action form on admin/config/system/actions;
- will this work for scheduled transitions?
- adding a WorkflowTransitionUIController, if this reduces code.

  • johnv committed eafe6c2 on 7.x-2.x
    Issue #1559680: Make Transitions fieldable entities - add extra fields...
johnv’s picture

With the adjacent patch, the WorkflowTransition objects are now fieldable!
Also, the Comment, TargetState and SchedulingInfo are now exposed as extra-fields, so you can move them around.

However, in the submit-function, a new Transtion is created and saved, without taking into consideration the fieldability. So every field has value 0. :-(

johnv’s picture

Attached file is an attempt to save the attached fields..

johnv’s picture

Todo: The extra_fields and the attached fields are not shown on the form, when it is exposed in a Advance Action or VBO action.

johnv’s picture

In D8, the following line must be activated:
[EDIT] which is done in #17.

--- a/src/Form/WorkflowTransitionForm.php
+++ b/src/Form/WorkflowTransitionForm.php
@@ -84,7 +84,8 @@ class WorkflowTransitionForm extends ContentEntityForm {
    * {@inheritdoc}
    */
   public function form(array $form, FormStateInterface $form_state) {
-    // $form = parent::form($form, $form_state);
+    // Call parent to get (extra) fields.
+    $form = parent::form($form, $form_state);

  • johnv committed dabfdb5 on 8.x-1.x
    Issue #1559680 by johnv: Prepare Transitions as fieldable entities
    

  • johnv committed aba006b on 8.x-1.x
    Issue #1559680 by johnv: Make D8-Transitions fieldable entities
    
johnv’s picture

The D8-version now supports Fieldable Workflow Transitions.
- limitation: Not on the widget, only on the form (Block and the History tab)
- limitation: Fields are added, but when editing a Transition, the added field cannot be changed.
- todo: baseField definitions should be used, so you do not need to define them in the element.
- todo: the WorkflowTransitionElement should be used.

  • johnv committed b25164d on 8.x-1.x
    Issue #1559680 by johnv: Make Transitions fieldable entities
    

  • johnv committed 9ceb764 on 8.x-1.x
    Issue #1559680 by johnv: Make Transitions fieldable entities
    
johnv’s picture

  • johnv committed 99fb65e on 8.x-1.x
    Issue #1559680 by johnv: Align element names to entity names (field_name...
johnv’s picture

Assigned: johnv » Unassigned

  • johnv committed 8c5e33f on 8.x-1.x
    Issue #1559680 by johnv: Make Transitions fieldable entities
    

  • johnv committed ba22942 on 8.x-1.x
    Issue #1559680 by johnv: Make Transitions fieldable entities
    
johnv’s picture

Version: 7.x-2.5 » 8.x-1.x-dev

Above commit adds the fieldability to the Workflow Widget and Workflow Form.

It still doesn't work for scheduled transitions.

bohemier’s picture

I tried patch in #13 and it does save the fields. That's a good start, thanks johnv.

ericniaina’s picture

I'm Using the patch and it seems to work but not on all field type.
I've tried on entity reference field and then I got Incorrect integer value because it's using raw value from $form_state['input']

Temporary change $form_state['input'] to $form_state['values']; on line 563 on the version 7.x-2.8 seems to fix my issue.

nicola85’s picture

nicola85’s picture

johnv’s picture

3ssom’s picture

Hello,

This patch is working fine when adding values to cutom fields but it has some issues:

  1. It's doesn't get saved unless a comment has a value.
  2. the saved (entity_id) value is wrong and it adds counter number to the real entity_id
  3. the table has no uid for the value entered .. I think its important to have that

Thanx

johnv’s picture

Issue tags: +fieldable
mithenks’s picture

For what I understand, the patch is related to 7.x version.

Why is the issue referring to 8.x-1.x-dev?

johnv’s picture

Issue summary: View changes
FileSize
1.02 KB

Attached patch is exactly the same as #30, only states the Version D7 in the file name.

@mithenks: generally, feature requests go from one version to the next. See #10 and #26. New features are then backported to a previous version.

johnv’s picture

Version: 8.x-1.x-dev » 7.x-2.x-dev

Setting this back to D7 for thos who are interested. D8 is now working. If anything is not working for D8, please open a new issue.

scoff’s picture

D7 version with #35 works, kind of

Simple text field — I can add it, it gets stored when I create a new transition and I can *see* it with "edit comment" link (workflow_transition//edit). I can't change it though it just stays the same.

date field (or unix timestamp) produces this when I add a new transition

PDOException: SQLSTATE[01000]: Warning: 1265 Data truncated for column 'field_date_value' at row 1: INSERT INTO {field_data_field_date} (entity_type, entity_id, revision_id, bundle, delta, language, field_date_value) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6); Array ( [:db_insert_placeholder_0] => WorkflowTransition [:db_insert_placeholder_1] => 11 [:db_insert_placeholder_2] => 11 [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => und [:db_insert_placeholder_6] => 2017-11-27 20:15 ) в функции field_sql_storage_field_storage_write()

nothing on change if the date was empty it just stays empty

totolearn’s picture

Any update on this issue? I applied the #35 patch. But there is still errors coming.

Here is what I got from different tries.

I can confirm that the workflow attached fields can be savd for text and link fields. But for list (text) and date field with time both are not saved in updating or adding new transition.

For the date field, when using date and time by popup calendar, the placeholder divided by two, ie. placeholder_6_0 (for date) and placeholder_6_1 (for time) and create SQL field mis-matching value error (field treat date/time as one field, but value placeholder passing two values).

In the testing, I wondered that the patch inside the foreach need to detect the proper field value to write. For list (text) field, it should write the field_name_value and for the date/time field, it should combine date time as one string to pass to SQL.

+ foreach($field_list as $transition_field_name => $bundles) {
+ if (isset($bundles['bundles'][$transition_type])) {
+ $transition->{$transition_field_name} = $items[0]['workflow'][$transition_field_name];
+ }

But, I am not good enough to find out the coding syntax for this.

Anyone?

singampalli’s picture

HI i am working on Drupal 7 , I have applied this patch. Its working well for textfields which are added in workflow. But I have added one noderefernce field. Its data is not getting saved into db.. Please help

strelkovandreyvalerievich’s picture

#39 +1 I need entity reference, but website going down