materio-base-legacy/materio_title_access.module
bachy 6c85be6c6d restrict page title on materiau node page for visitors
Signed-off-by: bachy <git@g-u-i.net>
2013-05-24 19:27:13 +02:00

44 lines
1.2 KiB
Plaintext

<?php
/**
* 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;
}
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']);
}
}
}