materio_didactique.module 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * Implements hook_permission().
  4. */
  5. function materio_didactique_permission() {
  6. return array(
  7. 'view materio didactique home block' => array(
  8. 'title' => t('view materio didactique home block'),
  9. 'description' => t(''),
  10. ),
  11. );
  12. }
  13. /**
  14. * Implements hook_block_info().
  15. */
  16. function materio_didactique_block_info() {
  17. $blocks['materio_didactique_home'] = array(
  18. 'info' => t('Materio didactique home block'),
  19. 'cache' => DRUPAL_NO_CACHE
  20. );
  21. return $blocks;
  22. }
  23. /**
  24. * Implements hook_block_view().
  25. */
  26. function materio_didactique_block_view($delta = '') {
  27. $block = array();
  28. switch ($delta) {
  29. case 'materio_didactique_home':
  30. if(user_access('view materio didactique home block')){
  31. $query = new EntityFieldQuery;
  32. $query
  33. ->entityCondition('entity_type', 'node')
  34. ->propertyCondition('status', 1)
  35. ->entityCondition('bundle', array('didactique'))
  36. ->fieldCondition('field_displayed_in_home', 'value', 1)
  37. ->fieldOrderBy('field_weight', 'value', 'ASC');
  38. $result = $query->execute();
  39. // dsm($result, '$result');
  40. if (isset($result['node'])) {
  41. $block['subject'] = t('Didactique home block');
  42. $block['content'] = theme('materio_didactique_home_block', array('items' => $result['node']));
  43. }
  44. }
  45. break;
  46. }
  47. return $block;
  48. }
  49. /**
  50. * Implements hook_theme().
  51. */
  52. function materio_didactique_theme($existing, $type, $theme, $path) {
  53. return array(
  54. 'materio_didactique_home_block' => array(
  55. 'arguments' => array('items'=>NULL),
  56. 'template' => 'materio-didactique-home-block',
  57. 'path' => drupal_get_path('module', 'materio_didactique').'/templates',
  58. ),
  59. );
  60. }
  61. function template_preprocess_materio_didactique_home_block(&$vars){
  62. // dsm($vars, 'template_preprocess_materio_didactique_home_block | $vars');
  63. $items = array();
  64. foreach ($vars['items'] as $nid => $item) {
  65. $items[] = node_load($nid);
  66. }
  67. $vars['items'] = $items;
  68. }