Update Composer, update everything

This commit is contained in:
Oliver Davies 2018-11-23 12:29:20 +00:00
parent ea3e94409f
commit dda5c284b6
19527 changed files with 1135420 additions and 351004 deletions

View file

@ -275,6 +275,20 @@ class BookManager implements BookManagerInterface {
// handle it here if it did not.
$node->book['pid'] = $node->book['bid'];
}
// Prevent changes to the book outline if the node being saved is not the
// default revision.
$updated = FALSE;
if (!$new) {
$original = $this->loadBookLink($node->id(), FALSE);
if ($node->book['bid'] != $original['bid'] || $node->book['pid'] != $original['pid'] || $node->book['weight'] != $original['weight']) {
$updated = TRUE;
}
}
if (($new || $updated) && !$node->isDefaultRevision()) {
return FALSE;
}
return $this->saveBookLink($node->book, $new);
}

View file

@ -6,7 +6,6 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\node\NodeInterface;
/**
* Provides an interface defining a book manager.
*/
@ -247,7 +246,8 @@ interface BookManagerInterface {
* A data structure representing the tree as returned from buildBookOutlineData.
*
* @return array
* A structured array to be rendered by drupal_render().
* A structured array to be rendered by
* \Drupal\Core\Render\RendererInterface::render().
*
* @see \Drupal\Core\Menu\MenuLinkTree::build
*/

View file

@ -39,12 +39,14 @@ class BookOutline {
if ($book_link['pid'] == 0) {
return NULL;
}
// Assigning the array to $flat resets the array pointer for use with each().
$flat = $this->bookManager->bookTreeGetFlat($book_link);
reset($flat);
$curr = NULL;
do {
$prev = $curr;
list($key, $curr) = each($flat);
$key = key($flat);
$curr = current($flat);
next($flat);
} while ($key && $key != $book_link['nid']);
if ($key == $book_link['nid']) {
@ -78,10 +80,11 @@ class BookOutline {
* $book_link.
*/
public function nextLink(array $book_link) {
// Assigning the array to $flat resets the array pointer for use with each().
$flat = $this->bookManager->bookTreeGetFlat($book_link);
reset($flat);
do {
list($key,) = each($flat);
$key = key($flat);
next($flat);
} while ($key && $key != $book_link['nid']);
if ($key == $book_link['nid']) {

View file

@ -69,7 +69,7 @@ interface BookOutlineStorageInterface {
public function delete($nid);
/**
* Loads book's children using it's parent ID.
* Loads book's children using its parent ID.
*
* @param int $pid
* The book's parent ID.
@ -110,7 +110,6 @@ interface BookOutlineStorageInterface {
*/
public function insert($link, $parents);
/**
* Updates book reference for links that were moved between books.
*

View file

@ -154,7 +154,7 @@ class BookController extends ControllerBase {
// @todo Convert the custom export functionality to serializer.
if (!method_exists($this->bookExport, $method)) {
drupal_set_message(t('Unknown export format.'));
$this->messenger()->addStatus(t('Unknown export format.'));
throw new NotFoundHttpException();
}

View file

@ -15,6 +15,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form for administering a single book's hierarchy.
*
* @internal
*/
class BookAdminEditForm extends FormBase {
@ -125,7 +127,7 @@ class BookAdminEditForm extends FormBase {
}
}
drupal_set_message($this->t('Updated book %title.', ['%title' => $form['#node']->label()]));
$this->messenger()->addStatus($this->t('Updated book %title.', ['%title' => $form['#node']->label()]));
}
/**
@ -220,7 +222,7 @@ class BookAdminEditForm extends FormBase {
}
$form[$id]['title'] = [
'#prefix' => !empty($indentation) ? drupal_render($indentation) : '',
'#prefix' => !empty($indentation) ? \Drupal::service('renderer')->render($indentation) : '',
'#type' => 'textfield',
'#default_value' => $data['link']['title'],
'#maxlength' => 255,

View file

@ -5,7 +5,7 @@ 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\EntityRepositoryInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
@ -13,6 +13,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Displays the book outline form.
*
* @internal
*/
class BookOutlineForm extends ContentEntityForm {
@ -33,8 +35,8 @@ class BookOutlineForm extends ContentEntityForm {
/**
* Constructs a BookOutlineForm object.
*
* @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
* The entity manager.
* @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
* The entity repository.
* @param \Drupal\book\BookManagerInterface $book_manager
* The BookManager service.
* @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info
@ -42,8 +44,8 @@ class BookOutlineForm extends ContentEntityForm {
* @param \Drupal\Component\Datetime\TimeInterface $time
* The time service.
*/
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);
public function __construct(EntityRepositoryInterface $entity_repository, BookManagerInterface $book_manager, EntityTypeBundleInfoInterface $entity_type_bundle_info = NULL, TimeInterface $time = NULL) {
parent::__construct($entity_repository, $entity_type_bundle_info, $time);
$this->bookManager = $book_manager;
}
@ -52,7 +54,7 @@ class BookOutlineForm extends ContentEntityForm {
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('entity.manager'),
$container->get('entity.repository'),
$container->get('book.manager'),
$container->get('entity_type.bundle.info'),
$container->get('datetime.time')
@ -111,7 +113,7 @@ class BookOutlineForm extends ContentEntityForm {
);
$book_link = $form_state->getValue('book');
if (!$book_link['bid']) {
drupal_set_message($this->t('No changes were made'));
$this->messenger()->addStatus($this->t('No changes were made'));
return;
}
@ -119,15 +121,15 @@ class BookOutlineForm extends ContentEntityForm {
if ($this->bookManager->updateOutline($this->entity)) {
if (isset($this->entity->book['parent_mismatch']) && $this->entity->book['parent_mismatch']) {
// This will usually only happen when JS is disabled.
drupal_set_message($this->t('The post has been added to the selected book. You may now position it relative to other pages.'));
$this->messenger()->addStatus($this->t('The post has been added to the selected book. You may now position it relative to other pages.'));
$form_state->setRedirectUrl($this->entity->urlInfo('book-outline-form'));
}
else {
drupal_set_message($this->t('The book outline has been updated.'));
$this->messenger()->addStatus($this->t('The book outline has been updated.'));
}
}
else {
drupal_set_message($this->t('There was an error adding the post to the book.'), 'error');
$this->messenger()->addError($this->t('There was an error adding the post to the book.'));
}
}

View file

@ -10,6 +10,8 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Remove form for book module.
*
* @internal
*/
class BookRemoveForm extends ConfirmFormBase {
@ -101,7 +103,7 @@ class BookRemoveForm extends ConfirmFormBase {
public function submitForm(array &$form, FormStateInterface $form_state) {
if ($this->bookManager->checkNodeIsRemovable($this->node)) {
$this->bookManager->deleteFromBook($this->node->id());
drupal_set_message($this->t('The post has been removed from the book.'));
$this->messenger()->addStatus($this->t('The post has been removed from the book.'));
}
$form_state->setRedirectUrl($this->getCancelUrl());
}

View file

@ -7,6 +7,8 @@ use Drupal\Core\Form\FormStateInterface;
/**
* Configure book settings for this site.
*
* @internal
*/
class BookSettingsForm extends ConfigFormBase {

View file

@ -0,0 +1,19 @@
<?php
namespace Drupal\book\Plugin\Validation\Constraint;
use Symfony\Component\Validator\Constraint;
/**
* Validation constraint for changing the book outline in pending revisions.
*
* @Constraint(
* id = "BookOutline",
* label = @Translation("Book outline.", context = "Validation"),
* )
*/
class BookOutlineConstraint extends Constraint {
public $message = 'You can only change the book outline for the <em>published</em> version of this content.';
}

View file

@ -0,0 +1,77 @@
<?php
namespace Drupal\book\Plugin\Validation\Constraint;
use Drupal\book\BookManagerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* Constraint validator for changing the book outline in pending revisions.
*/
class BookOutlineConstraintValidator extends ConstraintValidator implements ContainerInjectionInterface {
/**
* The book manager.
*
* @var \Drupal\book\BookManagerInterface
*/
protected $bookManager;
/**
* Creates a new BookOutlineConstraintValidator instance.
*
* @param \Drupal\book\BookManagerInterface $book_manager
* The book manager.
*/
public function __construct(BookManagerInterface $book_manager) {
$this->bookManager = $book_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('book.manager')
);
}
/**
* {@inheritdoc}
*/
public function validate($entity, Constraint $constraint) {
if (isset($entity) && !$entity->isNew() && !$entity->isDefaultRevision()) {
/** @var \Drupal\Core\Entity\ContentEntityInterface $original */
$original = $this->bookManager->loadBookLink($entity->id(), FALSE) ?: [
'bid' => 0,
'weight' => 0,
];
if (empty($original['pid'])) {
$original['pid'] = -1;
}
if ($entity->book['bid'] != $original['bid']) {
$this->context->buildViolation($constraint->message)
->atPath('book.bid')
->setInvalidValue($entity)
->addViolation();
}
if ($entity->book['pid'] != $original['pid']) {
$this->context->buildViolation($constraint->message)
->atPath('book.pid')
->setInvalidValue($entity)
->addViolation();
}
if ($entity->book['weight'] != $original['weight']) {
$this->context->buildViolation($constraint->message)
->atPath('book.weight')
->setInvalidValue($entity)
->addViolation();
}
}
}
}

View file

@ -0,0 +1,63 @@
<?php
namespace Drupal\book\Plugin\migrate\source;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
/**
* Drupal 6 and 7 book source.
*
* @MigrateSource(
* id = "book",
* source_module = "book",
* )
*/
class Book extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('book', 'b')->fields('b', ['nid', 'bid']);
$query->join('menu_links', 'ml', 'b.mlid = ml.mlid');
$ml_fields = ['mlid', 'plid', 'weight', 'has_children', 'depth'];
foreach (range(1, 9) as $i) {
$field = "p$i";
$ml_fields[] = $field;
$query->orderBy('ml.' . $field);
}
return $query->fields('ml', $ml_fields);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['mlid']['type'] = 'integer';
$ids['mlid']['alias'] = 'ml';
return $ids;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'nid' => $this->t('Node ID'),
'bid' => $this->t('Book ID'),
'mlid' => $this->t('Menu link ID'),
'plid' => $this->t('Parent link ID'),
'weight' => $this->t('Weight'),
'p1' => $this->t('The first mlid in the materialized path. If N = depth, then pN must equal the mlid. If depth > 1 then p(N-1) must equal the parent link mlid. All pX where X > depth must equal zero. The columns p1 .. p9 are also called the parents.'),
'p2' => $this->t('The second mlid in the materialized path. See p1.'),
'p3' => $this->t('The third mlid in the materialized path. See p1.'),
'p4' => $this->t('The fourth mlid in the materialized path. See p1.'),
'p5' => $this->t('The fifth mlid in the materialized path. See p1.'),
'p6' => $this->t('The sixth mlid in the materialized path. See p1.'),
'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

@ -2,62 +2,20 @@
namespace Drupal\book\Plugin\migrate\source\d6;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
use Drupal\book\Plugin\migrate\source\Book as BookGeneral;
@trigger_error('Book is deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.x. Use \Drupal\book\Plugin\migrate\source\Book instead. See https://www.drupal.org/node/2947487 for more information.', E_USER_DEPRECATED);
/**
* Drupal 6 book source.
*
* @MigrateSource(
* id = "d6_book"
* id = "d6_book",
* source_module = "book"
* )
*
* @deprecated in Drupal 8.6.x, to be removed before Drupal 9.0.x. Use
* \Drupal\book\Plugin\migrate\source\Book instead. See
* https://www.drupal.org/node/2947487 for more information.
*/
class Book extends DrupalSqlBase {
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('book', 'b')->fields('b', ['nid', 'bid']);
$query->join('menu_links', 'ml', 'b.mlid = ml.mlid');
$ml_fields = ['mlid', 'plid', 'weight', 'has_children', 'depth'];
for ($i = 1; $i <= 9; $i++) {
$field = "p$i";
$ml_fields[] = $field;
$query->orderBy('ml.' . $field);
}
$query->fields('ml', $ml_fields);
return $query;
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['mlid']['type'] = 'integer';
$ids['mlid']['alias'] = 'ml';
return $ids;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'nid' => $this->t('Node ID'),
'bid' => $this->t('Book ID'),
'mlid' => $this->t('Menu link ID'),
'plid' => $this->t('Parent link ID'),
'weight' => $this->t('Weight'),
'p1' => $this->t('The first mlid in the materialized path. If N = depth, then pN must equal the mlid. If depth > 1 then p(N-1) must equal the parent link mlid. All pX where X > depth must equal zero. The columns p1 .. p9 are also called the parents.'),
'p2' => $this->t('The second mlid in the materialized path. See p1.'),
'p3' => $this->t('The third mlid in the materialized path. See p1.'),
'p4' => $this->t('The fourth mlid in the materialized path. See p1.'),
'p5' => $this->t('The fifth mlid in the materialized path. See p1.'),
'p6' => $this->t('The sixth mlid in the materialized path. See p1.'),
'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.'),
];
}
}
class Book extends BookGeneral {}

View file

@ -1,156 +0,0 @@
<?php
namespace Drupal\book\Tests\Views;
use Drupal\views\Tests\ViewTestBase;
use Drupal\views\Tests\ViewTestData;
/**
* Tests entity reference relationship data.
*
* @group book
*
* @see book_views_data()
*/
class BookRelationshipTest extends ViewTestBase {
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = ['test_book_view'];
/**
* Modules to install.
*
* @var array
*/
public static $modules = ['book_test_views', 'book', 'views'];
/**
* A book node.
*
* @var object
*/
protected $book;
/**
* A user with permission to create and edit books.
*
* @var object
*/
protected $bookAuthor;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
// Create users.
$this->bookAuthor = $this->drupalCreateUser(
[
'create new books',
'create book content',
'edit own book content',
'add content to books',
]
);
ViewTestData::createTestViews(get_class($this), ['book_test_views']);
}
/**
* Creates a new book with a page hierarchy.
*/
protected function createBook() {
// Create new book.
$this->drupalLogin($this->bookAuthor);
$this->book = $this->createBookNode('new');
$book = $this->book;
$nodes = [];
// Node 0.
$nodes[] = $this->createBookNode($book->id());
// Node 1.
$nodes[] = $this->createBookNode($book->id(), $nodes[0]->book['nid']);
// Node 2.
$nodes[] = $this->createBookNode($book->id(), $nodes[1]->book['nid']);
// Node 3.
$nodes[] = $this->createBookNode($book->id(), $nodes[2]->book['nid']);
// Node 4.
$nodes[] = $this->createBookNode($book->id(), $nodes[3]->book['nid']);
// Node 5.
$nodes[] = $this->createBookNode($book->id(), $nodes[4]->book['nid']);
// Node 6.
$nodes[] = $this->createBookNode($book->id(), $nodes[5]->book['nid']);
// Node 7.
$nodes[] = $this->createBookNode($book->id(), $nodes[6]->book['nid']);
$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 book 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().
// Used to ensure that when sorted nodes stay in same order.
static $number = 0;
$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;
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 using the views relationship.
*/
public function testRelationship() {
// Create new book.
// @var \Drupal\node\NodeInterface[] $nodes
$nodes = $this->createBook();
for ($i = 0; $i < 8; $i++) {
$this->drupalGet('test-book/' . $nodes[$i]->id());
for ($j = 0; $j < $i; $j++) {
$this->assertLink($nodes[$j]->label());
}
}
}
}