| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 | <?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(). */function materio_page_title_block_info() {  // This example comes from node.module.  /*   *$blocks['syndicate'] = array(   *  'info' => t('Syndicate'),   *  'cache' => DRUPAL_NO_CACHE   *);   */  $blocks['materio_page_title'] = array(    'info' => t('Materio page title'),    'cache' => DRUPAL_NO_CACHE  );  return $blocks;}/** * Implements hook_block_view(). */function materio_page_title_block_view($delta = '') {  $block = array();  switch ($delta) {    case 'materio_page_title':      $block['subject'] = t('Page title');      $block['content'] = theme('materio_page_title', array('title' => materio_page_title_get_title()));      drupal_add_js(drupal_get_path('module', 'materio_page_title').'/js/materio_page_title.min.js');      break;  }  return $block;}/** * Implements hook_theme(). */function materio_page_title_theme($existing, $type, $theme, $path) {  return array(    'materio_page_title' => array(      'variables' => array('title' => NULL,),    ),  );}function theme_materio_page_title($vars){	if($vars['title'])		return '<h1 id="materio-page-title" class="page-title">'.$vars['title'].'</h1>';	return;}/** * Implements hook_menu(). */// function materio_page_title_menu() {//   $items = array();//   $base = array(//     'type' => MENU_CALLBACK,//     'file' => 'materio_page_title.pages.inc',//   );//   $items['materio_page_title/refresh/block'] = $base+array(//     'title' => 'Materio page title refresh block',//     'page callback' => 'materio_page_title_refresh_block',//     'page arguments' => array(),//     'access callback' => TRUE,//   );//   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();}
 |