clameursmod.module 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // function clameursmod_panels_pre_render($panel, &$renderer){
  3. // dsm($panel, 'panel');
  4. // dsm($renderer, 'renderer');
  5. //
  6. // $node_ctx = $render->display['context'][0]['data'];
  7. // dsm($node_ctx, 'node_ctx');
  8. //
  9. // }
  10. /**
  11. * Implements hook_block_info().
  12. */
  13. function clameursmod_block_info() {
  14. $blocks['thematiques-anchor-links'] = array(
  15. 'info' => t('Clameurs thematique anchor links'),
  16. 'cache' => DRUPAL_NO_CACHE
  17. );
  18. return $blocks;
  19. }
  20. /**
  21. * Implements hook_block_view().
  22. */
  23. function clameursmod_block_view($delta = '') {
  24. $block = array();
  25. switch ($delta) {
  26. case 'thematiques-anchor-links':
  27. $block['subject'] = t('Thématique menu');
  28. $block['content'] = _clameursmod_thematiques_anchor_links();
  29. break;
  30. }
  31. return $block;
  32. }
  33. function _clameursmod_thematiques_anchor_links(){
  34. $query = new EntityFieldQuery();
  35. $query
  36. ->entityCondition('entity_type', 'node')
  37. ->entityCondition('bundle', 'thematique')
  38. ->propertyCondition('status', 1);
  39. // ->propertyOrderBy('created', 'DESC');
  40. $result = $query->execute();
  41. $nids = array_keys($result['node']);
  42. $nodes = [];
  43. foreach ($nids as $nid) {
  44. $node = node_load($nid);
  45. $alias = drupal_get_path_alias('node/'.$nid);
  46. // TODO: get the workflow state ID
  47. $nodes[$nid] = array(
  48. "alias"=>$alias,
  49. "title"=>$node->title
  50. );
  51. }
  52. return theme('thematiques_anchor_links', array("items"=>$nodes));
  53. }
  54. /**
  55. * Implements hook_theme().
  56. */
  57. function clameursmod_theme($existing, $type, $theme, $path) {
  58. return array(
  59. 'thematiques_anchor_links' => array(
  60. 'render element' => 'element'
  61. ),
  62. );
  63. }
  64. function theme_thematiques_anchor_links($vars){
  65. $list = array(
  66. 'items'=>array(),
  67. 'type'=>'ul',
  68. 'attributes'=>array(
  69. "class"=>array("thematique-anchor-links")
  70. )
  71. );
  72. foreach ($vars["items"] as $nid => $val) {
  73. // TODO: display the workflow state ID
  74. $options = array(
  75. "class"=>array("anchor"),
  76. "fragment"=>$val['alias']
  77. );
  78. $list['items'][] = l($val['title'], '' , $options);
  79. }
  80. return theme('item_list', $list);
  81. }