edlp_studio.module 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. }
  32. /**
  33. * Implements hook_theme().
  34. */
  35. function edlp_studio_theme($existing, $type, $theme, $path) {
  36. // @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
  37. return array(
  38. 'edlp_chutier_ui' => array(
  39. 'file' => 'includes/edlp_chutier_ui.inc',
  40. 'variables' => array(
  41. 'title' => t('Chutier'),
  42. 'document_nodes' => array(),
  43. 'uid' => null,
  44. ),
  45. ),
  46. 'edlp_composition_ui' => array(
  47. 'file' => 'includes/edlp_composition_ui.inc',
  48. 'variables' => array(
  49. 'title' => t('Compositon'),
  50. 'compositions' => null,
  51. 'composer' => null,
  52. ),
  53. ),
  54. 'edlp_compositions_list' => array(
  55. 'file' => 'includes/edlp_compositions_list.inc',
  56. 'variables' => array(
  57. 'composition_entities' => array(),
  58. 'new_composition_url' => Null,
  59. ),
  60. ),
  61. 'edlp_studio_ui' => array(
  62. 'file' => 'includes/edlp_studio_ui.inc',
  63. 'variables' => array(
  64. 'chutier_ui' => null,
  65. 'composition_ui' => null,
  66. ),
  67. ),
  68. );
  69. }
  70. /**
  71. * hook_entity_extra_field_info()
  72. *
  73. */
  74. function edlp_studio_entity_extra_field_info(){
  75. $extra = [];
  76. // TODO: get node content type by settings @see readme
  77. $extra['node']['enregistrement']['display']['chutier_actions'] = [
  78. 'label' => t('Chutier actions'),
  79. 'description' => 'Display a link to add the content to chutier',
  80. 'weight' => 99,
  81. 'visible' => FALSE,
  82. ];
  83. return $extra;
  84. }
  85. /**
  86. * Implements hook_ENTITY_TYPE_view().
  87. * @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8
  88. */
  89. function edlp_studio_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
  90. $display_settings = $display->getComponent('chutier_actions');
  91. if (!empty($display_settings)) {
  92. // dpm($entity);
  93. // dpm($entity->id());
  94. $user = \Drupal::currentUser();
  95. // dpm($user);
  96. // check if user loged in ? no -> popup message : yes -> links
  97. if($user->id() == 0){
  98. $build['chutier_actions'] = array(
  99. '#type' => 'container',
  100. '#attributes' => array(
  101. 'class' => array('chutier-icon', 'not-logedin')
  102. ),
  103. "popup"=>array(
  104. '#type'=>'container',
  105. '#attributes' => array(
  106. 'class' => array('popup')
  107. ),
  108. "content"=>array(
  109. '#type'=>'container',
  110. '#attributes' => array(
  111. 'class' => array('inner')
  112. ),
  113. 'text'=>array(
  114. '#prefix'=>'<p>',
  115. '#markup'=>t('Le Studio rassemble vos documents favoris.Il permet de les sauvgarder et de les agencer en compositions.'),
  116. '#suffix'=>'</p>'
  117. ),
  118. 'links'=>array(
  119. '#prefix'=>'<p>',
  120. '#markup'=>'todo: login link',
  121. '#suffix'=>'</p>'
  122. )
  123. )
  124. )
  125. );
  126. }else{
  127. // TODO: check if user has permission 'use chutier'
  128. $url = Chutier::getActionsUrl($entity->id(), $user->id());
  129. $build['chutier_actions'] = array(
  130. '#type' => 'link',
  131. '#title' => 'Chutier',
  132. '#url' => $url,
  133. '#options'=>array(
  134. 'attributes' => array(
  135. 'data-drupal-link-system-path' => $url->getInternalPath()
  136. )
  137. )
  138. );
  139. }
  140. }
  141. }