12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?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']);
- }
- }
- }
|