updated core and modules

This commit is contained in:
Bachir Soussi Chiadmi
2017-09-09 16:27:51 +02:00
parent 027aa99b32
commit 41863f872c
7810 changed files with 318922 additions and 83631 deletions
@@ -56,10 +56,10 @@ class BookBreadcrumbBuilder implements BreadcrumbBuilderInterface {
* {@inheritdoc}
*/
public function build(RouteMatchInterface $route_match) {
$book_nids = array();
$book_nids = [];
$breadcrumb = new Breadcrumb();
$links = array(Link::createFromRoute($this->t('Home'), '<front>'));
$links = [Link::createFromRoute($this->t('Home'), '<front>')];
$book = $route_match->getParameter('node')->book;
$depth = 1;
// We skip the current node.
@@ -76,7 +76,7 @@ class BookBreadcrumbBuilder implements BreadcrumbBuilderInterface {
$breadcrumb->addCacheableDependency($access);
if ($access->isAllowed()) {
$breadcrumb->addCacheableDependency($parent_book);
$links[] = Link::createFromRoute($parent_book->label(), 'entity.node.canonical', array('node' => $parent_book->id()));
$links[] = Link::createFromRoute($parent_book->label(), 'entity.node.canonical', ['node' => $parent_book->id()]);
}
}
$depth++;
+7 -7
View File
@@ -73,8 +73,8 @@ class BookExport {
}
$tree = $this->bookManager->bookSubtreeData($node->book);
$contents = $this->exportTraverse($tree, array($this, 'bookNodeExport'));
return array(
$contents = $this->exportTraverse($tree, [$this, 'bookNodeExport']);
return [
'#theme' => 'book_export_html',
'#title' => $node->label(),
'#contents' => $contents,
@@ -82,7 +82,7 @@ class BookExport {
'#cache' => [
'tags' => $node->getEntityType()->getListCacheTags(),
],
);
];
}
/**
@@ -101,9 +101,9 @@ class BookExport {
*/
protected function exportTraverse(array $tree, $callable) {
// If there is no valid callable, use the default callback.
$callable = !empty($callable) ? $callable : array($this, 'bookNodeExport');
$callable = !empty($callable) ? $callable : [$this, 'bookNodeExport'];
$build = array();
$build = [];
foreach ($tree as $data) {
// Note- access checking is already performed when building the tree.
if ($node = $this->nodeStorage->load($data['link']['nid'])) {
@@ -133,12 +133,12 @@ class BookExport {
$build = $this->viewBuilder->view($node, 'print', NULL);
unset($build['#theme']);
return array(
return [
'#theme' => 'book_node_export_html',
'#content' => $build,
'#node' => $node,
'#children' => $children,
);
];
}
}
+77 -77
View File
@@ -92,7 +92,7 @@ class BookManager implements BookManagerInterface {
* Loads Books Array.
*/
protected function loadBooks() {
$this->books = array();
$this->books = [];
$nids = $this->bookOutlineStorage->getBooks();
if ($nids) {
@@ -117,15 +117,15 @@ class BookManager implements BookManagerInterface {
* {@inheritdoc}
*/
public function getLinkDefaults($nid) {
return array(
return [
'original_bid' => 0,
'nid' => $nid,
'bid' => 0,
'pid' => 0,
'has_children' => 0,
'weight' => 0,
'options' => array(),
);
'options' => [],
];
}
/**
@@ -138,7 +138,7 @@ class BookManager implements BookManagerInterface {
/**
* Determine the relative depth of the children of a given book link.
*
* @param array
* @param array $book_link
* The book link.
*
* @return int
@@ -159,40 +159,40 @@ class BookManager implements BookManagerInterface {
if ($form_state->hasValue('book')) {
$node->book = $form_state->getValue('book');
}
$form['book'] = array(
$form['book'] = [
'#type' => 'details',
'#title' => $this->t('Book outline'),
'#weight' => 10,
'#open' => !$collapsed,
'#group' => 'advanced',
'#attributes' => array(
'class' => array('book-outline-form'),
),
'#attached' => array(
'library' => array('book/drupal.book'),
),
'#attributes' => [
'class' => ['book-outline-form'],
],
'#attached' => [
'library' => ['book/drupal.book'],
],
'#tree' => TRUE,
);
foreach (array('nid', 'has_children', 'original_bid', 'parent_depth_limit') as $key) {
$form['book'][$key] = array(
];
foreach (['nid', 'has_children', 'original_bid', 'parent_depth_limit'] as $key) {
$form['book'][$key] = [
'#type' => 'value',
'#value' => $node->book[$key],
);
];
}
$form['book']['pid'] = $this->addParentSelectFormElements($node->book);
// @see \Drupal\book\Form\BookAdminEditForm::bookAdminTableTree(). The
// weight may be larger than 15.
$form['book']['weight'] = array(
$form['book']['weight'] = [
'#type' => 'weight',
'#title' => $this->t('Weight'),
'#default_value' => $node->book['weight'],
'#delta' => max(15, abs($node->book['weight'])),
'#weight' => 5,
'#description' => $this->t('Pages at a given level are ordered first by weight and then by title.'),
);
$options = array();
];
$options = [];
$nid = !$node->isNew() ? $node->id() : 'new';
if ($node->id() && ($nid == $node->book['original_bid']) && ($node->book['parent_depth_limit'] == 0)) {
// This is the top level node in a maximum depth book and thus cannot be
@@ -207,15 +207,15 @@ class BookManager implements BookManagerInterface {
if ($account->hasPermission('create new books') && ($nid == 'new' || ($nid != $node->book['original_bid']))) {
// The node can become a new book, if it is not one already.
$options = array($nid => $this->t('- Create a new book -')) + $options;
$options = [$nid => $this->t('- Create a new book -')] + $options;
}
if (!$node->book['bid']) {
// The node is not currently in the hierarchy.
$options = array(0 => $this->t('- None -')) + $options;
$options = [0 => $this->t('- None -')] + $options;
}
// Add a drop-down to select the destination book.
$form['book']['bid'] = array(
$form['book']['bid'] = [
'#type' => 'select',
'#title' => $this->t('Book'),
'#default_value' => $node->book['bid'],
@@ -223,14 +223,14 @@ class BookManager implements BookManagerInterface {
'#access' => (bool) $options,
'#description' => $this->t('Your page will be a part of the selected book.'),
'#weight' => -5,
'#attributes' => array('class' => array('book-title-select')),
'#ajax' => array(
'#attributes' => ['class' => ['book-title-select']],
'#ajax' => [
'callback' => 'book_form_update',
'wrapper' => 'edit-book-plid-wrapper',
'effect' => 'fade',
'speed' => 'fast',
),
);
],
];
return $form;
}
@@ -281,8 +281,8 @@ class BookManager implements BookManagerInterface {
/**
* {@inheritdoc}
*/
public function getBookParents(array $item, array $parent = array()) {
$book = array();
public function getBookParents(array $item, array $parent = []) {
$book = [];
if ($item['pid'] == 0) {
$book['p1'] = $item['nid'];
for ($i = 2; $i <= static::BOOK_MAX_DEPTH; $i++) {
@@ -325,15 +325,15 @@ class BookManager implements BookManagerInterface {
protected function addParentSelectFormElements(array $book_link) {
$config = $this->configFactory->get('book.settings');
if ($config->get('override_parent_selector')) {
return array();
return [];
}
// Offer a message or a drop-down to choose a different parent page.
$form = array(
$form = [
'#type' => 'hidden',
'#value' => -1,
'#prefix' => '<div id="edit-book-plid-wrapper">',
'#suffix' => '</div>',
);
];
if ($book_link['nid'] === $book_link['bid']) {
// This is a book - at the top level.
@@ -348,16 +348,16 @@ class BookManager implements BookManagerInterface {
$form['#prefix'] .= '<em>' . $this->t('No book selected.') . '</em>';
}
else {
$form = array(
$form = [
'#type' => 'select',
'#title' => $this->t('Parent item'),
'#default_value' => $book_link['pid'],
'#description' => $this->t('The parent page in the book. The maximum depth for a book and all child pages is @maxdepth. Some pages in the selected book may not be available as parents if selecting them would exceed this limit.', array('@maxdepth' => static::BOOK_MAX_DEPTH)),
'#options' => $this->getTableOfContents($book_link['bid'], $book_link['parent_depth_limit'], array($book_link['nid'])),
'#attributes' => array('class' => array('book-title-select')),
'#description' => $this->t('The parent page in the book. The maximum depth for a book and all child pages is @maxdepth. Some pages in the selected book may not be available as parents if selecting them would exceed this limit.', ['@maxdepth' => static::BOOK_MAX_DEPTH]),
'#options' => $this->getTableOfContents($book_link['bid'], $book_link['parent_depth_limit'], [$book_link['nid']]),
'#attributes' => ['class' => ['book-title-select']],
'#prefix' => '<div id="edit-book-plid-wrapper">',
'#suffix' => '</div>',
);
];
}
$this->renderer->addCacheableDependency($form, $config);
@@ -388,7 +388,7 @@ class BookManager implements BookManagerInterface {
* children).
*/
protected function recurseTableOfContents(array $tree, $indent, array &$toc, array $exclude, $depth_limit) {
$nids = array();
$nids = [];
foreach ($tree as $data) {
if ($data['link']['depth'] > $depth_limit) {
// Don't iterate through any links on this level.
@@ -417,9 +417,9 @@ class BookManager implements BookManagerInterface {
/**
* {@inheritdoc}
*/
public function getTableOfContents($bid, $depth_limit, array $exclude = array()) {
public function getTableOfContents($bid, $depth_limit, array $exclude = []) {
$tree = $this->bookTreeAllData($bid);
$toc = array();
$toc = [];
$this->recurseTableOfContents($tree, '', $toc, $exclude, $depth_limit);
return $toc;
@@ -443,14 +443,14 @@ class BookManager implements BookManagerInterface {
}
$this->updateOriginalParent($original);
$this->books = NULL;
Cache::invalidateTags(array('bid:' . $original['bid']));
Cache::invalidateTags(['bid:' . $original['bid']]);
}
/**
* {@inheritdoc}
*/
public function bookTreeAllData($bid, $link = NULL, $max_depth = NULL) {
$tree = &drupal_static(__METHOD__, array());
$tree = &drupal_static(__METHOD__, []);
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
// Use $nid as a flag for whether the data being loaded is for the whole
@@ -462,10 +462,10 @@ class BookManager implements BookManagerInterface {
if (!isset($tree[$cid])) {
// If the tree data was not in the static cache, build $tree_parameters.
$tree_parameters = array(
$tree_parameters = [
'min_depth' => 1,
'max_depth' => $max_depth,
);
];
if ($nid) {
$active_trail = $this->getActiveTrailIds($bid, $link);
$tree_parameters['expanded'] = $active_trail;
@@ -486,7 +486,7 @@ class BookManager implements BookManagerInterface {
public function getActiveTrailIds($bid, $link) {
// The tree is for a single item, so we need to match the values in its
// p columns and 0 (the top level) with the plid values of other links.
$active_trail = array(0);
$active_trail = [0];
for ($i = 1; $i < static::BOOK_MAX_DEPTH; $i++) {
if (!empty($link["p$i"])) {
$active_trail[] = $link["p$i"];
@@ -600,7 +600,7 @@ class BookManager implements BookManagerInterface {
* @return array
* A fully built book tree.
*/
protected function bookTreeBuild($bid, array $parameters = array()) {
protected function bookTreeBuild($bid, array $parameters = []) {
// Build the book tree.
$data = $this->doBookTreeBuild($bid, $parameters);
// Check access for the current user to each item in the tree.
@@ -639,9 +639,9 @@ class BookManager implements BookManagerInterface {
*
* @see \Drupal\book\BookOutlineStorageInterface::getBookMenuTree()
*/
protected function doBookTreeBuild($bid, array $parameters = array()) {
protected function doBookTreeBuild($bid, array $parameters = []) {
// Static cache of already built menu trees.
$trees = &drupal_static(__METHOD__, array());
$trees = &drupal_static(__METHOD__, []);
$language_interface = \Drupal::languageManager()->getCurrentLanguage();
// Build the cache id; sort parents to prevent duplicate storage and remove
@@ -664,18 +664,18 @@ class BookManager implements BookManagerInterface {
$result = $this->bookOutlineStorage->getBookMenuTree($bid, $parameters, $min_depth, static::BOOK_MAX_DEPTH);
// Build an ordered array of links using the query result object.
$links = array();
$links = [];
foreach ($result as $link) {
$link = (array) $link;
$links[$link['nid']] = $link;
}
$active_trail = (isset($parameters['active_trail']) ? $parameters['active_trail'] : array());
$active_trail = (isset($parameters['active_trail']) ? $parameters['active_trail'] : []);
$data['tree'] = $this->buildBookOutlineData($links, $active_trail, $min_depth);
$data['node_links'] = array();
$data['node_links'] = [];
$this->bookTreeCollectNodeLinks($data['tree'], $data['node_links']);
// Cache the data, if it is not already in the cache.
\Drupal::cache('data')->set($tree_cid, $data, Cache::PERMANENT, array('bid:' . $bid));
\Drupal::cache('data')->set($tree_cid, $data, Cache::PERMANENT, ['bid:' . $bid]);
$trees[$tree_cid] = $data;
}
@@ -705,7 +705,7 @@ class BookManager implements BookManagerInterface {
if (!isset($this->bookTreeFlattened[$book_link['nid']])) {
// Call $this->bookTreeAllData() to take advantage of caching.
$tree = $this->bookTreeAllData($book_link['bid'], $book_link, $book_link['depth'] + 1);
$this->bookTreeFlattened[$book_link['nid']] = array();
$this->bookTreeFlattened[$book_link['nid']] = [];
$this->flatBookTree($tree, $this->bookTreeFlattened[$book_link['nid']]);
}
@@ -735,7 +735,7 @@ class BookManager implements BookManagerInterface {
* {@inheritdoc}
*/
public function loadBookLink($nid, $translate = TRUE) {
$links = $this->loadBookLinks(array($nid), $translate);
$links = $this->loadBookLinks([$nid], $translate);
return isset($links[$nid]) ? $links[$nid] : FALSE;
}
@@ -744,7 +744,7 @@ class BookManager implements BookManagerInterface {
*/
public function loadBookLinks($nids, $translate = TRUE) {
$result = $this->bookOutlineStorage->loadMultiple($nids, $translate);
$links = array();
$links = [];
foreach ($result as $link) {
if ($translate) {
$this->bookLinkTranslate($link);
@@ -779,7 +779,7 @@ class BookManager implements BookManagerInterface {
// Update the bid for this page and all children.
if ($link['pid'] == 0) {
$link['depth'] = 1;
$parent = array();
$parent = [];
}
// In case the form did not specify a proper PID we use the BID as new
// parent.
@@ -801,11 +801,11 @@ class BookManager implements BookManagerInterface {
$this->updateParent($link);
}
// Update the weight and pid.
$this->bookOutlineStorage->update($link['nid'], array(
$this->bookOutlineStorage->update($link['nid'], [
'weight' => $link['weight'],
'pid' => $link['pid'],
'bid' => $link['bid'],
));
]);
}
$cache_tags = [];
foreach ($affected_bids as $bid) {
@@ -825,16 +825,16 @@ class BookManager implements BookManagerInterface {
*/
protected function moveChildren(array $link, array $original) {
$p = 'p1';
$expressions = array();
$expressions = [];
for ($i = 1; $i <= $link['depth']; $p = 'p' . ++$i) {
$expressions[] = array($p, ":p_$i", array(":p_$i" => $link[$p]));
$expressions[] = [$p, ":p_$i", [":p_$i" => $link[$p]]];
}
$j = $original['depth'] + 1;
while ($i <= static::BOOK_MAX_DEPTH && $j <= static::BOOK_MAX_DEPTH) {
$expressions[] = array('p' . $i++, 'p' . $j++, array());
$expressions[] = ['p' . $i++, 'p' . $j++, []];
}
while ($i <= static::BOOK_MAX_DEPTH) {
$expressions[] = array('p' . $i++, 0, array());
$expressions[] = ['p' . $i++, 0, []];
}
$shift = $link['depth'] - $original['depth'];
@@ -868,7 +868,7 @@ class BookManager implements BookManagerInterface {
// Nothing to update.
return TRUE;
}
return $this->bookOutlineStorage->update($link['pid'], array('has_children' => 1));
return $this->bookOutlineStorage->update($link['pid'], ['has_children' => 1]);
}
/**
@@ -897,7 +897,7 @@ class BookManager implements BookManagerInterface {
// Update the parent. If the original link did not have children, then the
// parent now does not have children. If the original had children, then the
// the parent has children now (still).
return $this->bookOutlineStorage->update($original['pid'], array('has_children' => $parent_has_children));
return $this->bookOutlineStorage->update($original['pid'], ['has_children' => $parent_has_children]);
}
/**
@@ -926,7 +926,7 @@ class BookManager implements BookManagerInterface {
/**
* {@inheritdoc}
*/
public function bookTreeCheckAccess(&$tree, $node_links = array()) {
public function bookTreeCheckAccess(&$tree, $node_links = []) {
if ($node_links) {
// @todo Extract that into its own method.
$nids = array_keys($node_links);
@@ -954,7 +954,7 @@ class BookManager implements BookManagerInterface {
* The book tree to operate on.
*/
protected function doBookTreeCheckAccess(&$tree) {
$new_tree = array();
$new_tree = [];
foreach ($tree as $key => $v) {
$item = &$tree[$key]['link'];
$this->bookLinkTranslate($item);
@@ -993,7 +993,7 @@ class BookManager implements BookManagerInterface {
}
// The node label will be the value for the current user's language.
$link['title'] = $node->label();
$link['options'] = array();
$link['options'] = [];
}
return $link;
}
@@ -1021,7 +1021,7 @@ class BookManager implements BookManagerInterface {
* array will be empty if the book link has no items in its sub-tree
* having a depth greater than or equal to $depth.
*/
protected function buildBookOutlineData(array $links, array $parents = array(), $depth = 1) {
protected function buildBookOutlineData(array $links, array $parents = [], $depth = 1) {
// Reverse the array so we can use the more efficient array_pop() function.
$links = array_reverse($links);
return $this->buildBookOutlineRecursive($links, $parents, $depth);
@@ -1047,16 +1047,16 @@ class BookManager implements BookManagerInterface {
* Book tree.
*/
protected function buildBookOutlineRecursive(&$links, $parents, $depth) {
$tree = array();
$tree = [];
while ($item = array_pop($links)) {
// We need to determine if we're on the path to root so we can later build
// the correct active trail.
$item['in_active_trail'] = in_array($item['nid'], $parents);
// Add the current link to the tree.
$tree[$item['nid']] = array(
$tree[$item['nid']] = [
'link' => $item,
'below' => array(),
);
'below' => [],
];
// Look ahead to the next link, but leave it on the array so it's
// available to other recursive function calls if we return or build a
// sub-tree.
@@ -1080,7 +1080,7 @@ class BookManager implements BookManagerInterface {
* {@inheritdoc}
*/
public function bookSubtreeData($link) {
$tree = &drupal_static(__METHOD__, array());
$tree = &drupal_static(__METHOD__, []);
// Generate a cache ID (cid) specific for this $link.
$cid = 'book-links:subtree-cid:' . $link['nid'];
@@ -1101,23 +1101,23 @@ class BookManager implements BookManagerInterface {
// If the subtree data was not in the cache, $data will be NULL.
if (!isset($data)) {
$result = $this->bookOutlineStorage->getBookSubtree($link, static::BOOK_MAX_DEPTH);
$links = array();
$links = [];
foreach ($result as $item) {
$links[] = $item;
}
$data['tree'] = $this->buildBookOutlineData($links, array(), $link['depth']);
$data['node_links'] = array();
$data['tree'] = $this->buildBookOutlineData($links, [], $link['depth']);
$data['node_links'] = [];
$this->bookTreeCollectNodeLinks($data['tree'], $data['node_links']);
// Compute the real cid for book subtree data.
$tree_cid = 'book-links:subtree-data:' . hash('sha256', serialize($data));
// Cache the data, if it is not already in the cache.
if (!\Drupal::cache('data')->get($tree_cid)) {
\Drupal::cache('data')->set($tree_cid, $data, Cache::PERMANENT, array('bid:' . $link['bid']));
\Drupal::cache('data')->set($tree_cid, $data, Cache::PERMANENT, ['bid:' . $link['bid']]);
}
// Cache the cid of the (shared) data using the book and item-specific
// cid.
\Drupal::cache('data')->set($cid, $tree_cid, Cache::PERMANENT, array('bid:' . $link['bid']));
\Drupal::cache('data')->set($cid, $tree_cid, Cache::PERMANENT, ['bid:' . $link['bid']]);
}
// Check access for the current user to each item in the tree.
$this->bookTreeCheckAccess($data['tree'], $data['node_links']);
@@ -108,7 +108,7 @@ interface BookManagerInterface {
* An array of (menu link ID, title) pairs for use as options for selecting
* a book page.
*/
public function getTableOfContents($bid, $depth_limit, array $exclude = array());
public function getTableOfContents($bid, $depth_limit, array $exclude = []);
/**
* Finds the depth limit for items in the parent select.
@@ -207,7 +207,7 @@ interface BookManagerInterface {
*/
public function getLinkDefaults($nid);
public function getBookParents(array $item, array $parent = array());
public function getBookParents(array $item, array $parent = []);
/**
* Builds the common elements of the book form for the node and outline forms.
@@ -262,7 +262,7 @@ interface BookManagerInterface {
* A collection of node link references generated from $tree by
* menu_tree_collect_node_links().
*/
public function bookTreeCheckAccess(&$tree, $node_links = array());
public function bookTreeCheckAccess(&$tree, $node_links = []);
/**
* Gets the data representing a subtree of the book hierarchy.
+1 -1
View File
@@ -105,7 +105,7 @@ class BookOutline {
public function childrenLinks(array $book_link) {
$flat = $this->bookManager->bookTreeGetFlat($book_link);
$children = array();
$children = [];
if ($book_link['has_children']) {
// Walk through the array until we find the current page.
+7 -7
View File
@@ -43,7 +43,7 @@ class BookOutlineStorage implements BookOutlineStorageInterface {
* {@inheritdoc}
*/
public function loadMultiple($nids, $access = TRUE) {
$query = $this->connection->select('book', 'b', array('fetch' => \PDO::FETCH_ASSOC));
$query = $this->connection->select('book', 'b', ['fetch' => \PDO::FETCH_ASSOC]);
$query->fields('b');
$query->condition('b.nid', $nids, 'IN');
@@ -89,7 +89,7 @@ class BookOutlineStorage implements BookOutlineStorageInterface {
*/
public function loadBookChildren($pid) {
return $this->connection
->query("SELECT * FROM {book} WHERE pid = :pid", array(':pid' => $pid))
->query("SELECT * FROM {book} WHERE pid = :pid", [':pid' => $pid])
->fetchAllAssoc('nid', \PDO::FETCH_ASSOC);
}
@@ -128,12 +128,12 @@ class BookOutlineStorage implements BookOutlineStorageInterface {
public function insert($link, $parents) {
return $this->connection
->insert('book')
->fields(array(
->fields([
'nid' => $link['nid'],
'bid' => $link['bid'],
'pid' => $link['pid'],
'weight' => $link['weight'],
) + $parents
] + $parents
)
->execute();
}
@@ -154,13 +154,13 @@ class BookOutlineStorage implements BookOutlineStorageInterface {
*/
public function updateMovedChildren($bid, $original, $expressions, $shift) {
$query = $this->connection->update('book');
$query->fields(array('bid' => $bid));
$query->fields(['bid' => $bid]);
foreach ($expressions as $expression) {
$query->expression($expression[0], $expression[1], $expression[2]);
}
$query->expression('depth', 'depth + :depth', array(':depth' => $shift));
$query->expression('depth', 'depth + :depth', [':depth' => $shift]);
$query->condition('bid', $original['bid']);
$p = 'p1';
for ($i = 1; !empty($original[$p]); $p = 'p' . ++$i) {
@@ -186,7 +186,7 @@ class BookOutlineStorage implements BookOutlineStorageInterface {
* {@inheritdoc}
*/
public function getBookSubtree($link, $max_depth) {
$query = db_select('book', 'b', array('fetch' => \PDO::FETCH_ASSOC));
$query = db_select('book', 'b', ['fetch' => \PDO::FETCH_ASSOC]);
$query->fields('b');
$query->condition('b.bid', $link['bid']);
@@ -2,7 +2,7 @@
namespace Drupal\book;
use Drupal\Core\Entity\Query\QueryFactory;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Extension\ModuleUninstallValidatorInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Core\StringTranslation\TranslationInterface;
@@ -23,25 +23,25 @@ class BookUninstallValidator implements ModuleUninstallValidatorInterface {
protected $bookOutlineStorage;
/**
* The entity query for node.
* The entity type manager.
*
* @var \Drupal\Core\Entity\Query\QueryInterface
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityQuery;
protected $entityTypeManager;
/**
* Constructs a new BookUninstallValidator.
*
* @param \Drupal\book\BookOutlineStorageInterface $book_outline_storage
* The book outline storage.
* @param \Drupal\Core\Entity\Query\QueryFactory $query_factory
* The entity query factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(BookOutlineStorageInterface $book_outline_storage, QueryFactory $query_factory, TranslationInterface $string_translation) {
public function __construct(BookOutlineStorageInterface $book_outline_storage, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
$this->bookOutlineStorage = $book_outline_storage;
$this->entityQuery = $query_factory->get('node');
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslation = $string_translation;
}
@@ -82,7 +82,7 @@ class BookUninstallValidator implements ModuleUninstallValidatorInterface {
* TRUE if there are book nodes, FALSE otherwise.
*/
protected function hasBookNodes() {
$nodes = $this->entityQuery
$nodes = $this->entityTypeManager->getStorage('node')->getQuery()
->condition('type', 'book')
->accessCheck(FALSE)
->range(0, 1)
@@ -4,7 +4,8 @@ namespace Drupal\book\Cache;
use Drupal\Core\Cache\CacheableMetadata;
use Drupal\Core\Cache\Context\CacheContextInterface;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\HttpFoundation\RequestStack;
/**
@@ -19,7 +20,9 @@ use Symfony\Component\HttpFoundation\RequestStack;
* This class is container-aware to avoid initializing the 'book.manager'
* service when it is not necessary.
*/
class BookNavigationCacheContext extends ContainerAware implements CacheContextInterface {
class BookNavigationCacheContext implements CacheContextInterface, ContainerAwareInterface {
use ContainerAwareTrait;
/**
* The request stack.
@@ -73,9 +73,9 @@ class BookController extends ControllerBase {
* A render array representing the administrative page content.
*/
public function adminOverview() {
$rows = array();
$rows = [];
$headers = array(t('Book'), t('Operations'));
$headers = [t('Book'), t('Operations')];
// Add any recognized books to the table list.
foreach ($this->bookManager->getAllBooks() as $book) {
/** @var \Drupal\Core\Url $url */
@@ -83,28 +83,28 @@ class BookController extends ControllerBase {
if (isset($book['options'])) {
$url->setOptions($book['options']);
}
$row = array(
$row = [
$this->l($book['title'], $url),
);
$links = array();
$links['edit'] = array(
];
$links = [];
$links['edit'] = [
'title' => t('Edit order and titles'),
'url' => Url::fromRoute('book.admin_edit', ['node' => $book['nid']]),
);
$row[] = array(
'data' => array(
];
$row[] = [
'data' => [
'#type' => 'operations',
'#links' => $links,
),
);
],
];
$rows[] = $row;
}
return array(
return [
'#type' => 'table',
'#header' => $headers,
'#rows' => $rows,
'#empty' => t('No books available.'),
);
];
}
/**
@@ -114,17 +114,17 @@ class BookController extends ControllerBase {
* A render array representing the listing of all books content.
*/
public function bookRender() {
$book_list = array();
$book_list = [];
foreach ($this->bookManager->getAllBooks() as $book) {
$book_list[] = $this->l($book['title'], $book['url']);
}
return array(
return [
'#theme' => 'item_list',
'#items' => $book_list,
'#cache' => [
'tags' => \Drupal::entityManager()->getDefinition('node')->getListCacheTags(),
],
);
];
}
/**
@@ -70,10 +70,10 @@ class BookAdminEditForm extends FormBase {
$form['#title'] = $node->label();
$form['#node'] = $node;
$this->bookAdminTable($node, $form);
$form['save'] = array(
$form['save'] = [
'#type' => 'submit',
'#value' => $this->t('Save book pages'),
);
];
return $form;
}
@@ -101,7 +101,7 @@ class BookAdminEditForm extends FormBase {
foreach (Element::children($form['table']) as $key) {
if ($form['table'][$key]['#item']) {
$row = $form['table'][$key];
$values = $form_state->getValue(array('table', $key));
$values = $form_state->getValue(['table', $key]);
// Update menu item if moved.
if ($row['parent']['pid']['#default_value'] != $values['pid'] || $row['weight']['#default_value'] != $values['weight']) {
@@ -114,18 +114,18 @@ class BookAdminEditForm extends FormBase {
// Update the title if changed.
if ($row['title']['#default_value'] != $values['title']) {
$node = $this->nodeStorage->load($values['nid']);
$node->revision_log = $this->t('Title changed from %original to %current.', array('%original' => $node->label(), '%current' => $values['title']));
$node->revision_log = $this->t('Title changed from %original to %current.', ['%original' => $node->label(), '%current' => $values['title']]);
$node->title = $values['title'];
$node->book['link_title'] = $values['title'];
$node->setNewRevision();
$node->save();
$this->logger('content')->notice('book: updated %title.', array('%title' => $node->label(), 'link' => $node->link($this->t('View'))));
$this->logger('content')->notice('book: updated %title.', ['%title' => $node->label(), 'link' => $node->link($this->t('View'))]);
}
}
}
}
drupal_set_message($this->t('Updated book %title.', array('%title' => $form['#node']->label())));
drupal_set_message($this->t('Updated book %title.', ['%title' => $form['#node']->label()]));
}
/**
@@ -139,7 +139,7 @@ class BookAdminEditForm extends FormBase {
* @see self::buildForm()
*/
protected function bookAdminTable(NodeInterface $node, array &$form) {
$form['table'] = array(
$form['table'] = [
'#type' => 'table',
'#header' => [
$this->t('Title'),
@@ -164,7 +164,7 @@ class BookAdminEditForm extends FormBase {
'group' => 'book-weight',
],
],
);
];
$tree = $this->bookManager->bookSubtreeData($node->book);
// Do not include the book item itself.
@@ -173,14 +173,14 @@ class BookAdminEditForm extends FormBase {
$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(
$form['tree_hash'] = [
'#type' => 'hidden',
'#default_value' => $hash,
);
$form['tree_current_hash'] = array(
];
$form['tree_current_hash'] = [
'#type' => 'value',
'#value' => $hash,
);
];
$this->bookAdminTableTree($tree['below'], $form['table']);
}
}
+12 -4
View File
@@ -3,8 +3,10 @@
namespace Drupal\book\Form;
use Drupal\book\BookManagerInterface;
use Drupal\Component\Datetime\TimeInterface;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -35,9 +37,13 @@ class BookOutlineForm extends ContentEntityForm {
* The entity manager.
* @param \Drupal\book\BookManagerInterface $book_manager
* The BookManager service.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
* The entity type bundle service.
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
public function __construct(EntityManagerInterface $entity_manager, BookManagerInterface $book_manager) {
parent::__construct($entity_manager);
public function __construct(EntityManagerInterface $entity_manager, BookManagerInterface $book_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
parent::__construct($entity_manager, $entity_type_bundle_info, $time);
$this->bookManager = $book_manager;
}
@@ -47,7 +53,9 @@ class BookOutlineForm extends ContentEntityForm {
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('book.manager')
$container->get('book.manager'),
$container->get('entity_type.bundle.info'),
$container->get('datetime.time')
);
}
@@ -99,7 +107,7 @@ class BookOutlineForm extends ContentEntityForm {
public function save(array $form, FormStateInterface $form_state) {
$form_state->setRedirect(
'entity.node.canonical',
array('node' => $this->entity->id())
['node' => $this->entity->id()]
);
$book_link = $form_state->getValue('book');
if (!$book_link['bid']) {
@@ -65,7 +65,7 @@ class BookRemoveForm extends ConfirmFormBase {
* {@inheritdoc}
*/
public function getDescription() {
$title = array('%title' => $this->node->label());
$title = ['%title' => $this->node->label()];
if ($this->node->book['has_children']) {
return $this->t('%title has associated child pages, which will be relocated automatically to maintain their connection to the book. To recreate the hierarchy (as it was before removing this page), %title may be added again using the Outline tab, and each of its former child pages will need to be relocated manually.', $title);
}
@@ -85,7 +85,7 @@ class BookRemoveForm extends ConfirmFormBase {
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Are you sure you want to remove %title from the book hierarchy?', array('%title' => $this->node->label()));
return $this->t('Are you sure you want to remove %title from the book hierarchy?', ['%title' => $this->node->label()]);
}
/**
@@ -30,22 +30,22 @@ class BookSettingsForm extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$types = node_type_get_names();
$config = $this->config('book.settings');
$form['book_allowed_types'] = array(
$form['book_allowed_types'] = [
'#type' => 'checkboxes',
'#title' => $this->t('Content types allowed in book outlines'),
'#default_value' => $config->get('allowed_types'),
'#options' => $types,
'#description' => $this->t('Users with the %outline-perm permission can add all content types.', array('%outline-perm' => $this->t('Administer book outlines'))),
'#description' => $this->t('Users with the %outline-perm permission can add all content types.', ['%outline-perm' => $this->t('Administer book outlines')]),
'#required' => TRUE,
);
$form['book_child_type'] = array(
];
$form['book_child_type'] = [
'#type' => 'radios',
'#title' => $this->t('Content type for the <em>Add child page</em> link'),
'#default_value' => $config->get('child_type'),
'#options' => $types,
'#required' => TRUE,
);
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
];
$form['array_filter'] = ['#type' => 'value', '#value' => TRUE];
return parent::buildForm($form, $form_state);
}
@@ -55,8 +55,8 @@ class BookSettingsForm extends ConfigFormBase {
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$child_type = $form_state->getValue('book_child_type');
if ($form_state->isValueEmpty(array('book_allowed_types', $child_type))) {
$form_state->setErrorByName('book_child_type', $this->t('The content type for the %add-child link must be one of those selected as an allowed book outline type.', array('%add-child' => $this->t('Add child page'))));
if ($form_state->isValueEmpty(['book_allowed_types', $child_type])) {
$form_state->setErrorByName('book_child_type', $this->t('The content type for the %add-child link must be one of those selected as an allowed book outline type.', ['%add-child' => $this->t('Add child page')]));
}
parent::validateForm($form, $form_state);
@@ -7,6 +7,7 @@ use Drupal\book\BookManagerInterface;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\node\NodeInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Drupal\Core\Entity\EntityStorageInterface;
@@ -85,26 +86,26 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
* {@inheritdoc}
*/
public function defaultConfiguration() {
return array(
return [
'block_mode' => "all pages",
);
];
}
/**
* {@inheritdoc}
*/
function blockForm($form, FormStateInterface $form_state) {
$options = array(
public function blockForm($form, FormStateInterface $form_state) {
$options = [
'all pages' => $this->t('Show block on all pages'),
'book pages' => $this->t('Show block only on book pages'),
);
$form['book_block_mode'] = array(
];
$form['book_block_mode'] = [
'#type' => 'radios',
'#title' => $this->t('Book navigation block display'),
'#options' => $options,
'#default_value' => $this->configuration['block_mode'],
'#description' => $this->t("If <em>Show block on all pages</em> is selected, the block will contain the automatically generated menus for all of the site's books. If <em>Show block only on book pages</em> is selected, the block will contain only the one menu corresponding to the current page's book. In this case, if the current page is not in a book, no block will be displayed. The <em>Page specific visibility settings</em> or other visibility settings can be used in addition to selectively display this block."),
);
];
return $form;
}
@@ -126,8 +127,8 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
$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));
$book_menus = [];
$pseudo_tree = [0 => ['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
@@ -145,20 +146,23 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
$pseudo_tree[0]['link'] = $book;
$book_menus[$book_id] = $this->bookManager->bookTreeOutput($pseudo_tree);
}
$book_menus[$book_id] += array(
$book_menus[$book_id] += [
'#book_title' => $book['title'],
);
];
}
if ($book_menus) {
return array(
return [
'#theme' => 'book_all_books_block',
) + $book_menus;
] + $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 display this block when the user is browsing a book and do
// not show unpublished books.
$nid = \Drupal::entityQuery('node')
->condition('nid', $node->book['bid'], '=')
->condition('status', NodeInterface::PUBLISHED)
->execute();
// Only show the block if the user has view access for the top-level node.
if ($nid) {
@@ -171,7 +175,7 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
}
}
}
return array();
return [];
}
/**
@@ -17,9 +17,9 @@ class Book extends DrupalSqlBase {
* {@inheritdoc}
*/
public function query() {
$query = $this->select('book', 'b')->fields('b', array('nid', 'bid'));
$query = $this->select('book', 'b')->fields('b', ['nid', 'bid']);
$query->join('menu_links', 'ml', 'b.mlid = ml.mlid');
$ml_fields = array('mlid', 'plid', 'weight', 'has_children', 'depth');
$ml_fields = ['mlid', 'plid', 'weight', 'has_children', 'depth'];
for ($i = 1; $i <= 9; $i++) {
$field = "p$i";
$ml_fields[] = $field;
@@ -42,7 +42,7 @@ class Book extends DrupalSqlBase {
* {@inheritdoc}
*/
public function fields() {
return array(
return [
'nid' => $this->t('Node ID'),
'bid' => $this->t('Book ID'),
'mlid' => $this->t('Menu link ID'),
@@ -57,7 +57,7 @@ class Book extends DrupalSqlBase {
'p7' => $this->t('The seventh mlid in the materialized path. See p1.'),
'p8' => $this->t('The eighth mlid in the materialized path. See p1.'),
'p9' => $this->t('The ninth mlid in the materialized path. See p1.'),
);
];
}
}
@@ -0,0 +1,73 @@
<?php
namespace Drupal\book\Plugin\views\argument_default;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\node\NodeStorageInterface;
use Drupal\node\Plugin\views\argument_default\Node;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Default argument plugin to get the current node's top level book.
*
* @ViewsArgumentDefault(
* id = "top_level_book",
* title = @Translation("Top Level Book from current node")
* )
*/
class TopLevelBook extends Node {
/**
* The node storage controller.
*
* @var \Drupal\node\NodeStorageInterface
*/
protected $nodeStorage;
/**
* Constructs a Drupal\book\Plugin\views\argument_default\TopLevelBook object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The route match.
* @param \Drupal\node\NodeStorageInterface $node_storage
* The node storage controller.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, RouteMatchInterface $route_match, NodeStorageInterface $node_storage) {
parent::__construct($configuration, $plugin_id, $plugin_definition, $route_match);
$this->nodeStorage = $node_storage;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('current_route_match'),
$container->get('entity.manager')->getStorage('node')
);
}
/**
* {@inheritdoc}
*/
public function getArgument() {
// Use the argument_default_node plugin to get the nid argument.
$nid = parent::getArgument();
if (!empty($nid)) {
$node = $this->nodeStorage->load($nid);
if (isset($node->book['bid'])) {
return $node->book['bid'];
}
}
}
}