Преглед изворни кода

merged materio_title_access and materio_page_title into materio_page_title

Signed-off-by: bachy <git@g-u-i.net>
bachy пре 11 година
родитељ
комит
5fd46660b9
2 измењених фајлова са 117 додато и 57 уклоњено
  1. 73 16
      materio_page_title.module
  2. 44 41
      materio_title_access.module

+ 73 - 16
materio_page_title.module

@@ -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();
+}

+ 44 - 41
materio_title_access.module

@@ -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_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']);
-    }
-  }
-}
+// /**
+//  * 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){
+//   // 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');
+//     }
+//   }
+// }