Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lb_related_articles_blocks
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
lb_related_articles_blocks
Commits
06ed3286
Commit
06ed3286
authored
1 year ago
by
Davyd Burianuvatyi
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3343373
: Create "Related articles" block when module are installing
parent
59336417
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!6
Resolve #3343373 "Initial implementation"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lb_related_articles_blocks.install
+46
-0
46 additions, 0 deletions
lb_related_articles_blocks.install
with
46 additions
and
0 deletions
lb_related_articles_blocks.install
+
46
−
0
View file @
06ed3286
...
...
@@ -5,6 +5,52 @@
* Contains install and update functions for lb_related_articles_blocks module.
*/
use
Drupal\block_content
\Entity\BlockContent
;
use
Drupal\layout_builder
\SectionComponent
;
/**
* Implements hook_install().
*/
function
lb_related_articles_blocks_install
()
{
$entity_display_repository
=
\Drupal
::
service
(
'entity_display.repository'
);
$view_modes
=
$entity_display_repository
->
getViewModeOptionsByBundle
(
'node'
,
'article_lb'
);
foreach
(
array_keys
(
$view_modes
)
as
$view_mode
)
{
/** @var \Drupal\Core\Entity\Display\EntityViewDisplayInterface $view_display */
$view_display
=
$entity_display_repository
->
getViewDisplay
(
'node'
,
'article_lb'
,
$view_mode
);
if
(
$view_mode
==
'default'
)
{
$sections
=
$view_display
->
getThirdPartySetting
(
'layout_builder'
,
'sections'
);
foreach
(
$sections
as
&
$section
)
{
if
(
$section
->
getLayoutSettings
()[
'label'
]
!==
'Related Articles'
)
{
continue
;
}
$block_content
=
BlockContent
::
create
([
'type'
=>
'lb_related_articles'
,
'info'
=>
'Related articles'
,
'reusable'
=>
'0'
]);
$block_content
->
save
();
$uuid_service
=
\Drupal
::
service
(
'uuid'
);
$component
=
new
SectionComponent
(
$uuid_service
->
generate
(),
'blb_region_col_1'
,
[
'id'
=>
'inline_block:lb_related_articles'
,
'label'
=>
'Related articles'
,
'label_display'
=>
'0'
,
'provider'
=>
'layout_builder'
,
'view_mode'
=>
'full'
,
'block_revision_id'
=>
$block_content
->
getRevisionId
(),
]);
$section
->
appendComponent
(
$component
);
}
$view_display
->
setThirdPartySetting
(
'layout_builder'
,
'sections'
,
$sections
);
$view_display
->
save
();
}
}
}
/**
* Add contextual filter to views.
...
...
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