Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -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++;

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,
);
];
}
}

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' => [],
];
}
/**
@ -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']);

View file

@ -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.

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.

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']);

View file

@ -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)

View file

@ -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(),
],
);
];
}
/**

View file

@ -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']);
}
}

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']) {

View file

@ -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()]);
}
/**

View file

@ -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);

View file

@ -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,14 +146,14 @@ 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) {
@ -160,7 +161,7 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
// not show unpublished books.
$nid = \Drupal::entityQuery('node')
->condition('nid', $node->book['bid'], '=')
->condition('status', NODE_PUBLISHED)
->condition('status', NodeInterface::PUBLISHED)
->execute();
// Only show the block if the user has view access for the top-level node.
@ -174,7 +175,7 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
}
}
}
return array();
return [];
}
/**

View file

@ -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.'),
);
];
}
}

View file

@ -1,204 +0,0 @@
<?php
namespace Drupal\book\Tests;
use Drupal\simpletest\WebTestBase;
/**
* Create a book, add pages, and test book interface.
*
* @group book
*/
class BookBreadcrumbTest extends WebTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('book', 'block', 'book_breadcrumb_test');
/**
* A book node.
*
* @var \Drupal\node\NodeInterface
*/
protected $book;
/**
* A user with permission to create and edit books.
*
* @var \Drupal\user\Entity\User
*/
protected $bookAuthor;
/**
* A user without the 'node test view' permission.
*
* @var \Drupal\user\UserInterface
*/
protected $webUserWithoutNodeAccess;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('system_breadcrumb_block');
$this->drupalPlaceBlock('page_title_block');
// Create users.
$this->bookAuthor = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books'));
$this->adminUser = $this->drupalCreateUser(array('create new books', 'create book content', 'edit any book content', 'delete any book content', 'add content to books', 'administer blocks', 'administer permissions', 'administer book outlines', 'administer content types', 'administer site configuration'));
}
/**
* Creates a new book with a page hierarchy.
*
* @return \Drupal\node\NodeInterface[]
* The created book nodes.
*/
protected function createBreadcrumbBook() {
// Create new book.
$this->drupalLogin($this->bookAuthor);
$this->book = $this->createBookNode('new');
$book = $this->book;
/*
* Add page hierarchy to book.
* Book
* |- Node 0
* |- Node 1
* |- Node 2
* |- Node 3
* |- Node 4
* |- Node 5
* |- Node 6
*/
$nodes = array();
$nodes[0] = $this->createBookNode($book->id());
$nodes[1] = $this->createBookNode($book->id(), $nodes[0]->id());
$nodes[2] = $this->createBookNode($book->id(), $nodes[0]->id());
$nodes[3] = $this->createBookNode($book->id(), $nodes[2]->id());
$nodes[4] = $this->createBookNode($book->id(), $nodes[3]->id());
$nodes[5] = $this->createBookNode($book->id(), $nodes[4]->id());
$nodes[6] = $this->createBookNode($book->id());
$this->drupalLogout();
return $nodes;
}
/**
* Creates a book node.
*
* @param int|string $book_nid
* A book node ID or set to 'new' to create a new book.
* @param int|null $parent
* (optional) Parent book reference ID. Defaults to NULL.
*
* @return \Drupal\node\NodeInterface
* The created node.
*/
protected function createBookNode($book_nid, $parent = NULL) {
// $number does not use drupal_static as it should not be reset since it
// uniquely identifies each call to createBookNode(). It is used to ensure
// that when sorted nodes stay in same order.
static $number = 0;
$edit = array();
$edit['title[0][value]'] = str_pad($number, 2, '0', STR_PAD_LEFT) . ' - SimpleTest test node ' . $this->randomMachineName(10);
$edit['body[0][value]'] = 'SimpleTest test body ' . $this->randomMachineName(32) . ' ' . $this->randomMachineName(32);
$edit['book[bid]'] = $book_nid;
if ($parent !== NULL) {
$this->drupalPostForm('node/add/book', $edit, t('Change book (update list of parents)'));
$edit['book[pid]'] = $parent;
$this->drupalPostForm(NULL, $edit, t('Save'));
// Make sure the parent was flagged as having children.
$parent_node = \Drupal::entityManager()->getStorage('node')->loadUnchanged($parent);
$this->assertFalse(empty($parent_node->book['has_children']), 'Parent node is marked as having children');
}
else {
$this->drupalPostForm('node/add/book', $edit, t('Save'));
}
// Check to make sure the book node was created.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertNotNull(($node === FALSE ? NULL : $node), 'Book node found in database.');
$number++;
return $node;
}
/**
* Test that the breadcrumb is updated when book content changes.
*/
public function testBreadcrumbTitleUpdates() {
// Create a new book.
$nodes = $this->createBreadcrumbBook();
$book = $this->book;
$this->drupalLogin($this->bookAuthor);
$this->drupalGet($nodes[4]->toUrl());
// Fetch each node title in the current breadcrumb.
$links = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a');
$got_breadcrumb = array();
foreach ($links as $link) {
$got_breadcrumb[] = (string) $link;
}
// Home link and four parent book nodes should be in the breadcrumb.
$this->assertEqual(5, count($got_breadcrumb));
$this->assertEqual($nodes[3]->getTitle(), end($got_breadcrumb));
$edit = [
'title[0][value]' => 'Updated node5 title',
];
$this->drupalPostForm($nodes[3]->toUrl('edit-form'), $edit, 'Save');
$this->drupalGet($nodes[4]->toUrl());
// Fetch each node title in the current breadcrumb.
$links = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a');
$got_breadcrumb = array();
foreach ($links as $link) {
$got_breadcrumb[] = (string) $link;
}
$this->assertEqual(5, count($got_breadcrumb));
$this->assertEqual($edit['title[0][value]'], end($got_breadcrumb));
}
/**
* Test that the breadcrumb is updated when book access changes.
*/
public function testBreadcrumbAccessUpdates() {
// Create a new book.
$nodes = $this->createBreadcrumbBook();
$this->drupalLogin($this->bookAuthor);
$edit = [
'title[0][value]' => "you can't see me",
];
$this->drupalPostForm($nodes[3]->toUrl('edit-form'), $edit, 'Save');
$this->drupalGet($nodes[4]->toUrl());
$links = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a');
$got_breadcrumb = array();
foreach ($links as $link) {
$got_breadcrumb[] = (string) $link;
}
$this->assertEqual(5, count($got_breadcrumb));
$this->assertEqual($edit['title[0][value]'], end($got_breadcrumb));
$config = $this->container->get('config.factory')->getEditable('book_breadcrumb_test.settings');
$config->set('hide', TRUE)->save();
$this->drupalGet($nodes[4]->toUrl());
$links = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a');
$got_breadcrumb = array();
foreach ($links as $link) {
$got_breadcrumb[] = (string) $link;
}
$this->assertEqual(4, count($got_breadcrumb));
$this->assertEqual($nodes[2]->getTitle(), end($got_breadcrumb));
$this->drupalGet($nodes[3]->toUrl());
$this->assertResponse(403);
}
}

View file

@ -1,752 +0,0 @@
<?php
namespace Drupal\book\Tests;
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityInterface;
use Drupal\simpletest\WebTestBase;
use Drupal\user\RoleInterface;
/**
* Create a book, add pages, and test book interface.
*
* @group book
*/
class BookTest extends WebTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('book', 'block', 'node_access_test', 'book_test');
/**
* A book node.
*
* @var \Drupal\node\NodeInterface
*/
protected $book;
/**
* A user with permission to create and edit books.
*
* @var object
*/
protected $bookAuthor;
/**
* A user with permission to view a book and access printer-friendly version.
*
* @var object
*/
protected $webUser;
/**
* A user with permission to create and edit books and to administer blocks.
*
* @var object
*/
protected $adminUser;
/**
* A user without the 'node test view' permission.
*
* @var \Drupal\user\UserInterface
*/
protected $webUserWithoutNodeAccess;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->drupalPlaceBlock('system_breadcrumb_block');
$this->drupalPlaceBlock('page_title_block');
// node_access_test requires a node_access_rebuild().
node_access_rebuild();
// Create users.
$this->bookAuthor = $this->drupalCreateUser(array('create new books', 'create book content', 'edit own book content', 'add content to books'));
$this->webUser = $this->drupalCreateUser(array('access printer-friendly version', 'node test view'));
$this->webUserWithoutNodeAccess = $this->drupalCreateUser(array('access printer-friendly version'));
$this->adminUser = $this->drupalCreateUser(array('create new books', 'create book content', 'edit any book content', 'delete any book content', 'add content to books', 'administer blocks', 'administer permissions', 'administer book outlines', 'node test view', 'administer content types', 'administer site configuration'));
}
/**
* Creates a new book with a page hierarchy.
*
* @return \Drupal\node\NodeInterface[]
*/
function createBook() {
// Create new book.
$this->drupalLogin($this->bookAuthor);
$this->book = $this->createBookNode('new');
$book = $this->book;
/*
* Add page hierarchy to book.
* Book
* |- Node 0
* |- Node 1
* |- Node 2
* |- Node 3
* |- Node 4
*/
$nodes = array();
$nodes[] = $this->createBookNode($book->id()); // Node 0.
$nodes[] = $this->createBookNode($book->id(), $nodes[0]->book['nid']); // Node 1.
$nodes[] = $this->createBookNode($book->id(), $nodes[0]->book['nid']); // Node 2.
$nodes[] = $this->createBookNode($book->id()); // Node 3.
$nodes[] = $this->createBookNode($book->id()); // Node 4.
$this->drupalLogout();
return $nodes;
}
/**
* Tests the book navigation cache context.
*
* @see \Drupal\book\Cache\BookNavigationCacheContext
*/
public function testBookNavigationCacheContext() {
// Create a page node.
$this->drupalCreateContentType(['type' => 'page']);
$page = $this->drupalCreateNode();
// Create a book, consisting of book nodes.
$book_nodes = $this->createBook();
// Enable the debug output.
\Drupal::state()->set('book_test.debug_book_navigation_cache_context', TRUE);
Cache::invalidateTags(['book_test.debug_book_navigation_cache_context']);
$this->drupalLogin($this->bookAuthor);
// On non-node route.
$this->drupalGet($this->adminUser->urlInfo());
$this->assertRaw('[route.book_navigation]=book.none');
// On non-book node route.
$this->drupalGet($page->urlInfo());
$this->assertRaw('[route.book_navigation]=book.none');
// On book node route.
$this->drupalGet($book_nodes[0]->urlInfo());
$this->assertRaw('[route.book_navigation]=0|2|3');
$this->drupalGet($book_nodes[1]->urlInfo());
$this->assertRaw('[route.book_navigation]=0|2|3|4');
$this->drupalGet($book_nodes[2]->urlInfo());
$this->assertRaw('[route.book_navigation]=0|2|3|5');
$this->drupalGet($book_nodes[3]->urlInfo());
$this->assertRaw('[route.book_navigation]=0|2|6');
$this->drupalGet($book_nodes[4]->urlInfo());
$this->assertRaw('[route.book_navigation]=0|2|7');
}
/**
* Tests saving the book outline on an empty book.
*/
function testEmptyBook() {
// Create a new empty book.
$this->drupalLogin($this->bookAuthor);
$book = $this->createBookNode('new');
$this->drupalLogout();
// Log in as a user with access to the book outline and save the form.
$this->drupalLogin($this->adminUser);
$this->drupalPostForm('admin/structure/book/' . $book->id(), array(), t('Save book pages'));
$this->assertText(t('Updated book @book.', array('@book' => $book->label())));
}
/**
* Tests book functionality through node interfaces.
*/
function testBook() {
// Create new book.
$nodes = $this->createBook();
$book = $this->book;
$this->drupalLogin($this->webUser);
// Check that book pages display along with the correct outlines and
// previous/next links.
$this->checkBookNode($book, array($nodes[0], $nodes[3], $nodes[4]), FALSE, FALSE, $nodes[0], array());
$this->checkBookNode($nodes[0], array($nodes[1], $nodes[2]), $book, $book, $nodes[1], array($book));
$this->checkBookNode($nodes[1], NULL, $nodes[0], $nodes[0], $nodes[2], array($book, $nodes[0]));
$this->checkBookNode($nodes[2], NULL, $nodes[1], $nodes[0], $nodes[3], array($book, $nodes[0]));
$this->checkBookNode($nodes[3], NULL, $nodes[2], $book, $nodes[4], array($book));
$this->checkBookNode($nodes[4], NULL, $nodes[3], $book, FALSE, array($book));
$this->drupalLogout();
$this->drupalLogin($this->bookAuthor);
// Check the presence of expected cache tags.
$this->drupalGet('node/add/book');
$this->assertCacheTag('config:book.settings');
/*
* Add Node 5 under Node 3.
* Book
* |- Node 0
* |- Node 1
* |- Node 2
* |- Node 3
* |- Node 5
* |- Node 4
*/
$nodes[] = $this->createBookNode($book->id(), $nodes[3]->book['nid']); // Node 5.
$this->drupalLogout();
$this->drupalLogin($this->webUser);
// Verify the new outline - make sure we don't get stale cached data.
$this->checkBookNode($nodes[3], array($nodes[5]), $nodes[2], $book, $nodes[5], array($book));
$this->checkBookNode($nodes[4], NULL, $nodes[5], $book, FALSE, array($book));
$this->drupalLogout();
// Create a second book, and move an existing book page into it.
$this->drupalLogin($this->bookAuthor);
$other_book = $this->createBookNode('new');
$node = $this->createBookNode($book->id());
$edit = array('book[bid]' => $other_book->id());
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$this->drupalLogout();
$this->drupalLogin($this->webUser);
// Check that the nodes in the second book are displayed correctly.
// First we must set $this->book to the second book, so that the
// correct regex will be generated for testing the outline.
$this->book = $other_book;
$this->checkBookNode($other_book, array($node), FALSE, FALSE, $node, array());
$this->checkBookNode($node, NULL, $other_book, $other_book, FALSE, array($other_book));
// Test that we can save a book programatically.
$this->drupalLogin($this->bookAuthor);
$book = $this->createBookNode('new');
$book->save();
}
/**
* Checks the outline of sub-pages; previous, up, and next.
*
* Also checks the printer friendly version of the outline.
*
* @param \Drupal\Core\Entity\EntityInterface $node
* Node to check.
* @param $nodes
* Nodes that should be in outline.
* @param $previous
* (optional) Previous link node. Defaults to FALSE.
* @param $up
* (optional) Up link node. Defaults to FALSE.
* @param $next
* (optional) Next link node. Defaults to FALSE.
* @param array $breadcrumb
* The nodes that should be displayed in the breadcrumb.
*/
function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = FALSE, $next = FALSE, array $breadcrumb) {
// $number does not use drupal_static as it should not be reset
// since it uniquely identifies each call to checkBookNode().
static $number = 0;
$this->drupalGet('node/' . $node->id());
// Check outline structure.
if ($nodes !== NULL) {
$this->assertPattern($this->generateOutlinePattern($nodes), format_string('Node @number outline confirmed.', array('@number' => $number)));
}
else {
$this->pass(format_string('Node %number does not have outline.', array('%number' => $number)));
}
// Check previous, up, and next links.
if ($previous) {
/** @var \Drupal\Core\Url $url */
$url = $previous->urlInfo();
$url->setOptions(array('attributes' => array('rel' => array('prev'), 'title' => t('Go to previous page'))));
$text = SafeMarkup::format('<b></b> @label', array('@label' => $previous->label()));
$this->assertRaw(\Drupal::l($text, $url), 'Previous page link found.');
}
if ($up) {
/** @var \Drupal\Core\Url $url */
$url = $up->urlInfo();
$url->setOptions(array('attributes' => array('title' => t('Go to parent page'))));
$this->assertRaw(\Drupal::l('Up', $url), 'Up page link found.');
}
if ($next) {
/** @var \Drupal\Core\Url $url */
$url = $next->urlInfo();
$url->setOptions(array('attributes' => array('rel' => array('next'), 'title' => t('Go to next page'))));
$text = SafeMarkup::format('@label <b></b>', array('@label' => $next->label()));
$this->assertRaw(\Drupal::l($text, $url), 'Next page link found.');
}
// Compute the expected breadcrumb.
$expected_breadcrumb = array();
$expected_breadcrumb[] = \Drupal::url('<front>');
foreach ($breadcrumb as $a_node) {
$expected_breadcrumb[] = $a_node->url();
}
// Fetch links in the current breadcrumb.
$links = $this->xpath('//nav[@class="breadcrumb"]/ol/li/a');
$got_breadcrumb = array();
foreach ($links as $link) {
$got_breadcrumb[] = (string) $link['href'];
}
// Compare expected and got breadcrumbs.
$this->assertIdentical($expected_breadcrumb, $got_breadcrumb, 'The breadcrumb is correctly displayed on the page.');
// Check printer friendly version.
$this->drupalGet('book/export/html/' . $node->id());
$this->assertText($node->label(), 'Printer friendly title found.');
$this->assertRaw($node->body->processed, 'Printer friendly body found.');
$number++;
}
/**
* Creates a regular expression to check for the sub-nodes in the outline.
*
* @param array $nodes
* An array of nodes to check in outline.
*
* @return string
* A regular expression that locates sub-nodes of the outline.
*/
function generateOutlinePattern($nodes) {
$outline = '';
foreach ($nodes as $node) {
$outline .= '(node\/' . $node->id() . ')(.*?)(' . $node->label() . ')(.*?)';
}
return '/<nav id="book-navigation-' . $this->book->id() . '"(.*?)<ul(.*?)' . $outline . '<\/ul>/s';
}
/**
* Creates a book node.
*
* @param int|string $book_nid
* A book node ID or set to 'new' to create a new book.
* @param int|null $parent
* (optional) Parent book reference ID. Defaults to NULL.
*
* @return \Drupal\node\NodeInterface
* The created node.
*/
function createBookNode($book_nid, $parent = NULL) {
// $number does not use drupal_static as it should not be reset
// since it uniquely identifies each call to createBookNode().
static $number = 0; // Used to ensure that when sorted nodes stay in same order.
$edit = array();
$edit['title[0][value]'] = str_pad($number, 2, '0', STR_PAD_LEFT) . ' - SimpleTest test node ' . $this->randomMachineName(10);
$edit['body[0][value]'] = 'SimpleTest test body ' . $this->randomMachineName(32) . ' ' . $this->randomMachineName(32);
$edit['book[bid]'] = $book_nid;
if ($parent !== NULL) {
$this->drupalPostForm('node/add/book', $edit, t('Change book (update list of parents)'));
$edit['book[pid]'] = $parent;
$this->drupalPostForm(NULL, $edit, t('Save'));
// Make sure the parent was flagged as having children.
$parent_node = \Drupal::entityManager()->getStorage('node')->loadUnchanged($parent);
$this->assertFalse(empty($parent_node->book['has_children']), 'Parent node is marked as having children');
}
else {
$this->drupalPostForm('node/add/book', $edit, t('Save'));
}
// Check to make sure the book node was created.
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
$this->assertNotNull(($node === FALSE ? NULL : $node), 'Book node found in database.');
$number++;
return $node;
}
/**
* Tests book export ("printer-friendly version") functionality.
*/
function testBookExport() {
// Create a book.
$nodes = $this->createBook();
// Log in as web user and view printer-friendly version.
$this->drupalLogin($this->webUser);
$this->drupalGet('node/' . $this->book->id());
$this->clickLink(t('Printer-friendly version'));
// Make sure each part of the book is there.
foreach ($nodes as $node) {
$this->assertText($node->label(), 'Node title found in printer friendly version.');
$this->assertRaw($node->body->processed, 'Node body found in printer friendly version.');
}
// Make sure we can't export an unsupported format.
$this->drupalGet('book/export/foobar/' . $this->book->id());
$this->assertResponse('404', 'Unsupported export format returned "not found".');
// Make sure we get a 404 on a not existing book node.
$this->drupalGet('book/export/html/123');
$this->assertResponse('404', 'Not existing book node returned "not found".');
// Make sure an anonymous user cannot view printer-friendly version.
$this->drupalLogout();
// Load the book and verify there is no printer-friendly version link.
$this->drupalGet('node/' . $this->book->id());
$this->assertNoLink(t('Printer-friendly version'), 'Anonymous user is not shown link to printer-friendly version.');
// Try getting the URL directly, and verify it fails.
$this->drupalGet('book/export/html/' . $this->book->id());
$this->assertResponse('403', 'Anonymous user properly forbidden.');
// Now grant anonymous users permission to view the printer-friendly
// version and verify that node access restrictions still prevent them from
// seeing it.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access printer-friendly version'));
$this->drupalGet('book/export/html/' . $this->book->id());
$this->assertResponse('403', 'Anonymous user properly forbidden from seeing the printer-friendly version when denied by node access.');
}
/**
* Tests the functionality of the book navigation block.
*/
function testBookNavigationBlock() {
$this->drupalLogin($this->adminUser);
// Enable the block.
$block = $this->drupalPlaceBlock('book_navigation');
// Give anonymous users the permission 'node test view'.
$edit = array();
$edit[RoleInterface::ANONYMOUS_ID . '[node test view]'] = TRUE;
$this->drupalPostForm('admin/people/permissions/' . RoleInterface::ANONYMOUS_ID, $edit, t('Save permissions'));
$this->assertText(t('The changes have been saved.'), "Permission 'node test view' successfully assigned to anonymous users.");
// Test correct display of the block.
$nodes = $this->createBook();
$this->drupalGet('<front>');
$this->assertText($block->label(), 'Book navigation block is displayed.');
$this->assertText($this->book->label(), format_string('Link to book root (@title) is displayed.', array('@title' => $nodes[0]->label())));
$this->assertNoText($nodes[0]->label(), 'No links to individual book pages are displayed.');
}
/**
* Tests BookManager::getTableOfContents().
*/
public function testGetTableOfContents() {
// Create new book.
$nodes = $this->createBook();
$book = $this->book;
$this->drupalLogin($this->bookAuthor);
/*
* Add Node 5 under Node 2.
* Add Node 6, 7, 8, 9, 10, 11 under Node 3.
* Book
* |- Node 0
* |- Node 1
* |- Node 2
* |- Node 5
* |- Node 3
* |- Node 6
* |- Node 7
* |- Node 8
* |- Node 9
* |- Node 10
* |- Node 11
* |- Node 4
*/
foreach ([5 => 2, 6 => 3, 7 => 6, 8 => 7, 9 => 8, 10 => 9, 11 => 10] as $child => $parent) {
$nodes[$child] = $this->createBookNode($book->id(), $nodes[$parent]->id());
}
$this->drupalGet($nodes[0]->toUrl('edit-form'));
// Snice Node 0 has children 2 levels deep, nodes 10 and 11 should not
// appear in the selector.
$this->assertNoOption('edit-book-pid', $nodes[10]->id());
$this->assertNoOption('edit-book-pid', $nodes[11]->id());
// Node 9 should be available as an option.
$this->assertOption('edit-book-pid', $nodes[9]->id());
// Get a shallow set of options.
/** @var \Drupal\book\BookManagerInterface $manager */
$manager = $this->container->get('book.manager');
$options = $manager->getTableOfContents($book->id(), 3);
$expected_nids = [$book->id(), $nodes[0]->id(), $nodes[1]->id(), $nodes[2]->id(), $nodes[3]->id(), $nodes[6]->id(), $nodes[4]->id()];
$this->assertEqual(count($options), count($expected_nids));
$diff = array_diff($expected_nids, array_keys($options));
$this->assertTrue(empty($diff), 'Found all expected option keys');
// Exclude Node 3.
$options = $manager->getTableOfContents($book->id(), 3, array($nodes[3]->id()));
$expected_nids = array($book->id(), $nodes[0]->id(), $nodes[1]->id(), $nodes[2]->id(), $nodes[4]->id());
$this->assertEqual(count($options), count($expected_nids));
$diff = array_diff($expected_nids, array_keys($options));
$this->assertTrue(empty($diff), 'Found all expected option keys after excluding Node 3');
}
/**
* Tests the book navigation block when an access module is installed.
*/
function testNavigationBlockOnAccessModuleInstalled() {
$this->drupalLogin($this->adminUser);
$block = $this->drupalPlaceBlock('book_navigation', array('block_mode' => 'book pages'));
// Give anonymous users the permission 'node test view'.
$edit = array();
$edit[RoleInterface::ANONYMOUS_ID . '[node test view]'] = TRUE;
$this->drupalPostForm('admin/people/permissions/' . RoleInterface::ANONYMOUS_ID, $edit, t('Save permissions'));
$this->assertText(t('The changes have been saved.'), "Permission 'node test view' successfully assigned to anonymous users.");
// Create a book.
$this->createBook();
// Test correct display of the block to registered users.
$this->drupalLogin($this->webUser);
$this->drupalGet('node/' . $this->book->id());
$this->assertText($block->label(), 'Book navigation block is displayed to registered users.');
$this->drupalLogout();
// Test correct display of the block to anonymous users.
$this->drupalGet('node/' . $this->book->id());
$this->assertText($block->label(), 'Book navigation block is displayed to anonymous users.');
// Test the 'book pages' block_mode setting.
$this->drupalGet('<front>');
$this->assertNoText($block->label(), 'Book navigation block is not shown on non-book pages.');
}
/**
* Tests the access for deleting top-level book nodes.
*/
function testBookDelete() {
$node_storage = $this->container->get('entity.manager')->getStorage('node');
$nodes = $this->createBook();
$this->drupalLogin($this->adminUser);
$edit = array();
// Test access to delete top-level and child book nodes.
$this->drupalGet('node/' . $this->book->id() . '/outline/remove');
$this->assertResponse('403', 'Deleting top-level book node properly forbidden.');
$this->drupalPostForm('node/' . $nodes[4]->id() . '/outline/remove', $edit, t('Remove'));
$node_storage->resetCache(array($nodes[4]->id()));
$node4 = $node_storage->load($nodes[4]->id());
$this->assertTrue(empty($node4->book), 'Deleting child book node properly allowed.');
// Delete all child book nodes and retest top-level node deletion.
foreach ($nodes as $node) {
$nids[] = $node->id();
}
entity_delete_multiple('node', $nids);
$this->drupalPostForm('node/' . $this->book->id() . '/outline/remove', $edit, t('Remove'));
$node_storage->resetCache(array($this->book->id()));
$node = $node_storage->load($this->book->id());
$this->assertTrue(empty($node->book), 'Deleting childless top-level book node properly allowed.');
// Tests directly deleting a book parent.
$nodes = $this->createBook();
$this->drupalLogin($this->adminUser);
$this->drupalGet($this->book->urlInfo('delete-form'));
$this->assertRaw(t('%title is part of a book outline, and has associated child pages. If you proceed with deletion, the child pages will be relocated automatically.', ['%title' => $this->book->label()]));
// Delete parent, and visit a child page.
$this->drupalPostForm($this->book->urlInfo('delete-form'), [], t('Delete'));
$this->drupalGet($nodes[0]->urlInfo());
$this->assertResponse(200);
$this->assertText($nodes[0]->label());
// The book parents should be updated.
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
$node_storage->resetCache();
$child = $node_storage->load($nodes[0]->id());
$this->assertEqual($child->id(), $child->book['bid'], 'Child node book ID updated when parent is deleted.');
// 3rd-level children should now be 2nd-level.
$second = $node_storage->load($nodes[1]->id());
$this->assertEqual($child->id(), $second->book['bid'], '3rd-level child node is now second level when top-level node is deleted.');
}
/**
* Tests outline of a book.
*/
public function testBookOutline() {
$this->drupalLogin($this->bookAuthor);
// Create new node not yet a book.
$empty_book = $this->drupalCreateNode(array('type' => 'book'));
$this->drupalGet('node/' . $empty_book->id() . '/outline');
$this->assertNoLink(t('Book outline'), 'Book Author is not allowed to outline');
$this->drupalLogin($this->adminUser);
$this->drupalGet('node/' . $empty_book->id() . '/outline');
$this->assertRaw(t('Book outline'));
$this->assertOptionSelected('edit-book-bid', 0, 'Node does not belong to a book');
$this->assertNoLink(t('Remove from book outline'));
$edit = array();
$edit['book[bid]'] = '1';
$this->drupalPostForm('node/' . $empty_book->id() . '/outline', $edit, t('Add to book outline'));
$node = \Drupal::entityManager()->getStorage('node')->load($empty_book->id());
// Test the book array.
$this->assertEqual($node->book['nid'], $empty_book->id());
$this->assertEqual($node->book['bid'], $empty_book->id());
$this->assertEqual($node->book['depth'], 1);
$this->assertEqual($node->book['p1'], $empty_book->id());
$this->assertEqual($node->book['pid'], '0');
// Create new book.
$this->drupalLogin($this->bookAuthor);
$book = $this->createBookNode('new');
$this->drupalLogin($this->adminUser);
$this->drupalGet('node/' . $book->id() . '/outline');
$this->assertRaw(t('Book outline'));
$this->clickLink(t('Remove from book outline'));
$this->assertRaw(t('Are you sure you want to remove %title from the book hierarchy?', array('%title' => $book->label())));
// Create a new node and set the book after the node was created.
$node = $this->drupalCreateNode(array('type' => 'book'));
$edit = array();
$edit['book[bid]'] = $node->id();
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$node = \Drupal::entityManager()->getStorage('node')->load($node->id());
// Test the book array.
$this->assertEqual($node->book['nid'], $node->id());
$this->assertEqual($node->book['bid'], $node->id());
$this->assertEqual($node->book['depth'], 1);
$this->assertEqual($node->book['p1'], $node->id());
$this->assertEqual($node->book['pid'], '0');
// Test the form itself.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertOptionSelected('edit-book-bid', $node->id());
}
/**
* Tests that saveBookLink() returns something.
*/
public function testSaveBookLink() {
$book_manager = \Drupal::service('book.manager');
// Mock a link for a new book.
$link = array('nid' => 1, 'has_children' => 0, 'original_bid' => 0, 'parent_depth_limit' => 8, 'pid' => 0, 'weight' => 0, 'bid' => 1);
$new = TRUE;
// Save the link.
$return = $book_manager->saveBookLink($link, $new);
// Add the link defaults to $link so we have something to compare to the return from saveBookLink().
$link += $book_manager->getLinkDefaults($link['nid']);
// Test the return from saveBookLink.
$this->assertEqual($return, $link);
}
/**
* Tests the listing of all books.
*/
public function testBookListing() {
// Create a new book.
$this->createBook();
// Must be a user with 'node test view' permission since node_access_test is installed.
$this->drupalLogin($this->webUser);
// Load the book page and assert the created book title is displayed.
$this->drupalGet('book');
$this->assertText($this->book->label(), 'The book title is displayed on the book listing page.');
}
/**
* Tests the administrative listing of all books.
*/
public function testAdminBookListing() {
// Create a new book.
$this->createBook();
// Load the book page and assert the created book title is displayed.
$this->drupalLogin($this->adminUser);
$this->drupalGet('admin/structure/book');
$this->assertText($this->book->label(), 'The book title is displayed on the administrative book listing page.');
}
/**
* Tests the administrative listing of all book pages in a book.
*/
public function testAdminBookNodeListing() {
// Create a new book.
$this->createBook();
$this->drupalLogin($this->adminUser);
// Load the book page list and assert the created book title is displayed
// and action links are shown on list items.
$this->drupalGet('admin/structure/book/' . $this->book->id());
$this->assertText($this->book->label(), 'The book title is displayed on the administrative book listing page.');
$elements = $this->xpath('//table//ul[@class="dropbutton"]/li/a');
$this->assertEqual((string) $elements[0], 'View', 'View link is found from the list.');
}
/**
* Ensure the loaded book in hook_node_load() does not depend on the user.
*/
public function testHookNodeLoadAccess() {
\Drupal::service('module_installer')->install(['node_access_test']);
// Ensure that the loaded book in hook_node_load() does NOT depend on the
// current user.
$this->drupalLogin($this->bookAuthor);
$this->book = $this->createBookNode('new');
// Reset any internal static caching.
$node_storage = \Drupal::entityManager()->getStorage('node');
$node_storage->resetCache();
// Log in as user without access to the book node, so no 'node test view'
// permission.
// @see node_access_test_node_grants().
$this->drupalLogin($this->webUserWithoutNodeAccess);
$book_node = $node_storage->load($this->book->id());
$this->assertTrue(!empty($book_node->book));
$this->assertEqual($book_node->book['bid'], $this->book->id());
// Reset the internal cache to retrigger the hook_node_load() call.
$node_storage->resetCache();
$this->drupalLogin($this->webUser);
$book_node = $node_storage->load($this->book->id());
$this->assertTrue(!empty($book_node->book));
$this->assertEqual($book_node->book['bid'], $this->book->id());
}
/**
* Tests the book navigation block when book is unpublished.
*
* There was a fatal error with "Show block only on book pages" block mode.
*/
public function testBookNavigationBlockOnUnpublishedBook() {
// Create a new book.
$this->createBook();
// Create administrator user.
$administratorUser = $this->drupalCreateUser(['administer blocks', 'administer nodes', 'bypass node access']);
$this->drupalLogin($administratorUser);
// Enable the block with "Show block only on book pages" mode.
$this->drupalPlaceBlock('book_navigation', ['block_mode' => 'book pages']);
// Unpublish book node.
$edit = [];
$this->drupalPostForm('node/' . $this->book->id() . '/edit', $edit, t('Save and unpublish'));
// Test node page.
$this->drupalGet('node/' . $this->book->id());
$this->assertText($this->book->label(), 'Unpublished book with "Show block only on book pages" book navigation settings.');
}
}

View file

@ -19,14 +19,14 @@ class BookRelationshipTest extends ViewTestBase {
*
* @var array
*/
public static $testViews = array('test_book_view');
public static $testViews = ['test_book_view'];
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('book_test_views', 'book', 'views');
public static $modules = ['book_test_views', 'book', 'views'];
/**
* A book node.
@ -50,14 +50,14 @@ class BookRelationshipTest extends ViewTestBase {
// Create users.
$this->bookAuthor = $this->drupalCreateUser(
array(
[
'create new books',
'create book content',
'edit own book content',
'add content to books',
)
]
);
ViewTestData::createTestViews(get_class($this), array('book_test_views'));
ViewTestData::createTestViews(get_class($this), ['book_test_views']);
}
/**
@ -70,7 +70,7 @@ class BookRelationshipTest extends ViewTestBase {
$this->book = $this->createBookNode('new');
$book = $this->book;
$nodes = array();
$nodes = [];
// Node 0.
$nodes[] = $this->createBookNode($book->id());
// Node 1.
@ -110,7 +110,7 @@ class BookRelationshipTest extends ViewTestBase {
// Used to ensure that when sorted nodes stay in same order.
static $number = 0;
$edit = array();
$edit = [];
$edit['title[0][value]'] = $number . ' - SimpleTest test node ' . $this->randomMachineName(10);
$edit['body[0][value]'] = 'SimpleTest test body ' . $this->randomMachineName(32) . ' ' . $this->randomMachineName(32);
$edit['book[bid]'] = $book_nid;