From 6c85be6c6dd5d17ed9ac944c963c6a4a5c5c84e6 Mon Sep 17 00:00:00 2001 From: bachy Date: Fri, 24 May 2013 19:27:13 +0200 Subject: [PATCH] restrict page title on materiau node page for visitors Signed-off-by: bachy --- materio_title_access.module | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/materio_title_access.module b/materio_title_access.module index 8dfc80ce..ebe0f37f 100644 --- a/materio_title_access.module +++ b/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; -} \ No newline at end of file +} + +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']); + } + } +}