0

I have a form/node that I want all users to complete after logging in for the first time. When the user completes the form (saves the node), they are automatically awarded the completed role.

If a user does not have the completed role, I want to keep redirecting them to the form no matter what links they click.

In Drupal 7, I could do this with Rules (event: content is viewed, condition: user does not have role, action: redirect). However, in Drupal 8, Rules is still in alpha and I can't get it to work without crashing my site. So what hook should I use to do this programmatically? (what's the hook for "user views a node"?)

1

You can use hook_entity_view, this is called when a user views any entity type, also hook_ENTITY_TYPE_view can be used if you want to redirect on specific entity type view like node.

0

Here's a simple way to do this.

  1. Find all the blocks that print links (User account menu, Footer, Main navigation, etc.)
  2. Configure the display settings for each block to "hide" the block on /node/*/edit.

By hiding all the links, the user will have to click "save" before being able to proceed to a different page.

However, this solution removes all the links from all node edit pages, which is a big tradeoff compared to what the question asks for (a way to redirect the user if they click a link-- this solution is just hiding all the links that can be clicked).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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