materio_display.module 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Implements hook_init().
  4. */
  5. // function materio_user_init() {
  6. // drupal_add_js(drupal_get_path('module', 'materio_user').'/js/materio_user.min.js');
  7. // }
  8. /**
  9. * Implements hook_permission().
  10. */
  11. function materio_display_permission() {
  12. return array(
  13. 'view full materiau description' => array(
  14. 'title' => t('view full materiau description'),
  15. 'description' => t('view full materiau description'),
  16. ),
  17. );
  18. }
  19. /**
  20. * Implements hook_preprocess().
  21. */
  22. function materio_display_preprocess_field(&$vars, $hook) {
  23. // dsm($vars);
  24. $element = $vars['element'];
  25. if($element['#field_name'] == 'field_description'){
  26. // dsm($vars);
  27. if(!user_access('view full materiau description')){
  28. $value = $element['#items'][0]['value'];
  29. switch ($element['#view_mode']) {
  30. case 'cardbig':
  31. case 'cardfull':
  32. $limit = 210;
  33. break;
  34. default:
  35. $limit = 130;
  36. break;
  37. }
  38. $summary = truncate_utf8($value, $limit, TRUE, TRUE);
  39. $summary .= '<div class="upgrade"><p>'
  40. . t("In order to access full description, information about manufacturers and more, you need to upgrade your account.")
  41. . l(t("Pricing"), 'node/11187')
  42. . '</p></div>';
  43. // dsm($summary);
  44. $vars['items'][0]['#markup'] = $summary;
  45. }
  46. }
  47. }
  48. /**
  49. * Implements hook_entity_info_alter().
  50. */
  51. function materio_display_entity_info_alter(&$entity_info) {
  52. $entity_info['node']['view modes']['homeblock'] = array(
  53. 'label' => t('Home block'),
  54. 'custom settings' => TRUE,
  55. );
  56. }