Skip to content
Snippets Groups Projects
Commit 6fa7c7c0 authored by Stephen Mustgrave's avatar Stephen Mustgrave
Browse files

Resolve #2781111 "Convert booknavigationblock to"

parent 614c2271
No related branches found
Tags 7.x-3.2
No related merge requests found
......@@ -9,6 +9,7 @@ use Drupal\Core\Cache\Cache;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Plugin\Context\EntityContextDefinition;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\node\NodeInterface;
......@@ -20,7 +21,14 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
#[Block(
id: "book_navigation",
admin_label: new TranslatableMarkup("Book navigation"),
category: new TranslatableMarkup("Menus")
category: new TranslatableMarkup("Menus"),
context_definitions: [
'node' => new EntityContextDefinition(
data_type: 'entity:node',
label: new TranslatableMarkup("Node"),
required: FALSE,
),
]
)]
class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInterface {
......@@ -106,7 +114,7 @@ class BookNavigationBlock extends BlockBase implements ContainerFactoryPluginInt
public function build(): array {
$current_bid = 0;
$node = $this->routeMatch->getParameter('node');
$node = $this->getContextValue('node');
if ($node instanceof NodeInterface && !empty($node->book['bid'])) {
$current_bid = $node->book['bid'];
}
......
......@@ -7,6 +7,7 @@ namespace Drupal\Tests\book\Functional;
use Drupal\Core\Cache\Cache;
use Drupal\Tests\BrowserTestBase;
use Drupal\user\RoleInterface;
use Drupal\user\UserInterface;
/**
* Create a book, add pages, and test book interface.
......@@ -41,21 +42,21 @@ class BookTest extends BrowserTestBase {
*
* @var \Drupal\user\UserInterface
*/
protected $webUser;
protected UserInterface $webUser;
/**
* A user with permission to create and edit books and to administer blocks.
*
* @var \Drupal\user\UserInterface
*/
protected $adminUser;
protected UserInterface $adminUser;
/**
* A user without the 'node test view' permission.
*
* @var \Drupal\user\UserInterface
*/
protected $webUserWithoutNodeAccess;
protected UserInterface $webUserWithoutNodeAccess;
/**
* {@inheritdoc}
......@@ -391,9 +392,12 @@ class BookTest extends BrowserTestBase {
/**
* Tests the book navigation block when an access module is installed.
*/
public function testNavigationBlockOnAccessModuleInstalled() {
public function testNavigationBlockOnAccessModuleInstalled(): void {
$this->drupalLogin($this->adminUser);
$block = $this->drupalPlaceBlock('book_navigation', ['block_mode' => 'book pages']);
$block = $this->drupalPlaceBlock('book_navigation', [
'block_mode' => 'book pages',
'context_mapping' => ['node' => '@node.node_route_context:node'],
]);
// Give anonymous users the permission 'node test view'.
$edit = [];
......@@ -422,6 +426,10 @@ class BookTest extends BrowserTestBase {
/**
* Tests the access for deleting top-level book nodes.
*
* @throws \Behat\Mink\Exception\ExpectationException
* @throws \Drupal\Core\Entity\EntityStorageException
* @throws \Drupal\Core\Entity\EntityMalformedException
*/
public function testBookDelete() {
$node_storage = $this->container->get('entity_type.manager')->getStorage('node');
......
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