Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The Workflow Transition Form that is displayed on the node is very difficult to theme because the "id" attribute is too specific and there is no "class" attribute to select with.
This is easily fixed:
function workflow_transition_form($form, &$form_state, $field, $instance, $entity_type, $entity) {
$form['#attributes'] = array('class' => array('workflow-transition-form'));
.
.
.
Comment | File | Size | Author |
---|---|---|---|
#3 | 2510958-3.patch | 643 bytes | NancyDru |
Comments
Comment #1
NancyDruFor anyone seeing this before it is fixed, this also works:
Comment #2
NancyDruPatch attached.
Comment #3
NancyDruActually, this one seems more consistent.
Comment #4
doxigo CreditAttribution: doxigo commentedNancy I applied the #3 patch but didnt change anything, can you check the patch out please ?
Comment #5
NancyDruI must have had trouble too, because I am now doing this:
Comment #6
doxigo CreditAttribution: doxigo commentedThanks Nancy, How about adding class to each state buttons?
Comment #7
NancyDruYes, that would be nice. I'm still having trouble figuring out how the buttons get there because I try to get rid of the "same state" button (see #2363521: Remove unnecessary action button in Node View page.), but it comes back any way.
Comment #8
doxigo CreditAttribution: doxigo commentedWell I end up writing a custom module for adding the classes to my button which is more like a hack and is not the best way to do this since I statically added my buttons ID to it but here's the code in case you need it, also I hide the current state with the following:
Comment #9
johnvIs this issue relevant?
#2599610: Schedule state change radio buttons generate conflicts and can't be changed
Comment #10
doxigo CreditAttribution: doxigo commentedIt can be related but I don't really think it is, this issue is mainly about lack of css class related to each state, I suggest adding state machine name as a class to the button/radio for easier theming of workflow.
Comment #11
johnvCan either of you provide a proposal for a definite fix? I see too many different options to decide myself.
I see:
- add class for form;
- add class for button; (there are other issues regarding this.)
Thanks.
Comment #12
doxigo CreditAttribution: doxigo commentedCurrently if in a page you have a list of nodes and each with a workflow field attached to it, you will end up with a structure like this:
First Node:
form#workflow-transition-form-node-[nodeID]
button#edit-workflow-1
button#edit-workflow-2
button#edit-workflow-3
Second Node:
form#workflow-transition-form-node-[nodeID]
button#edit-workflow-1--2
button#edit-workflow-2--2
button#edit-workflow-3--2
and so on.
I suggest having a simple class for form tag, such as "workflow-field-[nodeID]" and per buttons classes like "workflow-btn-[stateName]" so it's easier to theme, also the same approach for radio buttons.
Comment #13
johnv(Using d.o. as my notepad)
This is a radio button in html with values N/A, LABEL_1, LABEL_2:
And this is a select list.
And these are the action buttons:
Comment #17
johnvAbove commits add classes to the form (on workflow tab and on formatter-as-widget ) and on the workflow-container within the form:
D7 and D8 version are slightly different, as they try to emulate the nodeForm pattern.
Comment #18
johnv@doxigo, as I am no themer:
why would you need the class on the button, if even the 'preview' and 'delete' buttons (on node edit page) have a class?
Each button does have an ID:
Can you please create a new issue for the buttons, and add your solution for the removed button to : #2363521: Remove unnecessary action button in Node View page.
(since I'm getting confused)
Comment #19
johnvPlease use #2545660: Make action buttons more unique for the identifiable/themable action buttons.
Comment #20
johnvComment #21
doxigo CreditAttribution: doxigo commented@johnv, simply having just ID per action buttons is not enough as I mentioned in previous comment, imagine having a list of nodes and each node has a workflow action button, you cannot globally select each states just by using ID.
Here's an example:
States: Unpublish - Publish - Promote - Delete - Upgrade
Now imagine if you want to make "Delete" action buttons red and add an icon next to it.
Unless there's a class for that state, you have to manually select each ID for that button to do so, and if you have more than one workflow field in a page (views page maybe) the ID of the "Delete" buttons will look like this:
First Node's Workflow field: #edit-workflow-1
Second Node's Workflow field: #edit-workflow-1--2
Third Node's Workflow field: #edit-workflow-1--3
and so on.
Based on this pattern, you simply can't select "Delete" buttons using CSS selectors, that's why I suggest adding classes for each action button and radio buttons.
I will create a separate issue for this.
Comment #22
johnv@doxigo,
please see #2545660: Make action buttons more unique where I added a class, not an id:
$workflow_submit_button['#attributes']['class'][] = drupal_html_class('workflow_button_' . $option_name)
See also #2366867: Allow CSS/HTML in state / transition labels
Comment #23
kopeboy CreditAttribution: kopeboy commentedYou should let the classes be separate.
Like
class="workflow-button target-state-machine-name"
in case of a form, and
class="workflow-state current-state-machine-name"
in case of a field (shown on Node Display and in a View);
so we can target all of them and any specific one of them with the CSS.
Comment #24
johnvI am a nooby in classes, css, etc. A patch is highly appreciated.