Browse Source

restrict page title on materiau node page for visitors

Signed-off-by: bachy <git@g-u-i.net>
bachy 11 years ago
parent
commit
6c85be6c6d
1 changed files with 18 additions and 11 deletions
  1. 18 11
      materio_title_access.module

+ 18 - 11
materio_title_access.module

@@ -19,18 +19,25 @@ function materio_title_access_permission() {
  * Implements hook_field_access().
  */
 function materio_title_access_field_access($op, $field, $entity_type, $entity, $account) {
-  /*
-   *if ($field['field_name'] == 'field_of_interest' && $op == 'edit') {
-   *  return user_access('edit field of interest', $account);
-   *}
-   */
-  /* Your code here */
-  // dsm($entity, 'entity');
-  // dsm($entity_type, 'entity_type');
-
   if($field['field_name'] == 'title_field' && $entity_type == 'node' && isset($entity->type)){
   	return user_access('show '.$entity->type.' title');
   }
-
   return TRUE;
-}
+}
+
+function materio_title_access_preprocess_html(&$vars){
+
+  if (arg(0) == 'node' && $node = node_load(arg(1))) {
+
+    if(!user_access('show '.$node->type.' title')){
+      if($node->type == "materiau"){
+        $title = field_get_items('node', $node, 'field_nature_titre');
+        $vars['head_title_array']['title'] = $title[0]['safe_value'];
+      }else{
+        $vars['head_title_array']['title'] = 'restricted access';
+      }
+
+      $vars['head_title'] = implode(' | ', $vars['head_title_array']);
+    }
+  }
+}