0

I've created a custom workflow using the workflow module with the transitions listed below and I've noticed that when going to the view page of a node the workflow 'bar' that lets you transition a node between states only appears when it's set for review.

From what I can gather this is because only when it's in the review state is it considered moderated content which is also why it appears on the "Moderated Content" view. What I'd like is to have that appear no matter the moderation state it is in. How could I accomplish this?

States

  • Draft
  • Review
  • Published

Transitions

  • Draft || Review || Published > Draft
  • Review > Published
  • Draft > Review

1 Answer 1

0

I worked out what the issue is, you can only see that bar when you're looking at the Latest Version of a node (using the "Latest Version" tab) not when viewing the latest published version of the node (using the "View" tab).

So this is now resolved by checking if they have access to the "Latest Version" tab of a node (basically checking that exists) and sending them to that if it does, otherwise sending them to the "View" tab. The code below does it and is called from hook_node_insert & hook_node_update in my custom module .module file.

function send_user_to_view_page_after_save(NodeInterface $node) {
  $nid = (string) $node->id();

  if (!is_null($nid)) {
    $alias = Drupal::service('path.alias_manager')->getAliasByPath("/node/{$nid}");
    $url_service = new Url("entity.node.latest_version", ["node" => $nid], []);

    if ($url_service->access() === TRUE) {
      $response = new RedirectResponse("/node/{$nid}/latest");
      $response->send();
    }

    $response = new RedirectResponse($alias);
    $response->send();
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.