edlp_studio.module 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * @file
  4. * Contains edlp_studio.module.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. use Drupal\Core\Url;
  8. use Drupal\edlp_studio\Entity\Chutier;
  9. /**
  10. * Implements hook_help().
  11. */
  12. function edlp_studio_help($route_name, RouteMatchInterface $route_match) {
  13. switch ($route_name) {
  14. // Main module help for the edlp_studio module.
  15. case 'help.page.edlp_studio':
  16. $output = '';
  17. $output .= '<h3>' . t('About') . '</h3>';
  18. $output .= '<p>' . t('Edlp module that handle chutier and compositions entities') . '</p>';
  19. return $output;
  20. default:
  21. }
  22. }
  23. /**
  24. * Implements hook_page_attachments().
  25. * @param array $attachments
  26. */
  27. function edlp_studio_page_attachments(array &$attachments) {
  28. $attachments['#attached']['library'][] = 'edlp_studio/edlp_studio-library';
  29. $url = Url::fromRoute('edlp_studio.studio_chutier_ui_ajax', [], ['absolute' => TRUE]);
  30. $attachments['#attached']['drupalSettings']['edlp_studio']['chutier_ui_ajax'] = $url->getInternalPath();
  31. $url = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action'=>'open'], ['absolute' => TRUE]);
  32. $attachments['#attached']['drupalSettings']['edlp_studio']['open_compo_ajax_url'] = $url->getInternalPath();
  33. }
  34. /**
  35. * Implements hook_theme().
  36. */
  37. function edlp_studio_theme($existing, $type, $theme, $path) {
  38. // @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
  39. return array(
  40. 'edlp_chutier_ui' => array(
  41. 'file' => 'includes/edlp_chutier_ui.inc',
  42. 'variables' => array(
  43. 'title' => t('Chutier'),
  44. 'document_nodes' => array(),
  45. 'uid' => null,
  46. ),
  47. ),
  48. 'edlp_composition_ui' => array(
  49. 'file' => 'includes/edlp_composition_ui.inc',
  50. 'variables' => array(
  51. 'title' => t('Compositon'),
  52. 'compositions' => null,
  53. 'composer_header' => null,
  54. 'lastcomposition' => null,
  55. 'composer_actions' => null,
  56. ),
  57. ),
  58. 'edlp_compositions_list' => array(
  59. 'file' => 'includes/edlp_compositions_list.inc',
  60. 'variables' => array(
  61. 'composition_entities' => array(),
  62. 'new_composition_url' => Null,
  63. ),
  64. ),
  65. 'edlp_studio_ui' => array(
  66. 'file' => 'includes/edlp_studio_ui.inc',
  67. 'variables' => array(
  68. 'chutier_ui' => null,
  69. 'composition_ui' => null,
  70. ),
  71. ),
  72. );
  73. }
  74. /**
  75. * hook_entity_extra_field_info()
  76. *
  77. */
  78. function edlp_studio_entity_extra_field_info(){
  79. $extra = [];
  80. // TODO: get node content type by settings @see readme
  81. $extra['node']['enregistrement']['display']['chutier_actions'] = [
  82. 'label' => t('Chutier actions'),
  83. 'description' => 'Display a link to add the content to chutier',
  84. 'weight' => 99,
  85. 'visible' => FALSE,
  86. ];
  87. return $extra;
  88. }
  89. /**
  90. * Implements hook_ENTITY_TYPE_view().
  91. * @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8
  92. */
  93. function edlp_studio_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
  94. $display_settings = $display->getComponent('chutier_actions');
  95. if (!empty($display_settings)) {
  96. // dpm($entity);
  97. // dpm($entity->id());
  98. $user = \Drupal::currentUser();
  99. // dpm($user);
  100. // check if user loged in ? no -> popup message : yes -> links
  101. if($user->id() == 0){
  102. $build['chutier_actions'] = array(
  103. '#type' => 'container',
  104. '#attributes' => array(
  105. 'class' => array('chutier-icon', 'not-logedin')
  106. ),
  107. "popup"=>array(
  108. '#type'=>'container',
  109. '#attributes' => array(
  110. 'class' => array('popup')
  111. ),
  112. "content"=>array(
  113. '#type'=>'container',
  114. '#attributes' => array(
  115. 'class' => array('inner')
  116. ),
  117. 'text'=>array(
  118. '#prefix'=>'<p>',
  119. '#markup'=>t('Le Studio rassemble vos documents favoris.Il permet de les sauvgarder et de les agencer en compositions.'),
  120. '#suffix'=>'</p>'
  121. ),
  122. 'links'=>array(
  123. '#prefix'=>'<p>',
  124. '#markup'=>'todo: login link',
  125. '#suffix'=>'</p>'
  126. )
  127. )
  128. )
  129. );
  130. }else{
  131. // TODO: check if user has permission 'use chutier'
  132. $url = Chutier::getActionsUrl($entity->id(), $user->id());
  133. $build['chutier_actions'] = array(
  134. '#type' => 'link',
  135. '#title' => 'Chutier',
  136. '#url' => $url,
  137. '#options'=>array(
  138. 'attributes' => array(
  139. 'data-drupal-link-system-path' => $url->getInternalPath()
  140. )
  141. )
  142. );
  143. }
  144. }
  145. }
  146. /**
  147. * Prepares variables for Composition templates.
  148. *
  149. * Default template: composition.html.twig.
  150. *
  151. * @param array $variables
  152. * An associative array containing:
  153. * - elements: An associative array containing the user information and any
  154. * - attributes: HTML attributes for the containing element.
  155. */
  156. // function edlp_studio_preprocess_composition(array &$vars) {
  157. // dpm($vars);
  158. // $vars['test'] = 'test';
  159. // }