edlp_studio.module 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * @file
  4. * Contains edlp_studio.module.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. /**
  8. * Implements hook_help().
  9. */
  10. function edlp_studio_help($route_name, RouteMatchInterface $route_match) {
  11. switch ($route_name) {
  12. // Main module help for the edlp_studio module.
  13. case 'help.page.edlp_studio':
  14. $output = '';
  15. $output .= '<h3>' . t('About') . '</h3>';
  16. $output .= '<p>' . t('Edlp module that handle chutier and compositions entities') . '</p>';
  17. return $output;
  18. default:
  19. }
  20. }
  21. /**
  22. * hook_entity_extra_field_info()
  23. *
  24. */
  25. function edlp_studio_entity_extra_field_info(){
  26. $extra = [];
  27. // TODO: get node content type by settings @see readme
  28. $extra['node']['enregistrement']['display']['add_to_chutier'] = [
  29. 'label' => t('Add to chutier link'),
  30. 'description' => 'Display a link to add the content to chutier',
  31. 'weight' => 99,
  32. 'visible' => FALSE,
  33. ];
  34. return $extra;
  35. }
  36. /**
  37. * Implements hook_ENTITY_TYPE_view().
  38. * @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8
  39. */
  40. function edlp_studio_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
  41. $display_settings = $display->getComponent('add_to_chutier');
  42. if (!empty($display_settings)) {
  43. // dpm($entity);
  44. // dpm($entity->id());
  45. $url = Url::fromRoute('edlp_studio.chutier_controller_add_content', ['id'=>$entity->id()], array(
  46. 'attributes' => array(
  47. 'class' => ['add-to-chutier-link', 'ajax-link'],
  48. 'target_id' => $entity->id(),
  49. )
  50. ));
  51. $build['add_to_chutier'] = array(
  52. '#title' => t("Add this content to chutier."),
  53. '#type' => 'link',
  54. '#url' => $url,
  55. '#options'=>array(
  56. 'attributes' => array(
  57. 'data-drupal-link-system-path' => $url->getInternalPath()
  58. )
  59. )
  60. );
  61. }
  62. }