Exemplo n.º 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);
 }
Exemplo n.º 2
0
 /**
  * Generates HTML for export when invoked by book_export().
  *
  * The given node is embedded to its absolute depth in a top level section. For
  * example, a child node with depth 2 in the hierarchy is contained in
  * (otherwise empty) <div> elements corresponding to depth 0 and depth 1.
  * This is intended to support WYSIWYG output - e.g., level 3 sections always
  * look like level 3 sections, no matter their depth relative to the node
  * selected to be exported as printer-friendly HTML.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node to export.
  *
  * @throws \Exception
  *   Thrown when the node was not attached to a book.
  *
  * @return array
  *   A render array representing the HTML for a node and its children in the
  *   book hierarchy.
  */
 public function bookExportHtml(NodeInterface $node)
 {
     if (!isset($node->book)) {
         throw new \Exception();
     }
     $tree = $this->bookManager->bookSubtreeData($node->book);
     $contents = $this->exportTraverse($tree, array($this, 'bookNodeExport'));
     return array('#theme' => 'book_export_html', '#title' => $node->label(), '#contents' => $contents, '#depth' => $node->book['depth'], '#cache' => ['tags' => $node->getEntityType()->getListCacheTags()]);
 }
Exemplo n.º 3
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()]);
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, array &$form_state)
 {
     if ($this->bookManager->checkNodeIsRemovable($this->node)) {
         $this->bookManager->deleteFromBook($this->node->id());
         drupal_set_message($this->t('The post has been removed from the book.'));
     }
     $form_state['redirect_route'] = $this->getCancelRoute();
 }
Exemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     if ($this->bookManager->checkNodeIsRemovable($this->node)) {
         $this->bookManager->deleteFromBook($this->node->id());
         drupal_set_message($this->t('The post has been removed from the book.'));
     }
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
Exemplo n.º 6
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);
 }
 /**
  * {@inheritdoc}
  */
 public function getCacheKeys()
 {
     // Add a key for the active book trail.
     $current_bid = 0;
     if ($node = $this->requestStack->getCurrentRequest()->get('node')) {
         $current_bid = empty($node->book['bid']) ? 0 : $node->book['bid'];
     }
     if ($current_bid === 0) {
         return parent::getCacheKeys();
     }
     $active_trail = $this->bookManager->getActiveTrailIds($node->book['bid'], $node->book);
     $active_trail_key = 'trail.' . implode('|', $active_trail);
     return array_merge(parent::getCacheKeys(), array($active_trail_key));
 }
 /**
  * Builds the table portion of the form for the book administration page.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node of the top-level page in the book.
  * @param array $form
  *   The form that is being modified, passed by reference.
  *
  * @see self::buildForm()
  */
 protected function bookAdminTable(NodeInterface $node, array &$form)
 {
     $form['table'] = array('#theme' => 'book_admin_table', '#tree' => TRUE);
     $tree = $this->bookManager->bookSubtreeData($node->book);
     // Do not include the book item itself.
     $tree = array_shift($tree);
     if ($tree['below']) {
         $hash = Crypt::hashBase64(serialize($tree['below']));
         // Store the hash value as a hidden form element so that we can detect
         // if another user changed the book hierarchy.
         $form['tree_hash'] = array('#type' => 'hidden', '#default_value' => $hash);
         $form['tree_current_hash'] = array('#type' => 'value', '#value' => $hash);
         $this->bookAdminTableTree($tree['below'], $form['table']);
     }
 }
Exemplo n.º 9
0
 /**
  * Builds the table portion of the form for the book administration page.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node of the top-level page in the book.
  * @param array $form
  *   The form that is being modified, passed by reference.
  *
  * @see self::buildForm()
  */
 protected function bookAdminTable(NodeInterface $node, array &$form)
 {
     $form['table'] = array('#type' => 'table', '#header' => [$this->t('Title'), $this->t('Weight'), $this->t('Parent'), $this->t('Operations')], '#empty' => $this->t('No book content available.'), '#tabledrag' => [['action' => 'match', 'relationship' => 'parent', 'group' => 'book-pid', 'subgroup' => 'book-pid', 'source' => 'book-nid', 'hidden' => TRUE, 'limit' => BookManager::BOOK_MAX_DEPTH - 2], ['action' => 'order', 'relationship' => 'sibling', 'group' => 'book-weight']]);
     $tree = $this->bookManager->bookSubtreeData($node->book);
     // Do not include the book item itself.
     $tree = array_shift($tree);
     if ($tree['below']) {
         $hash = Crypt::hashBase64(serialize($tree['below']));
         // Store the hash value as a hidden form element so that we can detect
         // if another user changed the book hierarchy.
         $form['tree_hash'] = array('#type' => 'hidden', '#default_value' => $hash);
         $form['tree_current_hash'] = array('#type' => 'value', '#value' => $hash);
         $this->bookAdminTableTree($tree['below'], $form['table']);
     }
 }
Exemplo n.º 10
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();
 }
Exemplo n.º 11
0
 /**
  * Formats the book links for the child pages of the current page.
  *
  * @param array $book_link
  *   A fully loaded book link that is part of the book hierarchy.
  *
  * @return array
  *   HTML for the links to the child pages of the current page.
  */
 public function childrenLinks(array $book_link)
 {
     $flat = $this->bookManager->bookTreeGetFlat($book_link);
     $children = array();
     if ($book_link['has_children']) {
         // Walk through the array until we find the current page.
         do {
             $link = array_shift($flat);
         } while ($link && $link['nid'] != $book_link['nid']);
         // Continue though the array and collect the links whose parent is this page.
         while (($link = array_shift($flat)) && $link['pid'] == $book_link['nid']) {
             $data['link'] = $link;
             $data['below'] = '';
             $children[] = $data;
         }
     }
     if ($children) {
         return $this->bookManager->bookTreeOutput($children);
     }
     return '';
 }
Exemplo n.º 12
0
 /**
  * {@inheritdoc}
  */
 public function save(array $form, FormStateInterface $form_state)
 {
     $form_state->setRedirect('entity.node.canonical', array('node' => $this->entity->id()));
     $book_link = $form_state->getValue('book');
     if (!$book_link['bid']) {
         drupal_set_message($this->t('No changes were made'));
         return;
     }
     $this->entity->book = $book_link;
     if ($this->bookManager->updateOutline($this->entity)) {
         if (isset($this->entity->book['parent_mismatch']) && $this->entity->book['parent_mismatch']) {
             // This will usually only happen when JS is disabled.
             drupal_set_message($this->t('The post has been added to the selected book. You may now position it relative to other pages.'));
             $form_state->setRedirectUrl($this->entity->urlInfo('book-outline-form'));
         } else {
             drupal_set_message($this->t('The book outline has been updated.'));
         }
     } else {
         drupal_set_message($this->t('There was an error adding the post to the book.'), 'error');
     }
 }
Exemplo n.º 13
0
 /**
  * {@inheritdoc}
  *
  * @see book_remove_button_submit()
  */
 public function submit(array $form, array &$form_state)
 {
     $form_state['redirect_route'] = array('route_name' => 'node.view', 'route_parameters' => array('node' => $this->entity->id()));
     $book_link = $form_state['values']['book'];
     if (!$book_link['bid']) {
         drupal_set_message($this->t('No changes were made'));
         return;
     }
     $this->entity->book = $book_link;
     if ($this->bookManager->updateOutline($this->entity)) {
         if (isset($this->entity->book['parent_mismatch']) && $this->entity->book['parent_mismatch']) {
             // This will usually only happen when JS is disabled.
             drupal_set_message($this->t('The post has been added to the selected book. You may now position it relative to other pages.'));
             $form_state['redirect_route'] = $this->entity->urlInfo('book-outline-form');
         } else {
             drupal_set_message($this->t('The book outline has been updated.'));
         }
     } else {
         drupal_set_message($this->t('There was an error adding the post to the book.'), 'error');
     }
 }
 /**
  * Checks access for removing the node from its book.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node requested to be removed from its book.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(NodeInterface $node)
 {
     return AccessResult::allowedIf($this->bookManager->checkNodeIsRemovable($node))->addCacheableDependency($node);
 }
 /**
  * Checks access for removing the node from its book.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node requested to be removed from its book.
  *
  * @return \Drupal\Core\Access\AccessResultInterface
  *   The access result.
  */
 public function access(NodeInterface $node)
 {
     return AccessResult::allowedIf($this->bookManager->checkNodeIsRemovable($node))->cacheUntilEntityChanges($node);
 }
 /**
  * Checks access for removing the node from its book.
  *
  * @param \Drupal\node\NodeInterface $node
  *   The node requested to be removed from its book.
  *
  * @return string
  *   A \Drupal\Core\Access\AccessInterface constant value.
  */
 public function access(NodeInterface $node)
 {
     return $this->bookManager->checkNodeIsRemovable($node) ? static::ALLOW : static::DENY;
 }