materio_title_access.module 919 B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. /**
  3. * Implements hook_permission().
  4. */
  5. function materio_title_access_permission() {
  6. $perms = array();
  7. $entity_infos = entity_get_info();
  8. foreach ($entity_infos['node']['bundles'] as $bundle => $value) {
  9. $perms['show '.$bundle.' title'] = array(
  10. 'title' => t('Show !bundle node title.', array('!bundle'=>$value['label'])),
  11. );
  12. }
  13. return $perms;
  14. }
  15. /**
  16. * Implements hook_field_access().
  17. */
  18. function materio_title_access_field_access($op, $field, $entity_type, $entity, $account) {
  19. /*
  20. *if ($field['field_name'] == 'field_of_interest' && $op == 'edit') {
  21. * return user_access('edit field of interest', $account);
  22. *}
  23. */
  24. /* Your code here */
  25. // dsm($entity, 'entity');
  26. // dsm($entity_type, 'entity_type');
  27. if($field['field_name'] == 'title_field' && $entity_type == 'node' && isset($entity->type)){
  28. return user_access('show '.$entity->type.' title');
  29. }
  30. return TRUE;
  31. }