edlp_compositions_list.inc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. use \Drupal\Core\Url;
  3. use \Drupal\Component\Utility\Unicode;
  4. function template_preprocess_edlp_compositions_list(&$vars){
  5. $vars['compositions'] = array (
  6. '#theme' => 'item_list',
  7. '#items' => [],
  8. );
  9. $i = 0;
  10. foreach($vars['composition_entities'] as $entity){
  11. // get the url
  12. $url = Url::fromRoute('entity.composition.canonical',
  13. ['composition' => $entity->id()], ['absolute' => TRUE]);
  14. // get the delete url
  15. $delete_url = Url::fromRoute('edlp_studio.composition_controller_action_ajax',
  16. ['action' => 'delete', 'cid'=>$entity->id()], ['absolute' => TRUE]);
  17. $title = $entity->getName();
  18. array_unshift($vars['compositions']['#items'], array(
  19. 'compo_link' => array(
  20. '#title' => $title,
  21. '#type' => 'link',
  22. '#url' => $url,
  23. '#options'=>array(
  24. 'attributes' => array(
  25. 'data-drupal-link-system-path' => $url->getInternalPath(),
  26. 'cid' => $entity->id(),
  27. 'class' => ['composition-link', $i==count($vars['composition_entities'])-1 ? 'is-active':''],
  28. 'title'=>$title,
  29. ),
  30. ),
  31. ),
  32. 'delete_link' => array(
  33. '#title' => t("delete"),
  34. '#type' => 'link',
  35. '#url' => $delete_url,
  36. '#options'=>array(
  37. 'attributes' => array(
  38. 'data-drupal-link-system-path' => $delete_url->getInternalPath(),
  39. 'cid' => $entity->id(),
  40. 'class' => ['delete-composition-link'],
  41. 'title'=> t('Delete @title', array('@title'=>$title)),
  42. ),
  43. ),
  44. )
  45. ));
  46. $i++;
  47. }
  48. array_unshift($vars['compositions']['#items'], array(
  49. '#title' => t('New composition'),
  50. '#type' => 'link',
  51. '#url' => $vars['new_composition_url'],
  52. '#options'=>array(
  53. 'attributes' => array(
  54. 'data-drupal-link-system-path' => $vars['new_composition_url']->getInternalPath(),
  55. 'class' => ['new-composition-link']
  56. ),
  57. ),
  58. ));
  59. }