How to implement node access control with a simple field used during node creation? I have multiple roles on the site. I have used Role reference field in Nodes to choose which Role should see Nodes. Then I have set Views to show content based on roles and Role reference field in Node.

Now I'm facing issue with Search. Search shows all content and users in different roles can see all the content.

I was looking for solution to set access per node, but Content access and Nodeaccess modules only allow access to be set after node is created. And in these case user need to set access to two fields: Role reference field AND Content access/Nodeaccess tab.
Not good. I do not want to create own content type for each role.

Is there a way to use Role reference field to set access control to node?

I did install both Content access and Nodeaccess modules and tried to use the Rules module to achieve this, but seems that neither of the modules support Rules.

Any help/tips appreciated.
You can get this to work using a combination of the Rules module and the Content Access module, whereas the Rules module will automatically (behind the scenes) trigger the logic that's needed. The logic itself is entirely hidden for the user (author).

Here are some more details to get it to work:


Start from a rule that is similar to the example I included in my answer to "How to specify a Rules condition related to select list values?".
This sample rule uses a field named field_optionlist, with 3 possible values A,B,C. In your case you should use the fieldname of your Role reference field, and you should tune the possible values for that field also. Some more tips to get you going:


Make sure to tune the fieldname of this field (so that it matches the name you already have) BEFORE importing the rule sample in item '1.' above (if not the import of the rule will fail).
Adapt the Rules condition related to "value = C" to the values that fit your case, and the message included in the Rules Action.

QA-test the intermediate result after completing step '2.': you should have an appropriate Drupal message show up when a node is created with.
Use the integration of the Content Access module with the Rules module to create a Rules Action that updates the access of the node, similar to the Rules Action I included in my sample rule included in my answer to the question "How to revoke edit access to the node&#39;s author after publishing a node?". The actual settings to use for the content access module should match with your settings of course.