Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
custom_book_block
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
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
project
custom_book_block
Commits
2b0d53bb
Commit
2b0d53bb
authored
1 year ago
by
Simon Bäse
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3400698
by artemboiko, simonbaese, beder, MegaKeegMan: Start level and active branch of tree
parent
4ea1bdf3
No related branches found
No related tags found
1 merge request
!7
Issue #3400698: Add start level configuration
Pipeline
#63216
passed
1 year ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/ExpandBookManager.php
+9
-2
9 additions, 2 deletions
src/ExpandBookManager.php
src/Plugin/Block/CustomBookNavigationBlock.php
+18
-5
18 additions, 5 deletions
src/Plugin/Block/CustomBookNavigationBlock.php
with
27 additions
and
7 deletions
src/ExpandBookManager.php
+
9
−
2
View file @
2b0d53bb
...
...
@@ -61,7 +61,7 @@ class ExpandBookManager extends BookManager {
/**
* {@inheritdoc}
*/
public
function
bookTreeAllData
(
$bid
,
$link
=
NULL
,
$max_depth
=
NULL
,
$always_expand
=
0
)
{
public
function
bookTreeAllData
(
$bid
,
$link
=
NULL
,
$max_depth
=
NULL
,
$start_level
=
NULL
,
$always_expand
=
0
)
{
$tree
=
&
drupal_static
(
__METHOD__
,
[]);
$language_interface
=
$this
->
languageManager
->
getCurrentLanguage
();
...
...
@@ -77,7 +77,7 @@ class ExpandBookManager extends BookManager {
if
(
!
isset
(
$tree
[
$cid
]))
{
// If the tree data was not in the static cache, build $tree_parameters.
$tree_parameters
=
[
'min_depth'
=>
1
,
'min_depth'
=>
$start_level
??
1
,
'max_depth'
=>
$max_depth
,
];
...
...
@@ -95,6 +95,13 @@ class ExpandBookManager extends BookManager {
$tree_parameters
[
'active_trail'
][]
=
$nid
;
}
if
(
$start_level
&&
$start_level
>
1
)
{
$book_link
=
$this
->
loadBookLink
(
$nid
);
if
(
!
empty
(
$book_link
[
'p'
.
$start_level
])
&&
$book_link
[
'p'
.
$start_level
]
>
0
)
{
$tree_parameters
[
'conditions'
][
'p'
.
$start_level
]
=
$book_link
[
'p'
.
$start_level
];
}
}
// Build the tree using the parameters; the resulting tree will be cached.
$tree
[
$cid
]
=
$this
->
bookTreeBuild
(
$bid
,
$tree_parameters
);
}
...
...
This diff is collapsed.
Click to expand it.
src/Plugin/Block/CustomBookNavigationBlock.php
+
18
−
5
View file @
2b0d53bb
...
...
@@ -26,6 +26,7 @@ class CustomBookNavigationBlock extends BookNavigationBlock {
return
[
'block_mode'
=>
'all pages'
,
'target_book'
=>
''
,
'start_level'
=>
1
,
'max_levels'
=>
''
,
'always_expand'
=>
1
,
];
...
...
@@ -57,6 +58,14 @@ class CustomBookNavigationBlock extends BookNavigationBlock {
'#description'
=>
$this
->
t
(
'If set to zero, all levels will be shown.'
),
];
$form
[
'start_level'
]
=
[
'#type'
=>
'number'
,
'#title'
=>
$this
->
t
(
'Start level'
),
'#min'
=>
1
,
'#default_value'
=>
$this
->
configuration
[
'start_level'
],
'#description'
=>
$this
->
t
(
'Start level, filter tree, show only active branch.'
),
];
$form
[
'always_expand'
]
=
[
'#type'
=>
'checkbox'
,
'#title'
=>
$this
->
t
(
'Always expand the menu'
),
...
...
@@ -75,6 +84,7 @@ class CustomBookNavigationBlock extends BookNavigationBlock {
$this
->
configuration
[
'target_book'
]
=
$form_state
->
getValue
(
'target_book'
);
$this
->
configuration
[
'max_levels'
]
=
$form_state
->
getValue
(
'max_levels'
);
$this
->
configuration
[
'start_level'
]
=
$form_state
->
getValue
(
'start_level'
);
$this
->
configuration
[
'always_expand'
]
=
$form_state
->
getValue
(
'always_expand'
);
}
...
...
@@ -94,6 +104,7 @@ class CustomBookNavigationBlock extends BookNavigationBlock {
}
$max_levels
=
$this
->
configuration
[
'max_levels'
]
?:
NULL
;
$start_level
=
$this
->
configuration
[
'start_level'
]
?:
NULL
;
$target_book_id
=
$this
->
configuration
[
'target_book'
];
$always_expand
=
$this
->
configuration
[
'always_expand'
];
...
...
@@ -121,7 +132,7 @@ class CustomBookNavigationBlock extends BookNavigationBlock {
}
else
{
// Retrieve the full menu, to the specified depth.
$data
=
$book_manager
->
bookTreeAllData
(
$book_id
,
$book
,
$max_levels
,
$always_expand
);
$data
=
$book_manager
->
bookTreeAllData
(
$book_id
,
$book
,
$max_levels
,
$start_level
,
$always_expand
);
$book_menus
[
$book_id
]
=
$book_manager
->
bookTreeOutput
(
$data
);
$book_menus
[
$book_id
][
'#items'
][
$book_id
][
'in_active_trail'
]
=
FALSE
;
if
(
$book_menus
[
$book_id
][
'#items'
][
$book_id
][
'original_link'
][
'bid'
]
==
$current_book_id
)
{
...
...
@@ -157,12 +168,14 @@ class CustomBookNavigationBlock extends BookNavigationBlock {
// Only show the block if the user has view access for the top-level node.
if
(
$nid
)
{
$tree
=
$book_manager
->
bookTreeAllData
(
$node
->
book
[
'bid'
],
$node
->
book
,
$max_levels
,
$always_expand
);
$tree
=
$book_manager
->
bookTreeAllData
(
$node
->
book
[
'bid'
],
$node
->
book
,
$max_levels
,
$start_level
,
$always_expand
);
// There should only be one element at the top level.
$data
=
array_shift
(
$tree
);
$below
=
$book_manager
->
bookTreeOutput
(
$data
[
'below'
]);
if
(
!
empty
(
$below
))
{
return
$below
;
if
(
!
empty
(
$data
[
'below'
]))
{
$below
=
$book_manager
->
bookTreeOutput
(
$data
[
'below'
]);
if
(
!
empty
(
$below
))
{
return
$below
;
}
}
}
}
...
...
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