upgrades core to 8.4.2
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -220,7 +220,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,
|
||||
|
||||
@@ -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.';
|
||||
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,7 +8,8 @@ use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
|
||||
* Drupal 6 book source.
|
||||
*
|
||||
* @MigrateSource(
|
||||
* id = "d6_book"
|
||||
* id = "d6_book",
|
||||
* source_module = "book"
|
||||
* )
|
||||
*/
|
||||
class Book extends DrupalSqlBase {
|
||||
|
||||
Reference in New Issue
Block a user