-
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.
Merge pull request #773 from City-of-Helsinki/UHF-9708
UHF-9708: Survey content type
- Loading branch information
Showing
62 changed files
with
2,095 additions
and
752 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Remote entities | ||
|
||
Remote entities module allows fetching announcements from `Etusivu`-instance. | ||
It utilizes `json-api` and `external_entities`-module to transfer the data between instances. | ||
|
||
## How to set up locally | ||
|
||
Local setup requires Etusivu-instance to be up and running with some relevant data created to it. | ||
|
||
# Cache | ||
|
||
Remote entities are cached with custom cache tags. These tags are cleared when any entities are updated using [PubSub](https://github.com/City-of-Helsinki/drupal-module-helfi-api-base/blob/main/documentation/pubsub-messaging.md) by etusivu instance. See [`helfi_etusivu` -module](https://github.com/City-of-Helsinki/drupal-helfi-etusivu/tree/dev/public/modules/custom/helfi_etusivu). |
File renamed without changes.
39 changes: 39 additions & 0 deletions
39
..._etusivu_entities/config/install/external_entities.external_entity_type.helfi_surveys.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,39 @@ | ||
uuid: be631905-d77b-418a-890e-b04fa3ed3e22 | ||
langcode: en | ||
status: true | ||
dependencies: { } | ||
id: helfi_surveys | ||
label: 'Helfi: Survey' | ||
label_plural: 'Helfi: Surveys' | ||
description: '' | ||
read_only: true | ||
field_mapper_id: jsonpath | ||
field_mapper_config: | ||
field_mappings: | ||
id: | ||
value: $.id | ||
uuid: | ||
value: $.id | ||
title: | ||
value: '$.attributes["title"]' | ||
published_at: | ||
value: '$.attributes["published_at"]' | ||
unpublish_on: | ||
value: '$.attributes["unpublish_on"]' | ||
langcode: | ||
value: '$.attributes["langcode"]' | ||
body: | ||
value: '$.attributes["body"]["value"]' | ||
status: | ||
value: '$.attributes["status"]' | ||
survey_link_text: | ||
value: '$.attributes["field_survey_link"]["title"]' | ||
survey_link_url: | ||
value: '$.attributes["field_survey_link"]["uri"]' | ||
storage_client_id: helfi_surveys | ||
storage_client_config: { } | ||
persistent_cache_max_age: -1 | ||
annotation_entity_type_id: null | ||
annotation_bundle_id: null | ||
annotation_field_name: null | ||
inherits_annotation_fields: false |
13 changes: 13 additions & 0 deletions
13
modules/helfi_etusivu_entities/config/schema/helfi_etusivu_entities.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,13 @@ | ||
block.settings.surveys: | ||
type: block_settings | ||
label: 'Survey block settings' | ||
mapping: | ||
use_remote_entities: | ||
type: boolean | ||
|
||
block.settings.announcements: | ||
type: block_settings | ||
label: 'Announcement block settings' | ||
mapping: | ||
use_remote_entities: | ||
type: boolean |
10 changes: 10 additions & 0 deletions
10
modules/helfi_etusivu_entities/helfi_etusivu_entities.info.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,10 @@ | ||
name: 'HELfi Etusivu Entities' | ||
type: module | ||
core_version_requirement: ^10 | ||
dependencies: | ||
- external_entities:external_entities | ||
- publication_date:publication_date | ||
- helfi_api_base:helfi_api_base | ||
- helfi_platform_config:helfi_platform_config | ||
- helfi_platform_config:helfi_node_announcement | ||
- helfi_platform_config:helfi_node_survey |
75 changes: 75 additions & 0 deletions
75
modules/helfi_etusivu_entities/helfi_etusivu_entities.install
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,75 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains installation tasks for helfi_etusivu_entities module. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Implements hook_install(). | ||
*/ | ||
function helfi_etusivu_entities_install($is_syncing) : void { | ||
// Do not perform following steps if the module is being installed as part | ||
// of a configuration import. | ||
if ($is_syncing) { | ||
return; | ||
} | ||
|
||
helfi_etusivu_entities_grant_permissions(); | ||
helfi_etusivu_entities_create_blocks(); | ||
} | ||
|
||
/** | ||
* Create required blocks. | ||
*/ | ||
function helfi_etusivu_entities_create_blocks(): void { | ||
/** @var Drupal\helfi_platform_config\Helper\BlockInstaller $block_installer */ | ||
$block_installer = Drupal::service('helfi_platform_config.helper.block_installer'); | ||
|
||
/** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */ | ||
$theme_handler = \Drupal::service('theme_handler'); | ||
|
||
if (!str_starts_with($theme_handler->getDefault(), 'hdbt')) { | ||
return; | ||
} | ||
|
||
$theme = $theme_handler->getDefault(); | ||
foreach (helfi_etusivu_entities_get_block_configurations($theme) as $block_config) { | ||
['block' => $block, 'variations' => $variations] = $block_config; | ||
$block_installer->install($block, $variations); | ||
} | ||
} | ||
|
||
/** | ||
* Implements hook_themes_installed(). | ||
*/ | ||
function helfi_etusivu_entities_themes_installed($theme_list) : void { | ||
/** @var Drupal\helfi_platform_config\Helper\BlockInstaller $block_installer */ | ||
$block_installer = Drupal::service('helfi_platform_config.helper.block_installer'); | ||
|
||
foreach ($theme_list as $theme) { | ||
if (in_array($theme, ['stark', 'hdbt', 'hdbt_subtheme'])) { | ||
foreach (helfi_etusivu_entities_get_block_configurations($theme) as $block_config) { | ||
['block' => $block, 'variations' => $variations] = $block_config; | ||
$block_installer->install($block, $variations); | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Grants required permissions. | ||
*/ | ||
function helfi_etusivu_entities_grant_permissions() : void { | ||
$permissions = [ | ||
'view helfi_announcements external entity', | ||
'view helfi_surveys external entity', | ||
]; | ||
|
||
helfi_platform_config_grant_permissions([ | ||
'anonymous' => $permissions, | ||
'authenticated' => $permissions, | ||
]); | ||
} |
131 changes: 131 additions & 0 deletions
131
modules/helfi_etusivu_entities/helfi_etusivu_entities.module
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,131 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Contains installation tasks for helfi_etusivu_entities module. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
use Drupal\Core\Entity\EntityTypeInterface; | ||
use Drupal\Core\StringTranslation\TranslatableMarkup; | ||
use Drupal\entity\BundleFieldDefinition; | ||
|
||
/** | ||
* Gets the block configurations. | ||
* | ||
* Example block: | ||
* | ||
* @code | ||
* [ | ||
* 'breadbrumbs' => [ | ||
* 'block' => [ | ||
* ... | ||
* ], | ||
* 'variations' => [ | ||
* ... | ||
* ], | ||
* ], | ||
* ]; | ||
* @endcode | ||
* | ||
* @return array[] | ||
* The block configurations. | ||
*/ | ||
function helfi_etusivu_entities_get_block_configurations(string $theme) : array { | ||
return [ | ||
'announcements' => [ | ||
'block' => [ | ||
'id' => 'announcements', | ||
'plugin' => 'announcements', | ||
'settings' => [ | ||
'id' => 'announcements', | ||
'label' => 'Announcements', | ||
'provider' => 'helfi_node_announcement', | ||
], | ||
'provider' => 'helfi_node_announcement', | ||
'weight' => -15, | ||
], | ||
'variations' => [ | ||
[ | ||
'theme' => $theme, | ||
'region' => 'before_content', | ||
], | ||
[ | ||
'theme' => 'stark', | ||
'region' => 'content', | ||
], | ||
], | ||
], | ||
'surveys' => [ | ||
'block' => [ | ||
'id' => 'surveys', | ||
'plugin' => 'surveys', | ||
'settings' => [ | ||
'id' => 'surveys', | ||
'label' => 'Surveys', | ||
'provider' => 'helfi_node_survey', | ||
], | ||
'provider' => 'helfi_node_survey', | ||
'weight' => -15, | ||
], | ||
'variations' => [ | ||
[ | ||
'theme' => $theme, | ||
'region' => 'before_content', | ||
], | ||
[ | ||
'theme' => 'stark', | ||
'region' => 'content', | ||
], | ||
], | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* Implements hook_entity_bundle_field_info_alter(). | ||
*/ | ||
function helfi_etusivu_entities_entity_bundle_field_info_alter( | ||
&$fields, | ||
EntityTypeInterface $entity_type, | ||
) : void { | ||
$remote_entities = [ | ||
'helfi_announcements', | ||
'helfi_surveys', | ||
]; | ||
|
||
if (in_array($entity_type->id(), $remote_entities)) { | ||
// Common fields. | ||
$entity_info_fields = [ | ||
'published_at' => new TranslatableMarkup('Published at'), | ||
'unpublish_on' => new TranslatableMarkup('Unpublish on'), | ||
'langcode' => new TranslatableMarkup('Langcode'), | ||
'body' => new TranslatableMarkup('Body'), | ||
'status' => new TranslatableMarkup('Status'), | ||
]; | ||
|
||
// Additional entity info fields. | ||
$entity_info_fields += match ($entity_type->id()) { | ||
'helfi_announcements' => [ | ||
'notification' => new TranslatableMarkup('Notification'), | ||
'announcement_type' => new TranslatableMarkup('Announcement type'), | ||
'announcement_link_text' => new TranslatableMarkup('Announcement link text'), | ||
'announcement_link_url' => new TranslatableMarkup('Announcement link url'), | ||
'announcement_assistive_technology_close_button_title' => new TranslatableMarkup('Assistive technology close button title'), | ||
], | ||
'helfi_surveys' => [ | ||
'survey_link_text' => new TranslatableMarkup('Survey link text'), | ||
'survey_link_url' => new TranslatableMarkup('Survey link url'), | ||
], | ||
}; | ||
|
||
foreach ($entity_info_fields as $field_name => $field_label) { | ||
$fields[$field_name] = BundleFieldDefinition::create('string') | ||
->setName($field_name) | ||
->setLabel($field_label) | ||
->setDisplayConfigurable('view', TRUE) | ||
->setDisplayConfigurable('form', TRUE); | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
modules/helfi_etusivu_entities/helfi_etusivu_entities.services.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,6 @@ | ||
services: | ||
logger.channel.helfi_etusivu_entities: | ||
parent: logger.channel_base | ||
arguments: [ 'helfi_etusivu_entities' ] | ||
|
||
|
Oops, something went wrong.