diff --git a/documentation/development.md b/documentation/development.md index 869427a70..652b6564a 100644 --- a/documentation/development.md +++ b/documentation/development.md @@ -305,3 +305,25 @@ final class YourEntityImageBuilder implements OGImageBuilderInterface { } ``` + + +## First paragraph grey alter + +There are some paragraphs that we want to "blend" with the hero-block if they are directly after the hero such as +searches. Good example of this kind of search is `unit_search`. The grey background should continue from hero to the +paragraph seamlessly and for paragraphs that are usable on all instances this is done in the `helfi_platform_config`. +These paragraphs can be found listed in the `$paragraphs_with_grey_bg` variable in `HeroBlock.php`. + +There can be paragraphs that we want to function this way, but they are instance specific. For them to be able to +function the same way you need to use the `first_paragraph_grey_alter` on that instance that uses the paragraph. + +Here is an example on how this is done in front page instance (helfi_etusivu custom module, helfi_etusivu.module file): + +```php +/** +* Implements hook_first_paragraph_grey_alter(). +*/ +function helfi_etusivu_first_paragraph_grey_alter(array &$paragraphs): void { + $paragraphs[] = 'news_archive'; +} +``` diff --git a/helfi_platform_config.api.php b/helfi_platform_config.api.php new file mode 100644 index 000000000..0eb428406 --- /dev/null +++ b/helfi_platform_config.api.php @@ -0,0 +1,25 @@ +update('helfi_eu_cookie_compliance'); -} \ No newline at end of file +} diff --git a/src/Plugin/Block/ContentBlockBase.php b/src/Plugin/Block/ContentBlockBase.php index b55fbba67..64876af2d 100644 --- a/src/Plugin/Block/ContentBlockBase.php +++ b/src/Plugin/Block/ContentBlockBase.php @@ -7,6 +7,7 @@ use Drupal\Core\Block\BlockBase; use Drupal\Core\Cache\Cache; use Drupal\Core\Entity\EntityTypeManagerInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\helfi_platform_config\EntityVersionMatcher; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -30,6 +31,13 @@ class ContentBlockBase extends BlockBase implements ContainerFactoryPluginInterf */ protected EntityVersionMatcher $entityVersionMatcher; + /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected ModuleHandlerInterface $moduleHandler; + /** * {@inheritdoc} */ @@ -39,10 +47,12 @@ public function __construct( $plugin_definition, EntityTypeManagerInterface $entity_type_manager, EntityVersionMatcher $entity_version_matcher, + ModuleHandlerInterface $module_handler, ) { parent::__construct($configuration, $plugin_id, $plugin_definition); $this->entityTypeManager = $entity_type_manager; $this->entityVersionMatcher = $entity_version_matcher; + $this->moduleHandler = $module_handler; } /** @@ -60,6 +70,7 @@ public static function create( $plugin_definition, $container->get('entity_type.manager'), $container->get('helfi_platform_config.entity_version_matcher'), + $container->get('module_handler'), ); } diff --git a/src/Plugin/Block/HeroBlock.php b/src/Plugin/Block/HeroBlock.php index 6ebd5270b..22f754308 100644 --- a/src/Plugin/Block/HeroBlock.php +++ b/src/Plugin/Block/HeroBlock.php @@ -56,6 +56,9 @@ public function build() : array { 'service_list_search', ]; + // Let modules alter the array of paragraphs with grey background. + $this->moduleHandler->alter('first_paragraph_grey', $paragraphs_with_grey_bg); + if ( $paragraph instanceof ParagraphInterface && in_array($paragraph->getType(), $paragraphs_with_grey_bg)