I am using hook_node_access (https://api.drupal.org/api/drupal/modules%21node%21node.api.php/function/hook_node_access/7.x) to provide some users the ability to edit certain nodes they couldn't otherwise edit based on certain criteria. The solution works but there are two problems
- The users are able to edit certain nodes but they should also have a permission to attach the node to a specified place in the menu structure
- I am using the paragraphs module (https://www.drupal.org/project/paragraphs) so although the users are able to edit the node itself, they are unable to edit the paragraphs the node is holding.
I am thinking about the following solution for the above mentioned problems:
- In hook_init check that the current user has a certain uid
- Check whether the current user is on a node edit page
- Check the node has a specified node id
- If the above criteria is met, on the fly assign a special role to the user
- The special role has permission to edit menu and paragraphs
- During the first page load when the criteria above is not anymore met, remove the special role
So my question boils down to whether it is acceptable to assign and remove roles on the fly enabling the same user to have different set of roles based on the node the user is editing. Or would this type of approach be problematic?
I know there are a variety of access related modules but none of those has suited the use case I am dealing with so Im looking a code based solution rather than introducing new node access modules.