' . t('About') . ''; $output .= '
' . t('Edlp module that handle chutier and compositions entities') . '
'; 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'; // chutier ui $url = Url::fromRoute('edlp_studio.studio_chutier_ui_ajax', [], ['absolute' => TRUE]); $attachments['#attached']['drupalSettings']['edlp_studio']['chutier_ui_ajax'] = $url->getInternalPath(); // open compo $url = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action'=>'open'], ['absolute' => TRUE]); $attachments['#attached']['drupalSettings']['edlp_studio']['open_compo_ajax_url'] = $url->getInternalPath(); // save compo $url = Url::fromRoute('edlp_studio.composition_controller_action_ajax', ['action'=>'save'], ['absolute' => TRUE]); $attachments['#attached']['drupalSettings']['edlp_studio']['save_compo_ajax_url'] = $url->getInternalPath(); } /** * Implements hook_theme(). */ function edlp_studio_theme($existing, $type, $theme, $path) { // @see https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module return array( 'composition' => array( 'file' => 'includes/composition.inc', 'render element'=>'elements', ), 'edlp_chutier_ui' => array( 'file' => 'includes/edlp_chutier_ui.inc', 'variables' => array( 'title' => t('Chutier'), 'document_nodes' => array(), 'uid' => null, ), ), 'edlp_composition_ui' => array( 'file' => 'includes/edlp_composition_ui.inc', 'variables' => array( 'title' => t('Compositon'), 'compositions' => null, 'composer_header' => null, 'lastcomposition' => null, 'composer_actions' => null, ), ), 'edlp_compositions_list' => array( 'file' => 'includes/edlp_compositions_list.inc', 'variables' => array( 'composition_entities' => array(), 'new_composition_url' => Null, ), ), 'edlp_studio_ui' => array( 'file' => 'includes/edlp_studio_ui.inc', 'variables' => array( 'chutier_ui' => null, 'composition_ui' => null, ), ), ); } /** * Implements hook_theme_suggestions_HOOK(). */ function edlp_studio_theme_suggestions_composition(array $vars) { // dpm($vars); $suggestions = []; /** @var \Drupal\edlp_studio\CompositionInterface $compo */ $compo = $vars['elements']['#composition']; // $suggestions[] = 'composition'; $suggestions[] = 'composition__' . $compo->id(); $suggestions[] = 'composition__' . $vars['elements']['#view_mode']; $suggestions[] = 'composition__' . $compo->id() . '__' . $vars['elements']['#view_mode']; // $suggestions[] = 'taxonomy_term__' . $term->id(); // dpm($suggestions); return $suggestions; } /** * 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 $register_url = Url::fromRoute('user.register'); 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') ), 'description'=>array( '#prefix'=>'', '#markup'=>t('To bookmark sounds and make your own playlists, you must log in. Click the studio icon on the low-right corner of the page.'), '#suffix'=>'
' ), // TODO: ajouter le login form 'register'=>array( '#prefix'=>'', 'register'=> array( '#type' => 'link', '#title' => t('Create new account'), '#url' => $register_url, '#options'=>array( 'attributes' => array( 'data-drupal-link-system-path' => $register_url->getInternalPath() ) ) ), '#suffix'=>'
' ), // 'login'=>array( // '#prefix'=>'', // '#markup'=>t("Ou connectez vous en survolant l'icone du studio en bas a droite de la page"), // '#suffix'=>'
' // ), ) ) ); }else{ // TODO: check if user has permission 'use chutier' $url = Chutier::getActionsUrl($entity->id(), $user->id()); $build['chutier_actions'] = array( '#type' => 'link', '#title' => 'Chutier', '#url' => $url, '#options'=>array( 'attributes' => array( 'data-drupal-link-system-path' => $url->getInternalPath() ) ) ); } } }