Explorar o código

materio title access

Signed-off-by: bachy <git@g-u-i.net>
bachy %!s(int64=12) %!d(string=hai) anos
pai
achega
b750ae41c4
Modificáronse 2 ficheiros con 65 adicións e 0 borrados
  1. 29 0
      materio_title_access.info
  2. 36 0
      materio_title_access.module

+ 29 - 0
materio_title_access.info

@@ -0,0 +1,29 @@
+name = Materio title access
+description = "Materio title access"
+
+; Core version (required)
+core = 7.x
+
+; Package name (see http://drupal.org/node/542202 for a list of names)
+package = Materio
+
+; PHP version requirement (optional)
+; php = 5.2
+
+; Loadable code files
+;files[] = materio_search_api.theme.inc
+;files[] = materio_search_api.forms.inc
+;files[] = materio_search_api.pages.inc
+;files[] = materio_search_api.admin.inc
+files[] = materio_title_access.module
+
+; Module dependencies
+;dependencies[] = taxonomy
+;dependencies[] = search_api
+dependencies[] = title
+
+; Configuration page
+; configure = admin/config/materiobasemod
+
+; For further information about configuration options, see
+; - http://drupal.org/node/542202

+ 36 - 0
materio_title_access.module

@@ -0,0 +1,36 @@
+<?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'] == 'field_of_interest' && $op == 'edit') {
+   *  return user_access('edit field of interest', $account);
+   *}
+   */
+  /* Your code here */
+  // dsm($entity, 'entity');
+  // dsm($entity_type, 'entity_type');
+
+  if($field['field_name'] == 'title_field' && $entity_type == 'node' && isset($entity->type)){
+  	return user_access('show '.$entity->type.' title');
+  }
+
+  return TRUE;
+}