edlp_chutier_ui.inc 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. use \Drupal\Core\Url;
  3. use Drupal\Component\Utility\Unicode;
  4. use Drupal\edlp_studio\Entity\Chutier;
  5. function template_preprocess_edlp_chutier_ui(&$vars){
  6. // dpm($vars);
  7. // $view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
  8. $vars['documents'] = array (
  9. '#theme' => 'item_list',
  10. '#items' => [],
  11. );
  12. foreach($vars['document_nodes'] as $node){
  13. // get the url
  14. $url = Url::fromRoute('entity.node.canonical', ['node' => $node->id()], ['absolute' => TRUE]);
  15. // get the audio file url
  16. $field_son_values = $node->get('field_son')->getValue();
  17. $son_fid = count($field_son_values) ? $field_son_values[0]['target_id'] : "";
  18. $son_file = \Drupal\file\Entity\File::load($son_fid);
  19. $son_url = null;
  20. if($son_file){
  21. $son_uri = $son_file->getFileUri();
  22. $son_url = file_create_url($son_uri);
  23. }
  24. // get the title
  25. $title = $node->getTitle();
  26. if(!$title) continue;
  27. $trunc_title = Unicode::truncate($title, 25, true, true);
  28. // classes
  29. $classes = array('audio-link', 'ajax-link');
  30. // get the entries
  31. $entrees = '';
  32. foreach ($node->get('field_entrees')->getValue() as $key => $term) {
  33. $entrees .= '<span class="entree" tid="'.$term['target_id'].'"></span>';
  34. }
  35. //
  36. // get the remove url (obviously as we are in chutier all contents actions are remove ;)
  37. $remove_url = Chutier::getActionsUrl($node->id(), $vars['uid']);
  38. // build the link
  39. array_unshift($vars['documents']['#items'], array(
  40. '#type' => 'container',
  41. 'remove_link' => array(
  42. '#title' => t("Chutier."),
  43. '#type' => 'link',
  44. '#url' => $remove_url,
  45. '#options'=>array(
  46. 'attributes' => array(
  47. 'data-drupal-link-system-path' => $remove_url->getInternalPath()
  48. ),
  49. ),
  50. ),
  51. 'link'=>array(
  52. '#title' => $trunc_title,
  53. '#type' => 'link',
  54. '#url' => $url,
  55. '#options'=>array(
  56. 'attributes' => array(
  57. 'data-drupal-link-system-path' => $url->getInternalPath(),
  58. 'audio_url' => $son_url,
  59. 'nid' => $node->id(),
  60. // 'tid' => $entrees[mt_rand(0, count($entrees) - 1)],
  61. // 'entries_size' => count($entrees),
  62. 'class' => $classes,
  63. 'title'=>$title,
  64. ),
  65. ),
  66. ),
  67. 'entrees' => array(
  68. '#type' => 'container',
  69. '#attributes'=>['class'=>['entrees']],
  70. '#markup'=>$entrees,
  71. )
  72. ));
  73. }
  74. }