Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UHF-9741: News archive refresh #785

Merged
merged 3 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions documentation/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
```
25 changes: 25 additions & 0 deletions helfi_platform_config.api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @file
* HELfi platform config hooks.
*/

declare(strict_types=1);

/**
* @file
* Hooks provided by the HELfi platform config module.
*/

/**
* Modify the list of paragraphs of first-paragraph-grey.
*
* The paragraphs on the list will get the special class
* has-first-paragraph-gray.
*
* @param array $paragraphs
* Array of paragraph machine names.
*/
function hook_first_paragraph_grey_alter(array &$paragraphs) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ function helfi_eu_cookie_compliance_update_9011(): void {
function helfi_eu_cookie_compliance_update_9012(): void {
\Drupal::service('helfi_platform_config.config_update_helper')
->update('helfi_eu_cookie_compliance');
}
}
11 changes: 11 additions & 0 deletions src/Plugin/Block/ContentBlockBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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}
*/
Expand All @@ -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;
}

/**
Expand All @@ -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'),
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Plugin/Block/HeroBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down