edlp_studio.module 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. * hook_entity_extra_field_info()
  32. *
  33. */
  34. function edlp_studio_entity_extra_field_info(){
  35. $extra = [];
  36. // TODO: get node content type by settings @see readme
  37. $extra['node']['enregistrement']['display']['chutier_actions'] = [
  38. 'label' => t('Chutier actions'),
  39. 'description' => 'Display a link to add the content to chutier',
  40. 'weight' => 99,
  41. 'visible' => FALSE,
  42. ];
  43. return $extra;
  44. }
  45. /**
  46. * Implements hook_ENTITY_TYPE_view().
  47. * @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8
  48. */
  49. function edlp_studio_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
  50. $display_settings = $display->getComponent('chutier_actions');
  51. if (!empty($display_settings)) {
  52. // dpm($entity);
  53. // dpm($entity->id());
  54. $user = \Drupal::currentUser();
  55. // dpm($user);
  56. // check if user loged in ? no -> popup message : yes -> links
  57. if($user->id() == 0){
  58. $build['chutier_actions'] = array(
  59. '#type' => 'container',
  60. '#attributes' => array(
  61. 'class' => array('chutier-icon', 'not-logedin')
  62. ),
  63. "popup"=>array(
  64. '#type'=>'container',
  65. '#attributes' => array(
  66. 'class' => array('popup')
  67. ),
  68. "content"=>array(
  69. '#type'=>'container',
  70. '#attributes' => array(
  71. 'class' => array('inner')
  72. ),
  73. 'text'=>array(
  74. '#prefix'=>'<p>',
  75. '#markup'=>t('Le Studio rassemble vos documents favoris.Il permet de les sauvgarder et de les agencer en compositions.'),
  76. '#suffix'=>'</p>'
  77. ),
  78. 'links'=>array(
  79. '#prefix'=>'<p>',
  80. '#markup'=>'todo: login link',
  81. '#suffix'=>'</p>'
  82. )
  83. )
  84. )
  85. );
  86. }else{
  87. // TODO: check if user has permission 'use chutier'
  88. $url = Chutier::getActionsUrl($entity->id(), $user->id());
  89. $build['chutier_actions'] = array(
  90. '#type' => 'link',
  91. '#url' => $url,
  92. '#options'=>array(
  93. 'attributes' => array(
  94. 'data-drupal-link-system-path' => $url->getInternalPath()
  95. )
  96. )
  97. );
  98. }
  99. }
  100. }