123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- /**
- * @file
- * Contains edlp_studio.module.
- */
- use Drupal\Core\Routing\RouteMatchInterface;
- use Drupal\Core\Url;
- use Drupal\edlp_studio\Entity\Chutier;
- /**
- * Implements hook_help().
- */
- function edlp_studio_help($route_name, RouteMatchInterface $route_match) {
- switch ($route_name) {
- // Main module help for the edlp_studio module.
- case 'help.page.edlp_studio':
- $output = '';
- $output .= '<h3>' . t('About') . '</h3>';
- $output .= '<p>' . t('Edlp module that handle chutier and compositions entities') . '</p>';
- return $output;
- default:
- }
- }
- /**
- * Implements hook_page_attachments().
- * @param array $attachments
- */
- function edlp_studio_page_attachments(array &$attachments) {
- $attachments['#attached']['library'][] = 'edlp_studio/edlp_studio-library';
- }
- /**
- * hook_entity_extra_field_info()
- *
- */
- function edlp_studio_entity_extra_field_info(){
- $extra = [];
- // TODO: get node content type by settings @see readme
- $extra['node']['enregistrement']['display']['chutier_actions'] = [
- 'label' => t('Chutier actions'),
- 'description' => 'Display a link to add the content to chutier',
- 'weight' => 99,
- 'visible' => FALSE,
- ];
- return $extra;
- }
- /**
- * Implements hook_ENTITY_TYPE_view().
- * @see https://www.amazeelabs.com/en/render-menu-tree-custom-code-drupal-8
- */
- function edlp_studio_node_view(array &$build, \Drupal\Core\Entity\EntityInterface $entity, \Drupal\Core\Entity\Display\EntityViewDisplayInterface $display, $view_mode) {
- $display_settings = $display->getComponent('chutier_actions');
- if (!empty($display_settings)) {
- // dpm($entity);
- // dpm($entity->id());
- $user = \Drupal::currentUser();
- // dpm($user);
- // check if user loged in ? no -> popup message : yes -> links
- if($user->id() == 0){
- $build['chutier_actions'] = array(
- '#type' => 'container',
- '#attributes' => array(
- 'class' => array('chutier-icon', 'not-logedin')
- ),
- "popup"=>array(
- '#type'=>'container',
- '#attributes' => array(
- 'class' => array('popup')
- ),
- "content"=>array(
- '#type'=>'container',
- '#attributes' => array(
- 'class' => array('inner')
- ),
- 'text'=>array(
- '#prefix'=>'<p>',
- '#markup'=>t('Le Studio rassemble vos documents favoris.Il permet de les sauvgarder et de les agencer en compositions.'),
- '#suffix'=>'</p>'
- ),
- 'links'=>array(
- '#prefix'=>'<p>',
- '#markup'=>'todo: login link',
- '#suffix'=>'</p>'
- )
- )
- )
- );
- }else{
- // TODO: check if user has permission 'use chutier'
- $url = Chutier::getActionsUrl($entity->id(), $user->id());
- $build['chutier_actions'] = array(
- '#type' => 'link',
- '#url' => $url,
- '#options'=>array(
- 'attributes' => array(
- 'data-drupal-link-system-path' => $url->getInternalPath()
- )
- )
- );
- }
- }
- }
|