' . 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'; } /** * 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); if($user->id() == 0){ // // TODO: check if user loged in ? yes -> links : no : popup message // $action = 'add'; } // else{ // // TODO: check if node already in chutier ? no -> add link : yes -> remove link // // use getUserChutiersContents() from \Drupal\edlp_studio\ChutierInterface // $contents = Chutier::getUserChutiersContents($user->id()); // dpm($contents); // if(array_search($entity->id(), $contents) === false){ // $action = 'add'; // }else{ // $action = 'remove'; // } // } // $args = array( // 'action'=>$action, // 'id'=>$entity->id() // ); // $url = Url::fromRoute('edlp_studio.chutier_controller_ajax_add_content', $args, array( // 'attributes' => array( // 'class' => ['chutier-link','chutier-ajax-link'], // 'action' => $action, // 'target_id' => $entity->id(), // ) // )); $url = Chutier::getActionsUrl($entity->id(), $user->id()); $build['chutier_actions'] = array( '#title' => t("Chutier."), '#type' => 'link', '#url' => $url, '#options'=>array( 'attributes' => array( 'data-drupal-link-system-path' => $url->getInternalPath() ) ) ); } }