1

I written a module to filter the access for country_admin,country_admin can only view and edit the content that have the same country with the country_admin.(Both the country_admin and content have a country field.) Now I want to hide the content that current country_admin have no access on. Is there a function can hide the content in drupal 7 ? Will be very appreciate if anyone can help.

if(!isset($target_user->field_role_country) || !$target_user->field_role_country['und'][0]['value']) {
  // The value is false (checkbox not checked) so we refuse access:
  return FALSE;
}
elseif ($node->type == 'clinic' 
    && strtolower($target_user->field_role_country['und'][0]['value']) != strtolower($node->field_country['und'][0]['value'])) {
  drupal_set_message('This clinic does not associated with :country, You have no permission to view.', array(':country' => $target_user->field_role_country['und'][0]['value']));
  return FALSE;
}
1

1 Answer 1

0

hook_query_alter() serves this purpose.

The exact query alter you want looks like this:

function modulename_query_node_access_alter(QueryAlterableInterface $query) {
  // Obtain node, if needed
  $node = $query->getMetaData('node');

  // Do some calculations

  // Add condition
  $query->condition( /* your custom conditions here */ );
}

More details on Query alteration documentation page.

2
  • thanks for your answer.But I dont know how to use this,I just want to hide the content after filter.I still not find a good way.
    – Zhu Jing
    Oct 24, 2013 at 2:06
  • @ZhuJing if you want me to actually help with your code, post your code. If you are asking in general way, generic answer is all you can ever get. Se SSCCE.
    – Mołot
    Oct 24, 2013 at 5:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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