Skip to content
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

Merged
merged 23 commits into from
May 27, 2019

Conversation

nagyad
Copy link
Member

@nagyad nagyad commented May 6, 2019

  • 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.

@nagyad nagyad force-pushed the OPENEUROPA-1770 branch 3 times, most recently from 0ba592e to a0b01fe Compare May 10, 2019 08:42
upchuk
upchuk previously approved these changes May 10, 2019
/**
* Provides an interface for shortcut handler service.
*/
interface ShortcutTransitionHandlerInterface {
Copy link
Contributor

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 {
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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);
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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.
*/
Copy link
Contributor

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
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The target state

@nagyad nagyad requested a review from upchuk May 23, 2019 13:23
}

/** @var \Drupal\node\NodeInterface $node */
$node = \Drupal::routeMatch()->getParameter('node');
Copy link
Member

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?

@nagyad nagyad requested review from hernani and removed request for upchuk May 24, 2019 07:19
@nagyad nagyad requested a review from upchuk May 26, 2019 14:58
@nagyad nagyad merged commit dbbb762 into master May 27, 2019
@nagyad nagyad deleted the OPENEUROPA-1770 branch May 27, 2019 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants