slides_presentation-8.x-1.x-dev/slides_presentation.module
slides_presentation.module
<?php /** * @file * Contains slides_presentation.module.. * @author Marouan Hammami mh.marouan@gmail.com */ use Drupal\Core\Url; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Routing\RouteMatchInterface; /** * Implements hook_help(). */ function slides_presentation_help($route_name, RouteMatchInterface $route_match) { switch ($route_name) { // Main module help for the slides_presentation module. case 'help.page.slides_presentation': $output = ''; $output .= '<h3>' . t('About') . '</h3>'; $output .= '<p>' . t('Editor tools for easily creating beautiful presentations using HTML') . '</p>'; return $output; default: } } /** * Implements hook_theme(). */ function slides_presentation_theme($existing, $type, $theme, $path) { $theme = []; $theme['page__slides'] = [ 'template' => 'page--slides', 'variables' => ['title' => NULL, 'slides' => NULL], ]; return $theme; } /** * Implements hook_page_attachments(). */ function slides_presentation_page_attachments(array &$page) { $route_name = \Drupal::service('current_route_match')->getRouteName(); if ($route_name == 'slides_presentation_content') { $page['#attached']['library'][] = 'slides_presentation/integration'; } } /** * Implements hook_theme_registry_alter(). */ function slides_presentation_theme_registry_alter(&$theme_registry) { $theme_registry['sitemap']['path'] = drupal_get_path('module', 'slides_presentation') . '/templates'; } /** * Implements hook_entity_operation(). */ function slides_presentation_entity_operation(EntityInterface $entity) { $route_name = \Drupal::service('current_route_match')->getRouteName(); if ($route_name == 'entity.slides_presentation.collection') { $operations = []; $operations['view_slide'] = [ 'title' => t('display'), 'url' => Url::fromRoute('slides_presentation_content', ['id_presentation' => $entity->id()]), 'weight' => 50, ]; return $operations; } } /** * Prepares variables for Presentation templates. * * Default template: page--slide.html.twig. * * @param array $variables * An associative array containing: * - elements: An associative array containing the user information and any * - attributes: HTML attributes for the containing element. */ function template_preprocess_page__slides(array &$variables) { $route_match = \Drupal::service('current_route_match'); $id_presentation = $route_match->getParameter('id_presentation'); $nids_slides = \Drupal::entityQuery('slides_slide') ->condition('presentation_id', $id_presentation) ->condition('status', 1) ->execute(); $slides = \Drupal::entityTypeManager() ->getStorage('slides_slide') ->loadMultiple($nids_slides); $variables['content'] = []; $variables['slides'] = $slides; } /** * Implements hook_libraries_info(). */ function slides_presentation_libraries_info() { $libraries['reveal'] = [ 'name' => 'reveal', 'vendor url' => 'http://lab.hakim.se/reveal-js/', 'download url' => 'https://github.com/hakimel/reveal.js', 'files' => [ 'js' => [ 'lib/js/head.min.js', 'js/reveal.js', ], 'css' => [ 'css/reveal.css', 'css/theme/black.css', 'lib/css/zenburn.css', ], ], ]; return $libraries; } /** * Implements slides_presentation_libraries_info_alter(). */ function slides_presentation_libraries_info_alter(&$libraries) { var_dump($libraries); $library_path = libraries_get_path('reveal'); if (isset($libraries['reveal'])) { $libraries['reveal']['files']['js'] = [ $library_path . '/js/reveal.js', ]; } }