-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPENEUROPA-1770: Shortcuts on workflow block on node view page #23
Conversation
nagyad
commented
May 6, 2019
•
edited
Loading
edited
- Override StateTransitionValidation::getValidTransitions() method in order to provide extended options with permission check.
- Provide form_alter() for the moderation form in order to make sure that the next state is selected by default.
- Removed access for moderation state dropdown in node form if there is only a Draft state present.
- Add service to save revisions for all transitions programatically when shortcuts are used.
0ba592e
to
a0b01fe
Compare
modules/oe_editorial_corporate_workflow/oe_editorial_corporate_workflow.module
Outdated
Show resolved
Hide resolved
modules/oe_editorial_corporate_workflow/src/CorporateWorkflowStateTransitionValidation.php
Outdated
Show resolved
Hide resolved
modules/oe_editorial_corporate_workflow/src/CorporateWorkflowStateTransitionValidation.php
Outdated
Show resolved
Hide resolved
modules/oe_editorial_corporate_workflow/oe_editorial_corporate_workflow.module
Outdated
Show resolved
Hide resolved
…orkflow in forms.
modules/oe_editorial_corporate_workflow/config/install/user.role.oe_validator.yml
Show resolved
Hide resolved
modules/oe_editorial_corporate_workflow/oe_editorial_corporate_workflow.module
Outdated
Show resolved
Hide resolved
modules/oe_editorial_corporate_workflow/oe_editorial_corporate_workflow.module
Show resolved
Hide resolved
modules/oe_editorial_corporate_workflow/oe_editorial_corporate_workflow.module
Outdated
Show resolved
Hide resolved
/** | ||
* Provides an interface for shortcut handler service. | ||
*/ | ||
interface ShortcutTransitionHandlerInterface { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call it ShortcutRevisionHandlerInterface
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function handleShortcutTransitions(array $form, FormStateInterface $form_state): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we tying this to a form? The implementation you have simply needs an entity (whatever kind of content entity) and a state to make the revisions. So that's what should be the interface.
protected $currentUser; | ||
|
||
/** | ||
* Entity type manager to get entity storage. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The entity type manager.
protected $time; | ||
|
||
/** | ||
* Constructs a new StateTransitionValidation. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No it doesn't
* @param \Drupal\Core\Form\FormStateInterface $form_state | ||
* The form state. | ||
*/ | ||
public function handleShortcutTransitions(array $form, FormStateInterface $form_state); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's call it createShortcutRevisions
} | ||
|
||
/** | ||
* Function to save state transitions and revisions to the target state. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small comment is enough here:
Recursively saves the revisions between two states.
* The form state of the form we are submitting. | ||
*/ | ||
protected function saveTransitionRevisions($current_state, $target_state, WorkflowTypeInterface $workflow_plugin, RevisionableInterface $entity, FormStateInterface $form_state): void { | ||
// We need to stop before the last transition, since the following |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to stop before the last transition because the creation of that revision is handled by core.
|
||
/** | ||
* Provides an interface for shortcut handler service. | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provides an interface for shortcut revision handlers.
These are used in the form responsible for moderating content, provided by Drupal core.
$entity->save(); | ||
|
||
// We need to repeat this operation until we reach the target state. | ||
// Once we see that the target state is the next the following form submit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just this is enough:
We need to repeat this operation until we reach the target state.
* @param string $current_state | ||
* The current state of the entity. | ||
* @param string $target_state | ||
* The target state selected from the moderation form. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The target state
} | ||
|
||
/** @var \Drupal\node\NodeInterface $node */ | ||
$node = \Drupal::routeMatch()->getParameter('node'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get it from form_state just for consistency?