Even though this question is related to the Workflow module, the solution you're looking for should come from the Feeds and/or Rules module, as further explained in my answer below.
1st attempt: Feeds Rules module
The Feeds Rules module might be what you are looking for. Excerpt from its project page:
... provides some Rules integration for the Feeds module.
It provides:
- Feeds processor: a processor for Feeds to create content via Rules. (Currently only simple data types like text and integer are supported).
- Rules Event: Feeds After Import
- Rules Data: Feeds Source (properties: ID, imported)
Recommendation: this might work, however there is only a dev version available for this module ... my advice = no go.
2nd attempt: Native Feeds module
The Feeds issue about Rules integration & enable modules to customize imports adds a hook hook_feeds_before_import()
. Here are some quotes from that issue (bold markup added here):
... such that a rules integration could use it to customize the imported entities before saving + to skip saving.
Based on the hook we could add an event for it + an action for skipping the import. The entity could be manipulated with the usual rules actions else too.
Of course, in the question here the goal is to not skip saving. But instead "customize the imported entities before saving" and/or "manipulate the entity with the usual rules actions". More specifically: set the value of "state" to "Saved".
Recommendation: much better already, but it is not exactly right yet (and requires using a hook, i.e. writing some custom module) ... There has to be a Rules based solution ...
3rd (and Final) attempt: A rule that should do the job
Inspired (challenged) by the "I tried adding a rule upon feeds presave, but it never gets to the save since it is a draft" part of this question, I created a rule. Here is the export that rule, which I believe should be a perfect answer to the question (also because it doesn't require custom PHP code ...):
{ "rules_update_entity_after_import_via_feeds" : {
"LABEL" : "Update field imported via feeds",
"PLUGIN" : "reaction rule",
"OWNER" : "rules",
"REQUIRES" : [ "rules", "workflow_rules", "feeds" ],
"ON" : { "feeds_import_node" : [] },
"IF" : [
{ "entity_has_field" : { "entity" : [ "node" ], "field" : "field_workflow_status" } }
],
"DO" : [
{ "workflowfield_field_set_state" : {
"node" : [ "node" ],
"field" : [ "node:field-workflow-status" ],
"workflow_state" : { "value" : { "3" : "3" } }
}
}
]
}
}
To get this to work, I enabled the Workflow API
module (of course ...), and also it's submodules Workflow UI
, Workflow Field
and Workflow Rules
.
My Workflow itself has only status "Draft" and "Done" (identical to the question here).
The rule above only applies to "node", and only for those "nodes" that have a field defined with machine name "field_workflow_status
" (if you want to use another field name, change the rule accordingly and it should work also ...). In my case I used "Article" as the content type, though the "entity_has_field
" prevented that I had to hardcode the content type in my rule ...
Obviously, and to be complete, Feeds and Rules are also part of the solution.