예제 #1
0
 /**
  * Prints a listing of all books.
  *
  * @return array
  *   A render array representing the listing of all books content.
  */
 public function bookRender()
 {
     $book_list = array();
     foreach ($this->bookManager->getAllBooks() as $book) {
         $book_list[] = l($book['title'], $book['link_path']);
     }
     return array('#theme' => 'item_list', '#items' => $book_list);
 }
예제 #2
0
 /**
  * Prints a listing of all books.
  *
  * @return array
  *   A render array representing the listing of all books content.
  */
 public function bookRender()
 {
     $book_list = array();
     foreach ($this->bookManager->getAllBooks() as $book) {
         $book_list[] = $this->l($book['title'], $book['url']);
     }
     return array('#theme' => 'item_list', '#items' => $book_list, '#cache' => ['tags' => \Drupal::entityManager()->getDefinition('node')->getListCacheTags()]);
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function buildForm(array $form, FormStateInterface $form_state)
 {
     $config = $this->configFactory->get('sitemap.settings');
     $form['page_title'] = array('#type' => 'textfield', '#title' => $this->t('Page title'), '#default_value' => $config->get('page_title'), '#description' => $this->t('Page title that will be used on the @sitemap_page.', array('@sitemap_page' => $this->l($this->t('sitemap page'), Url::fromRoute('sitemap.page')))));
     $sitemap_message = $config->get('message');
     $form['message'] = array('#type' => 'text_format', '#format' => isset($sitemap_message['format']) ? $sitemap_message['format'] : NULL, '#title' => $this->t('Sitemap message'), '#default_value' => $sitemap_message['value'], '#description' => $this->t('Define a message to be displayed above the sitemap.'));
     $form['sitemap_content'] = array('#type' => 'details', '#title' => $this->t('Sitemap content'), '#open' => TRUE);
     $sitemap_ordering = array();
     $form['sitemap_content']['show_front'] = array('#type' => 'checkbox', '#title' => $this->t('Show front page'), '#default_value' => $config->get('show_front'), '#description' => $this->t('When enabled, this option will include the front page in the sitemap.'));
     $sitemap_ordering['front'] = t('Front page');
     $form['sitemap_content']['show_titles'] = array('#type' => 'checkbox', '#title' => $this->t('Show titles'), '#default_value' => $config->get('show_titles'), '#description' => $this->t('When enabled, this option will show titles. Disable to not show section titles.'));
     if ($this->moduleHandler->moduleExists('book')) {
         $book_options = array();
         foreach ($this->bookManager->getAllBooks() as $book) {
             $book_options[$book['bid']] = $book['title'];
         }
         $form['sitemap_content']['show_books'] = array('#type' => 'checkboxes', '#title' => $this->t('Books to include in the sitemap'), '#default_value' => $config->get('show_books'), '#options' => $book_options, '#multiple' => TRUE);
         $form['sitemap_content']['books_expanded'] = array('#type' => 'checkbox', '#title' => $this->t('Show books expanded'), '#default_value' => $config->get('books_expanded'), '#description' => $this->t('When enabled, this option will show all children pages for each book.'));
         $sitemap_ordering['books'] = t('Books');
     }
     $menu_options = array();
     $menus = Menu::loadMultiple();
     foreach ($menus as $id => $menu) {
         $menu_options[$id] = $menu->label();
         $sitemap_ordering['menus_' . $id] = $menu->label();
     }
     $form['sitemap_content']['show_menus'] = array('#type' => 'checkboxes', '#title' => $this->t('Menus to include in the sitemap'), '#default_value' => $config->get('show_menus'), '#options' => $menu_options);
     $form['sitemap_content']['show_menus_hidden'] = array('#type' => 'checkbox', '#title' => $this->t('Show disabled menu items'), '#default_value' => $config->get('show_menus_hidden'), '#description' => $this->t('When enabled, hidden menu links will also be shown.'));
     if ($this->moduleHandler->moduleExists('taxonomy')) {
         $vocab_options = array();
         foreach (taxonomy_vocabulary_load_multiple() as $vocabulary) {
             $vocab_options[$vocabulary->id()] = $vocabulary->label();
             $sitemap_ordering['vocabularies_' . $vocabulary->id()] = $vocabulary->label();
         }
         $form['sitemap_content']['show_vocabularies'] = array('#type' => 'checkboxes', '#title' => $this->t('Vocabularies to include in the sitemap'), '#default_value' => $config->get('show_vocabularies'), '#options' => $vocab_options, '#multiple' => TRUE);
     }
     $form['sitemap_content']['order'] = array('#type' => 'item', '#title' => t('Sitemap order'), '#theme' => 'sitemap_order');
     $sitemap_order_defaults = $config->get('order');
     foreach ($sitemap_ordering as $content_id => $content_title) {
         $form['sitemap_content']['order'][$content_id] = array('content' => array('#markup' => $content_title), 'weight' => array('#type' => 'weight', '#title' => t('Weight for @title', array('@title' => $content_title)), '#title_display' => 'invisible', '#delta' => 50, '#default_value' => isset($sitemap_order_defaults[$content_id]) ? $sitemap_order_defaults[$content_id] : -50, '#parents' => array('order', $content_id)), '#weight' => isset($sitemap_order_defaults[$content_id]) ? $sitemap_order_defaults[$content_id] : -50);
     }
     $form['sitemap_taxonomy_options'] = array('#type' => 'details', '#title' => $this->t('Taxonomy settings'));
     $form['sitemap_taxonomy_options']['show_description'] = array('#type' => 'checkbox', '#title' => $this->t('Show vocabulary description'), '#default_value' => $config->get('show_description'), '#description' => $this->t('When enabled, this option will show the vocabulary description.'));
     $form['sitemap_taxonomy_options']['show_count'] = array('#type' => 'checkbox', '#title' => $this->t('Show node counts by taxonomy terms'), '#default_value' => $config->get('show_count'), '#description' => $this->t('When enabled, this option will show the number of nodes in each taxonomy term.'));
     $form['sitemap_taxonomy_options']['vocabulary_depth'] = array('#type' => 'textfield', '#title' => $this->t('Vocabulary depth'), '#default_value' => $config->get('vocabulary_depth'), '#size' => 3, '#maxlength' => 10, '#description' => $this->t('Specify how many levels taxonomy terms should be included. Enter "-1" to include all terms, "0" not to include terms at all, or "1" to only include top-level terms.'));
     $form['sitemap_taxonomy_options']['term_threshold'] = array('#type' => 'textfield', '#title' => $this->t('Term count threshold'), '#default_value' => $config->get('term_threshold'), '#size' => 3, '#description' => $this->t('Only show taxonomy terms whose node counts are greater than this threshold. Set to -1 to disable.'));
     if ($this->moduleHandler->moduleExists('forum')) {
         $form['sitemap_taxonomy_options']['forum_threshold'] = array('#type' => 'textfield', '#title' => $this->t('Forum count threshold'), '#default_value' => $config->get('forum_threshold'), '#size' => 3, '#description' => $this->t('Only show forums whose node counts are greater than this threshold. Set to -1 to disable.'));
     }
     $form['sitemap_rss_options'] = array('#type' => 'details', '#title' => $this->t('RSS settings'));
     $form['sitemap_rss_options']['rss_front'] = array('#type' => 'textfield', '#title' => $this->t('RSS feed for front page'), '#default_value' => $config->get('rss_front'), '#description' => $this->t('The RSS feed for the front page, default is rss.xml.'));
     $form['sitemap_rss_options']['show_rss_links'] = array('#type' => 'select', '#title' => $this->t('Include RSS links'), '#default_value' => $config->get('show_rss_links'), '#options' => array(0 => $this->t('None'), 1 => $this->t('Include on the right side'), 2 => $this->t('Include on the left side')), '#description' => $this->t('When enabled, this option will show links to the RSS feeds for the front page and taxonomy terms, if enabled.'));
     $form['sitemap_rss_options']['rss_taxonomy'] = array('#type' => 'textfield', '#title' => $this->t('RSS depth for vocabularies'), '#default_value' => $config->get('rss_taxonomy'), '#size' => 3, '#maxlength' => 10, '#description' => $this->t('Specify how many RSS feed links should be displayed with taxonomy terms. Enter "-1" to include with all terms, "0" not to include with any terms, or "1" to show only for top-level taxonomy terms.'));
     $form['sitemap_css_options'] = array('#type' => 'details', '#title' => $this->t('CSS settings'));
     $form['sitemap_css_options']['css'] = array('#type' => 'checkbox', '#title' => $this->t('Do not include sitemap CSS file'), '#default_value' => $config->get('css'), '#description' => $this->t("If you don't want to load the included CSS file you can check this box. To learn how to override or specify the CSS at the theme level, visit the @documentation_page.", array('@documentation_page' => $this->l($this->t("documentation page"), Url::fromUri('https://www.drupal.org/node/2615568')))));
     return parent::buildForm($form, $form_state);
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $current_bid = 0;
     if ($node = $this->requestStack->getCurrentRequest()->get('node')) {
         $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
     }
     if ($this->configuration['block_mode'] == 'all pages') {
         $book_menus = array();
         $pseudo_tree = array(0 => array('below' => FALSE));
         foreach ($this->bookManager->getAllBooks() as $book_id => $book) {
             if ($book['bid'] == $current_bid) {
                 // If the current page is a node associated with a book, the menu
                 // needs to be retrieved.
                 $data = $this->bookManager->bookTreeAllData($node->book['bid'], $node->book);
                 $book_menus[$book_id] = $this->bookManager->bookTreeOutput($data);
             } else {
                 // Since we know we will only display a link to the top node, there
                 // is no reason to run an additional menu tree query for each book.
                 $book['in_active_trail'] = FALSE;
                 // Check whether user can access the book link.
                 $book_node = $this->nodeStorage->load($book['nid']);
                 $book['access'] = $book_node->access('view');
                 $pseudo_tree[0]['link'] = $book;
                 $book_menus[$book_id] = $this->bookManager->bookTreeOutput($pseudo_tree);
             }
             $book_menus[$book_id] += array('#book_title' => $book['title']);
         }
         if ($book_menus) {
             return array('#theme' => 'book_all_books_block') + $book_menus;
         }
     } elseif ($current_bid) {
         // Only display this block when the user is browsing a book.
         $query = \Drupal::entityQuery('node');
         $nid = $query->condition('nid', $node->book['bid'], '=')->execute();
         // Only show the block if the user has view access for the top-level node.
         if ($nid) {
             $tree = $this->bookManager->bookTreeAllData($node->book['bid'], $node->book);
             // There should only be one element at the top level.
             $data = array_shift($tree);
             $below = $this->bookManager->bookTreeOutput($data['below']);
             if (!empty($below)) {
                 return $below;
             }
         }
     }
     return array();
 }