Skip to content
Snippets Groups Projects
Commit 68d2dc4a authored by Brian Canini's avatar Brian Canini
Browse files

applying patch

- Book outline not limited to allowed content types
parent 527e0887
No related branches found
No related tags found
No related merge requests found
......@@ -271,6 +271,7 @@
"patches": {
"drupal/core": {
"2799049": "patches/role_based_email_access-2799049-d87.patch",
"2862291": "https://www.drupal.org/files/issues/2019-07-02/2862291-21.patch",
"2949017": "https://www.drupal.org/files/issues/2019-12-12/2949017-59.patch"
},
"drupal/better_exposed_filters": {
......
......@@ -3701,6 +3701,7 @@
},
"patches_applied": {
"2799049": "patches/role_based_email_access-2799049-d87.patch",
"2862291": "https://www.drupal.org/files/issues/2019-07-02/2862291-21.patch",
"2949017": "https://www.drupal.org/files/issues/2019-12-12/2949017-59.patch"
}
},
......
......@@ -5,6 +5,10 @@ Patches applied to this directory:
Source: patches/role_based_email_access-2799049-d87.patch
2862291
Source: https://www.drupal.org/files/issues/2019-07-02/2862291-21.patch
2949017
Source: https://www.drupal.org/files/issues/2019-12-12/2949017-59.patch
......
......@@ -177,78 +177,86 @@ public function addFormElements(array $form, FormStateInterface $form_state, Nod
if ($form_state->hasValue('book')) {
$node->book = $form_state->getValue('book');
}
$form['book'] = [
'#type' => 'details',
'#title' => $this->t('Book outline'),
'#weight' => 10,
'#open' => !$collapsed,
'#group' => 'advanced',
'#attributes' => [
'class' => ['book-outline-form'],
],
'#attached' => [
'library' => ['book/drupal.book'],
],
'#tree' => TRUE,
];
foreach (['nid', 'has_children', 'original_bid', 'parent_depth_limit'] as $key) {
$form['book'][$key] = [
'#type' => 'value',
'#value' => $node->book[$key],
$config = \Drupal::configFactory()->getEditable('book.settings');
$allowed_types = $config->get('allowed_types');
if (in_array($node->getType(), $allowed_types)) {
$form['book'] = [
'#type' => 'details',
'#title' => $this->t('Book outline'),
'#weight' => 10,
'#open' => !$collapsed,
'#group' => 'advanced',
'#attributes' => [
'class' => ['book-outline-form'],
],
'#attached' => [
'library' => ['book/drupal.book'],
],
'#tree' => TRUE,
];
}
$form['book']['pid'] = $this->addParentSelectFormElements($node->book);
// @see \Drupal\book\Form\BookAdminEditForm::bookAdminTableTree(). The
// weight may be larger than 15.
$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 = [];
$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
// moved.
$options[$node->id()] = $node->label();
}
else {
foreach ($this->getAllBooks() as $book) {
$options[$book['nid']] = $book['title'];
foreach (['nid', 'has_children', 'original_bid', 'parent_depth_limit'] as $key) {
$form['book'][$key] = [
'#type' => 'value',
'#value' => $node->book[$key],
];
}
}
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 = [$nid => $this->t('- Create a new book -')] + $options;
}
if (!$node->book['bid']) {
// The node is not currently in the hierarchy.
$options = [0 => $this->t('- None -')] + $options;
$form['book']['pid'] = $this->addParentSelectFormElements($node->book);
// @see \Drupal\book\Form\BookAdminEditForm::bookAdminTableTree(). The
// weight may be larger than 15.
$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 = [];
$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
// moved.
$options[$node->id()] = $node->label();
}
else {
foreach ($this->getAllBooks() as $book) {
$options[$book['nid']] = $book['title'];
}
}
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 = [$nid => $this->t('- Create a new book -')] + $options;
}
if (!$node->book['bid']) {
// The node is not currently in the hierarchy.
$options = [0 => $this->t('- None -')] + $options;
}
// Add a drop-down to select the destination book.
$form['book']['bid'] = [
'#type' => 'select',
'#title' => $this->t('Book'),
'#default_value' => $node->book['bid'],
'#options' => $options,
'#access' => (bool) $options,
'#description' => $this->t('Your page will be a part of the selected book.'),
'#weight' => -5,
'#attributes' => ['class' => ['book-title-select']],
'#ajax' => [
'callback' => 'book_form_update',
'wrapper' => 'edit-book-plid-wrapper',
'effect' => 'fade',
'speed' => 'fast',
],
];
}
// Add a drop-down to select the destination book.
$form['book']['bid'] = [
'#type' => 'select',
'#title' => $this->t('Book'),
'#default_value' => $node->book['bid'],
'#options' => $options,
'#access' => (bool) $options,
'#description' => $this->t('Your page will be a part of the selected book.'),
'#weight' => -5,
'#attributes' => ['class' => ['book-title-select']],
'#ajax' => [
'callback' => 'book_form_update',
'wrapper' => 'edit-book-plid-wrapper',
'effect' => 'fade',
'speed' => 'fast',
],
];
return $form;
}
......
......@@ -5,6 +5,7 @@
use Drupal\book\BookManager;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Tests\UnitTestCase;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
* @coversDefaultClass \Drupal\book\BookManager
......@@ -54,15 +55,68 @@ class BookManagerTest extends UnitTestCase {
*/
protected $bookOutlineStorage;
/**
* The mocked form state
*
* @var \Drupal\Core\Form\FormState
*/
protected $form_state;
/**
* The mocked node Interface.
*
* @var \Drupal\node\NodeInterface
*/
protected $node;
/**
* The mocked User
*
* @var \Drupal\user\Entity\User
*/
protected $account;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
$book_id = [
'nid' => 'new',
'has_children' => 0,
'original_bid' => 0,
'parent_depth_limit' => 0,
'bid' => 0,
'pid' => 0,
'weight' => 0,
'parent_depth_limit' => 8,
'options' => [],
];
$this->form_state = $this->getMockBuilder('Drupal\Core\Form\FormState')
->disableOriginalConstructor()->disableOriginalConstructor()
->setMethods(['hasValue', 'getValue'])->getMock();
$this->form_state->expects($this->any())
->method('getValue')
->willReturn($book_id);
$this->node = $this->getMockBuilder('Drupal\node\NodeInterface')
->disableOriginalConstructor()->getMock();
$this->node->book = $book_id;
$this->account = $this->getMockBuilder('Drupal\user\Entity\User')
->disableOriginalConstructor()->getMock();
$this->translation = $this->getStringTranslationStub();
$this->configFactory = $this->getConfigFactoryStub([]);
$config = [
'book.settings' => [
'allowed_types' => [
'page'
]
]
];
$this->configFactory = $this->getConfigFactoryStub($config);
$this->bookOutlineStorage = $this->createMock('Drupal\book\BookOutlineStorageInterface');
$this->renderer = $this->createMock('\Drupal\Core\Render\RendererInterface');
$container = new ContainerBuilder();
$container->set('config.factory', $this->configFactory);
\Drupal::setContainer($container);
$this->bookManager = new BookManager($this->entityTypeManager, $this->translation, $this->configFactory, $this->bookOutlineStorage, $this->renderer);
}
......@@ -115,4 +169,30 @@ public function providerTestGetBookParents() {
];
}
/**
* Testing the Book Outline form element in node add page form.
* When the Book setting is enabled for the Content Type 'Page'.
*/
public function testAddFormElementsNodeAddWithBook() {
$form = [];
$this->node->expects($this->any())
->method('getType')
->willReturn('page');
$addform = $this->bookManager->addFormElements($form, $this->form_state, $this->node, $this->account);
$this->assertArrayHasKey('book', $addform);
}
/**
* Testing the Book Outline form element in node add article form.
* When the Book setting is not enabled for the Content Type 'Article'
*/
public function testAddFormElementsNodeAddWithoutBook() {
$form = [];
$this->node->expects($this->any())
->method('getType')
->willReturn('artilce');
$addform = $this->bookManager->addFormElements($form, $this->form_state, $this->node, $this->account);
$this->assertArrayNotHasKey('book', $addform);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment