The Problem
I once wanted to make it possible for one user to alter the content of a specific Drupal block, but not give this user complete access to all blocks in order to accomplish it. Also, I wanted to limit the user’s ability to change the fonts and the general look of the content in the block or to accidentally delete the block.
There is a module for Drupal (Nodeaccess) that makes it possible to give individuals access to specific nodes. But, there is nothing like this for blocks.
The Solution
I wondered if it would be possible to embed a node in a block. It turns out that it is possible. Just paste the following code into your block, changing YOUR_NODE_ID to the id of the node the user will have access to for editing. (NOTE: you have to have the PHP text format enabled for the administrator.)
1 2 3 4 5 |
<?php $node = node_load(YOUR_NODE_ID); $body_content = $node->body[$node->language][0]['value']; print $body_content; ?> |
Next, install and enable Nodeaccess.
For the problem of what to do about preserving styling, it turns out that any styling in the node is not honored by the block. So, you have to style the block, which is great news, because, the user does not have access to the block.
The final steps to finish off are:
- Make sure you have set up a role for the user.
- In Drupal’s permissions, give the user’s role access only to their own node content for editing, but do not allow deleting.
- Give the user access to the “Content overview” page so that the user can see a link to the node to edit it. (There might be cases where you won’t want a user to see all content on a site. Something else will have to be worked out then.).
- Change the owner of the node which is embedded in the block to that of the user who will edit it.