1. How I can set default state which will be selected when I'm creating content type with workflow states?
2. How can I change the weight of it?

Comments

flebas’s picture

Create an action "Change workflow state to new state" triggered on "after saving a new post".

jvandyk’s picture

1. When editing your workflow, only allow the author to go to the state you desire. Then the workflow form will be suppressed, but the state will be assigned to the node.

2. There is no UI for that at present, but you can change weights in the workflow_states table.

robertdouglass’s picture

Status: Active » Fixed

Good answers. Closing.

Status: Fixed » Closed (fixed)

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

mnp’s picture

hi all
i have same problem
i have created 3 states
draft
publish
rejected
for administrator and editor
when creating node default state is rejected (selected)
i want to default state as draft
tried to change weights but it doesnt worked.
for other roles default is draft.
please help me

kenorb’s picture

Maybe hook_form_alter ?

thtas’s picture

here is my solution to this using hook_form_alter


//Implementation of hook_form_alter
function MYMODULE_form_alter($form,$form_state,$form_id)
{
	//if its a new node being crated and of the required type
	if($form_id =='MYTYPE_node_form' && !is_numeric($form['nid']['#value']) )
	{		
		global $user;
		//checking role "content admin" and for THE admin user (uid 1)
		if( in_array("content admin", array_values($user->roles)) || $user->uid == 1)
		{
			$form['workflow']['']['#default_value'] = 3;//Approved
		}		
	}
}

jeffschuler’s picture

In Workflow version 7.x-2.0 (7.x-2.0-beta9+17-dev) I set:

<?php
  $form['field_status']['und'][0]['workflow']['workflow_sid']['#default_value']
?>

in hook_form_FORM_ID_alter().

johnv’s picture

Title: how to set default state selected » How to set default state selected, depending on author roles?
Version: 6.x-1.1 » 7.x-2.x-dev
Issue summary: View changes
Status: Closed (fixed) » Closed (works as designed)

In 7.x, you can set the weight in the Admin UI.
I've added a similar issue as a reference.

TBarina’s picture

I'm using workflow 7.x-2.2 and I see weights in Admin UI but they are not taken into account outside admin UI.
I mean, they are not taken into account:
- when seeing the list of possibile states that is shown when setting the workflow field in any entity;
- when a user with a particular role is adding any content the first state by SID and not by weight is the default value for the workflow field.

Does anybody knows how to fix that?
Many thanks in advance.

johnv’s picture

Did you check "show weights" in the admin page? By default all options get the same weight. In the widget they have a different sort order. This is a flaw. Rearranging the options in admin ui explicitly, should fix the problem.

TBarina’s picture

To Johnv (...sorry for my delay in answering): Yes I did! Here are my settings for states:
# | State | Weight | Active
1. Creation (grayed out) -20 yes
2. No promotion requested -19 yes
3. Promotion requested -18 yes
4. Promotion granted -17 yes
5. Promotion cancelled -16 yes

I noticed that all works well for root user since he can access any state.
But authenticated users only can access states n. 1 and 2 when creating new contents (according to permissions set in Transitions settings).
In this case the default value shown in the node creation form to authenticated users is "Promotion requested" (which was created first and moved to lower level by editing its weight).

Many thanks in advance.

(P.S.: I tried and enabled all states for authenticated users for node creation and the module behaves correcty in this case - i.e.: showing the first state, according to the assigned weights, as the default value)

johnv’s picture

Title: How to set default state selected, depending on author roles? » how to set default state selected

@TBarina, it was wrong of me to change the title, and with that the scope of the issue.
Please upgrade to lates version. (2.4 or 2.5-beta)
- The error with the with the weights has been solved.
- for states depending on author role, see the following issues:
#748814-14: Permitted transitions depending on extra roles of author.
#744272: Allow dynamic/flexible/freely definable transitions per state

In file workflow.api.php you'll find a new hook_workflow_permitted_state_transitions_alter(), in which you can filter the available transitions.

Pleasse reopen a new issue if you still have problems.