vlsuite-1.0.x-dev/vlsuite.module
vlsuite.module
<?php
/**
* @file
* VLSuite main module file.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Component\Utility\Html;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Display\EntityViewDisplayInterface;
use Drupal\layout_builder\Entity\LayoutEntityDisplayInterface;
/**
* Implements hook_help().
*/
function vlsuite_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.vlsuite':
$text = file_get_contents(__DIR__ . '/README.md');
if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
return '<pre>' . Html::escape($text) . '</pre>';
}
else {
// Use the Markdown filter to render the README.
$filter_manager = \Drupal::service('plugin.manager.filter');
$settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
$config = ['settings' => $settings];
$filter = $filter_manager->createInstance('markdown', $config);
return $filter->process($text, 'en');
}
}
return NULL;
}
/**
* Implements hook_entity_view_alter().
*/
function vlsuite_entity_view_alter(array &$build, EntityInterface $entity, EntityViewDisplayInterface $display) {
// Allow having a "fixed" content header & footer with no need to make an
// update on every change.
// Related:
// https://www.drupal.org/project/drupal/issues/3338369
// https://www.drupal.org/project/layout_builder_lock/issues/3240829
if ($display->getMode() == 'full' && $display instanceof LayoutEntityDisplayInterface && $display->isLayoutBuilderEnabled()) {
/* \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_view_repository */
$entity_view_repository = \Drupal::service('entity_display.repository');
/* \Drupal\Core\Entity\EntityViewBuilder $view_builder */
$view_builder = \Drupal::entityTypeManager()->getViewBuilder($entity->getEntityTypeId());
$view_mode_options = $entity_view_repository->getViewModeOptionsByBundle($entity->getEntityTypeId(), $entity->bundle());
if (!empty($view_mode_options['vlsuite_full_content_top'])) {
$build['vlsuite_full_content_top'] = $view_builder->view($entity, 'vlsuite_full_content_top');
$build['vlsuite_full_content_top']['#weight'] = -99999;
}
if (!empty($view_mode_options['vlsuite_full_content_bottom'])) {
$build['vlsuite_full_content_bottom'] = $view_builder->view($entity, 'vlsuite_full_content_bottom');
$build['vlsuite_full_content_bottom']['#weight'] = 99999;
}
}
}
