I just wanted to share a quick solution to a probably common problem;
Problem description:
I wanted to be able to provide full EDIT access to a particular node, based upon the user having "ownership" of that node, whilst not authoring it, yet restricting them from editing other nodes of the same type, but which were not assigned to them.
Problem example:
Each Organisation has one or more Organisation Contacts. These contacts are Users in the system. The Organisation is a content type in the system. Each user has an optional field that correlates to the Organisation that they are an Org Contact for. The user also has a role set ("Organisation") when they become an Org Contact.
Solution:
In a custom module, use a call to the hook_node_access like so:
function mymodule_node_access($node,$op,$account){ //implement hook_node_access // https://docs.backdropcms.org/api/backdrop/core%21modules%21node%21node.api.php/function/hook_node_access/1 // this does a check against the Organisation field of a Org Contact, and gives them access to UPDATE the org foreach ($account->roles as $k=>$role) { //skip over the User account Roles if($role=="organisation"){ $u=user_load($account->uid); //load the full user now, so we have access to their custom fields if(isset($u->field_organisation['und'][0])){ // field_organisation is the field set to show which Org they are a Contact of $oid=$u->field_organisation['und'][0]['target_id']; // the orgID if($oid==$node->nid && $op=="update"){ // do the work of allowing them access to the UPDATE mode return NODE_ACCESS_ALLOW; } } } } }
Recent comments
With the threat of Drupal 7 EOL looming, and a very out of date Drupal 6 site that no longer worked with newer php versions, I made the decision to move both sites to Backdrop in March 2024. ...
Happy Birthday Backdrop CMS - Share your projects!
Happy Birthday Backdrop CMS! Thanks to the team for everything you do and I'm glad to be part of the people who have been using this system since version 1.1 :)) I have built more than 100...
Happy Birthday Backdrop CMS - Share your projects!
I have a handful of projects I have migrated from Drupal 7 sites, and a number of new sites I have built. Here's my list: Twin Cities Amnesty https://twincitiesamnesty.org...
Happy Birthday Backdrop CMS - Share your projects!
I'll start! My company Triplo, has been building Backdrop CMS sites and upgrading Drupal 7 sites to Backdrop for about 6 years now? Here are a few of the Backdrop sites we have...
Happy Birthday Backdrop CMS - Share your projects!
Sure, I could set up an site on my server for testing this.
Drupal 7 Migration, content_access issue