From 5fd46660b9818de36797572e0f97b7740733f020 Mon Sep 17 00:00:00 2001 From: bachy Date: Sat, 1 Jun 2013 20:20:54 +0200 Subject: [PATCH] merged materio_title_access and materio_page_title into materio_page_title Signed-off-by: bachy --- materio_page_title.module | 89 ++++++++++++++++++++++++++++++------- materio_title_access.module | 73 +++++++++++++++--------------- 2 files changed, 111 insertions(+), 51 deletions(-) diff --git a/materio_page_title.module b/materio_page_title.module index e94818c8..c0a5f965 100644 --- a/materio_page_title.module +++ b/materio_page_title.module @@ -1,5 +1,56 @@ $value) { + $perms['show '.$bundle.' title'] = array( + 'title' => t('Show !bundle node title.', array('!bundle'=>$value['label'])), + ); + } + return $perms; +} + +/** + * Implements hook_field_access(). + */ +function materio_page_title_field_access($op, $field, $entity_type, $entity, $account) { + if($field['field_name'] == 'title_field' && $entity_type == 'node' && isset($entity->type)){ + return user_access('show '.$entity->type.' title'); + } + return TRUE; +} + +function materio_page_title_preprocess_html(&$vars){ + // dsm($vars, '$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']); + + // // dsm($vars, 'vars'); + // } + // } + + $vars['head_title_array']['title'] = materio_page_title_get_title(); + $vars['head_title'] = implode(' | ', $vars['head_title_array']); + $vars['head_array']['title'] = $vars['head_title']; + +} + + + /** * Implements hook_block_info(). */ @@ -35,21 +86,6 @@ function materio_page_title_block_view($delta = '') { return $block; } -function materio_page_title_get_title(){ - - 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'); - return $title[0]['safe_value']; - }else{ - return 'restricted access'; - } - } - } - - return drupal_get_title(); -} /** * Implements hook_theme(). @@ -88,4 +124,25 @@ function theme_materio_page_title($vars){ // ); // return $items; -// } \ No newline at end of file +// } + + +/** +* HELPERS +* */ + +function materio_page_title_get_title(){ + + 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'); + return $title[0]['safe_value']; + }else{ + return 'restricted access'; + } + } + } + + return drupal_get_title(); +} diff --git a/materio_title_access.module b/materio_title_access.module index ebe0f37f..375c36b4 100644 --- a/materio_title_access.module +++ b/materio_title_access.module @@ -1,43 +1,46 @@ $value) { - $perms['show '.$bundle.' title'] = array( - 'title' => t('Show !bundle node title.', array('!bundle'=>$value['label'])), - ); - } - return $perms; -} +// /** +// * Implements hook_permission(). +// */ +// function materio_title_access_permission() { +// $perms = array(); +// $entity_infos = entity_get_info(); +// foreach ($entity_infos['node']['bundles'] as $bundle => $value) { +// $perms['show '.$bundle.' title'] = array( +// 'title' => t('Show !bundle node title.', array('!bundle'=>$value['label'])), +// ); +// } +// return $perms; +// } -/** - * Implements hook_field_access(). - */ -function materio_title_access_field_access($op, $field, $entity_type, $entity, $account) { - if($field['field_name'] == 'title_field' && $entity_type == 'node' && isset($entity->type)){ - return user_access('show '.$entity->type.' title'); - } - return TRUE; -} +// /** +// * Implements hook_field_access(). +// */ +// function materio_title_access_field_access($op, $field, $entity_type, $entity, $account) { +// 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){ +// function materio_title_access_preprocess_html(&$vars){ +// // dsm($vars, '$vars'); - if (arg(0) == 'node' && $node = node_load(arg(1))) { +// 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'; - } +// 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']); - } - } -} +// $vars['head_title'] = implode(' | ', $vars['head_title_array']); + +// // dsm($vars, 'vars'); +// } +// } +// }