merged materio_title_access and materio_page_title into materio_page_title

Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
bachy 2013-06-01 20:20:54 +02:00
parent 70b4f2279f
commit 5fd46660b9
2 changed files with 111 additions and 51 deletions

View File

@ -1,5 +1,56 @@
<?php
/**
* Implements hook_permission().
*/
function materio_page_title_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_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;
// }
// }
/**
* 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();
}

View File

@ -1,43 +1,46 @@
<?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_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');
// }
// }
// }