Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
book-2862291
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
book-2862291
Commits
6fa7c7c0
Commit
6fa7c7c0
authored
3 months ago
by
Stephen Mustgrave
Browse files
Options
Downloads
Patches
Plain Diff
Resolve
#2781111
"Convert booknavigationblock to"
parent
614c2271
No related branches found
Branches containing commit
Tags
7.x-3.2
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Plugin/Block/BookNavigationBlock.php
+10
-2
10 additions, 2 deletions
src/Plugin/Block/BookNavigationBlock.php
tests/src/Functional/BookTest.php
+13
-5
13 additions, 5 deletions
tests/src/Functional/BookTest.php
with
23 additions
and
7 deletions
src/Plugin/Block/BookNavigationBlock.php
+
10
−
2
View file @
6fa7c7c0
...
...
@@ -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'
];
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Functional/BookTest.php
+
13
−
5
View file @
6fa7c7c0
...
...
@@ -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'
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment