edlp_studio.module 3.8 KB

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