edlp_studio.module 4.1 KB

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