-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UHF-10191: Merge branch 'main' of https://github.com/City-of-Helsinki…
…/drupal-helfi-platform-config into UHF-10191
- Loading branch information
Showing
25 changed files
with
520 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(function (Drupal, drupalSettings) { | ||
Drupal.behaviors.hdbt_cookie_banner = { | ||
attach: function (context, settings) { | ||
|
||
// Todo initialize hdbt cookie banner. | ||
fetch(drupalSettings.hdbt_cookie_banner.apiUrl) | ||
.then(response => response.json()) | ||
.then(console.log) | ||
.catch(console.error) | ||
} | ||
} | ||
})(Drupal, drupalSettings); |
8 changes: 8 additions & 0 deletions
8
modules/hdbt_cookie_banner/config/schema/hdbt_cookie_banner.schema.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
hdbt_cookie_banner.settings: | ||
type: config_object | ||
label: HDBT cookie banner | ||
mapping: | ||
site_settings: | ||
type: string | ||
label: Site settings | ||
nullable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
name: 'HDBT cookie banner' | ||
type: module | ||
description: 'Drupal module for hdbt cookie banner.' | ||
core_version_requirement: ^10 || ^11 | ||
dependencies: | ||
- helfi_api_base:helfi_api_base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
hdbt_cookie_banner: | ||
js: | ||
assets/hdbt_cookie_banner.js: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
hdbt_cookie_banner.form: | ||
title: 'HDBT Cookie Banner' | ||
route_name: hdbt_cookie_banner.form | ||
parent: system.admin_config_system | ||
description: 'Configure HDBT Cookie Banner' | ||
weight: -10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains module hooks for hdbt cookie banner. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Drupal\Core\Url; | ||
use Drupal\hdbt_cookie_banner\Form\HdbtCookieBannerForm; | ||
use Drupal\helfi_api_base\Environment\EnvironmentResolverInterface; | ||
use Drupal\helfi_api_base\Environment\Project; | ||
|
||
/** | ||
* Implements hook_config_ignore_settings_alter(). | ||
*/ | ||
function hdbt_cookie_banner_config_ignore_settings_alter(array &$settings): void { | ||
$settings[] = HdbtCookieBannerForm::SETTINGS; | ||
} | ||
|
||
/** | ||
* Implements hook_page_attachments(). | ||
*/ | ||
function hdbt_cookie_banner_page_attachments(array &$attachments) : void { | ||
$attachments['#attached']['library'][] = 'hdbt_cookie_banner/hdbt_cookie_banner'; | ||
$attachments['#attached']['drupalSettings']['hdbt_cookie_banner'] = [ | ||
'apiUrl' => _hdbt_cookie_banner_get_api_url(), | ||
]; | ||
|
||
$config = \Drupal::configFactory()->get(HdbtCookieBannerForm::SETTINGS); | ||
$attachments['#cache']['tags'] = array_merge($attachments['#cache']['tags'] ?? [], $config->getCacheTags()); | ||
} | ||
|
||
/** | ||
* Gets HDBT cookie banner api url. | ||
*/ | ||
function _hdbt_cookie_banner_get_api_url(): string { | ||
$config = \Drupal::configFactory()->get(HdbtCookieBannerForm::SETTINGS); | ||
$language = \Drupal::languageManager()->getDefaultLanguage(); | ||
|
||
// Default to etusivu api url. | ||
if (empty($config->get('site_settings'))) { | ||
/** @var \Drupal\helfi_api_base\Environment\EnvironmentResolverInterface $resolver */ | ||
$resolver = \Drupal::service(EnvironmentResolverInterface::class); | ||
try { | ||
$environment = $resolver | ||
->getEnvironment(Project::ETUSIVU, $resolver->getActiveEnvironmentName()); | ||
|
||
return vsprintf("%s/api/cookie-banner", [ | ||
$environment->getUrl($language->getId()), | ||
]); | ||
} | ||
catch (InvalidArgumentException) { | ||
} | ||
} | ||
|
||
return Url::fromRoute('hdbt_cookie_banner.site_settings', options: [ | ||
'language' => $language, | ||
])->toString(); | ||
} |
2 changes: 2 additions & 0 deletions
2
modules/hdbt_cookie_banner/hdbt_cookie_banner.permissions.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
administer hdbt_cookie_banner: | ||
title: 'Administer hdbt cookie banner' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
hdbt_cookie_banner.form: | ||
path: '/admin/structure/hdbt-cookie-banner' | ||
defaults: | ||
_form: '\Drupal\hdbt_cookie_banner\Form\HdbtCookieBannerForm' | ||
_title: 'Administer hdbt cookie banner' | ||
requirements: | ||
_permission: 'administer hdbt_cookie_banner' | ||
|
||
hdbt_cookie_banner.site_settings: | ||
path: '/api/cookie-banner' | ||
defaults: | ||
_controller: '\Drupal\hdbt_cookie_banner\Controller\HdbtCookieBannerController::siteSettings' | ||
requirements: | ||
_access: 'TRUE' |
41 changes: 41 additions & 0 deletions
41
modules/hdbt_cookie_banner/src/Controller/HdbtCookieBannerController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\hdbt_cookie_banner\Controller; | ||
|
||
use Drupal\Component\Serialization\Json; | ||
use Drupal\Core\Cache\CacheableJsonResponse; | ||
use Drupal\Core\Config\ConfigFactoryInterface; | ||
use Drupal\Core\Controller\ControllerBase; | ||
use Drupal\hdbt_cookie_banner\Form\HdbtCookieBannerForm; | ||
|
||
/** | ||
* HDBT cookie banner controller. | ||
*/ | ||
class HdbtCookieBannerController extends ControllerBase { | ||
|
||
/** | ||
* Constructs a new instance. | ||
* | ||
* @param \Drupal\Core\Config\ConfigFactoryInterface $config | ||
* The config factory. | ||
*/ | ||
public function __construct(private readonly ConfigFactoryInterface $config) { | ||
} | ||
|
||
/** | ||
* Returns site settings. | ||
*/ | ||
public function siteSettings(): CacheableJsonResponse { | ||
$config = $this->config->get(HdbtCookieBannerForm::SETTINGS); | ||
|
||
$response = new CacheableJsonResponse(Json::decode($config->get('site_settings'))); | ||
$response->addCacheableDependency($config); | ||
$response->setMaxAge(600); | ||
$response->setPublic(); | ||
|
||
return $response; | ||
} | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
modules/hdbt_cookie_banner/src/Form/HdbtCookieBannerForm.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\hdbt_cookie_banner\Form; | ||
|
||
use Drupal\Core\Form\ConfigFormBase; | ||
use Drupal\Core\Form\FormStateInterface; | ||
|
||
/** | ||
* HDBT cookie banner form. | ||
*/ | ||
final class HdbtCookieBannerForm extends ConfigFormBase { | ||
|
||
/** | ||
* Config settings. | ||
*/ | ||
public const SETTINGS = 'hdbt_cookie_banner.settings'; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getFormId(): string { | ||
return 'hdbt_cookie_banner'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function getEditableConfigNames(): array { | ||
return [ | ||
self::SETTINGS, | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function buildForm(array $form, FormStateInterface $form_state): array { | ||
$form['site_settings'] = [ | ||
'#type' => 'textarea', | ||
'#title' => $this->t('Site settings', options: ['context' => 'hdbt cookie banner']), | ||
'#config_target' => self::SETTINGS . ":site_settings", | ||
]; | ||
|
||
return parent::buildForm($form, $form_state); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function validateForm(array &$form, FormStateInterface $form_state): void { | ||
parent::validateForm($form, $form_state); | ||
|
||
$values = $form_state->getValues(); | ||
|
||
if (!$this->isValidJson($values['site_settings'])) { | ||
$form_state->setErrorByName('site_settings', | ||
$this->t('Site settings must be valid JSON', options: ['context' => 'hdbt cookie banner']) | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Validates JSON string. | ||
* | ||
* @param string $value | ||
* Input string. | ||
* | ||
* @return bool | ||
* True if input is valid JSON. | ||
*/ | ||
private function isValidJson(string $value): bool { | ||
// @todo replace with json_validate in php >= 8.3. | ||
// https://www.php.net/releases/8.3/en.php#json_validate. | ||
json_decode($value); | ||
return json_last_error() === JSON_ERROR_NONE; | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# HELfi users | ||
|
||
Fixes related to deleting or banning users. | ||
|
||
Other user account related fixes and features: | ||
- [Expired users](https://github.com/City-of-Helsinki/drupal-module-helfi-api-base/blob/main/documentation/user-expire.md) | ||
- [Infofinland user sanitization](https://github.com/City-of-Helsinki/drupal-infofinland/blob/dev/public/modules/custom/infofinland_user_cancel/README.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: HELfi users | ||
description: 'Fixes related to deleting or canceling users.' | ||
package: HELfi | ||
type: module | ||
core_version_requirement: ^10 || ^11 | ||
'interface translation project': helfi_users | ||
'interface translation server pattern': modules/contrib/helfi_platform_config/modules/helfi_users/translations/%language.po |
Oops, something went wrong.