Skip to content
Snippets Groups Projects
Commit 06ed3286 authored by Davyd Burianuvatyi's avatar Davyd Burianuvatyi
Browse files

Issue #3343373: Create "Related articles" block when module are installing

parent 59336417
No related branches found
No related tags found
1 merge request!6Resolve #3343373 "Initial implementation"
......@@ -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.
......
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