Skip to content

Commit

Permalink
Merge pull request #128 from dragos-dumi-ibm/main
Browse files Browse the repository at this point in the history
New TPR Service listing component with search
  • Loading branch information
tuutti authored Dec 5, 2022
2 parents cd05561 + b6ee553 commit f7e1e09
Show file tree
Hide file tree
Showing 18 changed files with 835 additions and 7 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ jobs:
with:
fetch-depth: 1

- name: Parse $MODULE_NAME from composer.json
run: echo "MODULE_NAME=$(cat composer.json | jq -r .name | awk -F/ '{print $NF}')" >> $GITHUB_ENV

- name: Set Drupal root
run: echo "DRUPAL_ROOT=$HOME/drupal" >> $GITHUB_ENV

- name: Set module folder
run: echo "MODULE_FOLDER=$DRUPAL_ROOT/modules/contrib/${{ secrets.MODULE_NAME }}" >> $GITHUB_ENV
run: echo "MODULE_FOLDER=$DRUPAL_ROOT/modules/contrib/$MODULE_NAME" >> $GITHUB_ENV

- name: Clone drupal
run: git clone --depth 1 --branch "$DRUPAL_CORE_VERSION" http://git.drupal.org/project/drupal.git/ $DRUPAL_ROOT
Expand All @@ -50,7 +53,7 @@ jobs:
composer config platform.php ${{ matrix.php-versions }}
composer config repositories.4 composer https://repository.drupal.hel.ninja/
composer config repositories.5 path $GITHUB_WORKSPACE
composer require drupal/${{ secrets.MODULE_NAME }} -W
composer require drupal/$MODULE_NAME -W
composer run-script drupal-phpunit-upgrade
composer require "drush/drush ^11.0"
composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
Expand All @@ -61,7 +64,7 @@ jobs:
run: |
cd $DRUPAL_ROOT
php -d sendmail_path=$(which true); vendor/bin/drush --yes -v site-install minimal --db-url="$SIMPLETEST_DB"
vendor/bin/drush en ${{ secrets.MODULE_NAME }} -y
vendor/bin/drush en $MODULE_NAME -y
- name: Run PHPCS
run: |
Expand Down
1 change: 0 additions & 1 deletion config/language/fi/views.view.unit_services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ display:
items_per_page_options_all_label: '- Kaikki -'
views_infinite_scroll:
button_text: 'Lataa lisää palveluita'

15 changes: 15 additions & 0 deletions config/schema/helfi_tpr.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ field.formatter.settings.tpr_service_channel_formatter:
weight:
type: integer

field.formatter.settings.tpr_service_err_channel_list:
type: mapping
mapping:
sort_order:
type: sequence
sequence:
type: mapping
mapping:
label:
type: label
show:
type: boolean
weight:
type: integer

field.formatter.settings.service_map_embed:
type: mapping
label: 'Service map embed'
Expand Down
1 change: 0 additions & 1 deletion helfi_tpr.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ dependencies:
- views
'interface translation project': helfi_tpr
'interface translation server pattern': modules/contrib/helfi_tpr/translations/%language.po

63 changes: 63 additions & 0 deletions helfi_tpr.install
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\helfi_tpr\Entity\ChannelTypeCollection;
use Drupal\migrate\Plugin\MigrateIdMapInterface;

/**
* Helper function to get the content translation field definitions.
Expand Down Expand Up @@ -714,3 +715,65 @@ function helfi_tpr_update_8040() : void {
->installFieldStorageDefinition($name, 'tpr_unit', 'helfi_tpr', $field);
}
}

/**
* Add name_synonyms field and service_id field to Service entity.
*/
function helfi_tpr_update_8041() : void {

$fields['service_id'] = BaseFieldDefinition::create('integer')
->setLabel(new TranslatableMarkup('Service grouping ID'))
->setDescription(new TranslatableMarkup('Value from service_id property'))
->setDisplayOptions('form', [
'type' => 'readonly_field_widget',
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setSetting('unsigned', TRUE);

$fields['name_synonyms'] = BaseFieldDefinition::create('string_long')
->setTranslatable(TRUE)
->setRevisionable(FALSE)
->setLabel(new TranslatableMarkup('Name synonyms'))
->setDescription(new TranslatableMarkup('Name synonyms for the service title.'))
->setDisplayOptions('form', [
'type' => 'readonly_field_widget',
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);

foreach ($fields as $name => $field) {
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition($name, 'tpr_service', 'helfi_tpr', $field);
}
}

/**
* Map all services that needs update to import name_synonyms on next migration.
*/
function helfi_tpr_update_8042() : void {
\Drupal::database()->update('migrate_map_tpr_service')->fields([
'source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE,
])->execute();
}

/**
* Add has_unit field to Service entity.
*/
function helfi_tpr_update_8043() : void {
$fields['has_unit'] = BaseFieldDefinition::create('boolean')
->setTranslatable(TRUE)
->setRevisionable(FALSE)
->setLabel(new TranslatableMarkup('Has Unit'))
->setDescription(new TranslatableMarkup('If service have unit its true else false.'))
->setDisplayOptions('form', [
'type' => 'readonly_field_widget',
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);

foreach ($fields as $name => $field) {
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition($name, 'tpr_service', 'helfi_tpr', $field);
}
}
17 changes: 17 additions & 0 deletions helfi_tpr.module
Original file line number Diff line number Diff line change
Expand Up @@ -269,3 +269,20 @@ function helfi_tpr_tpr_errand_service_access(EntityInterface $entity, $operation
function helfi_tpr_query_owd_relationship_alter(AlterableInterface $query) : void {
$query->groupBy('id');
}

/**
* Implements hook_views_data_alter().
*/
function helfi_tpr_views_data_alter(&$data) : void {
$data['tpr_service_field_data']['id_or_service_id'] = [
'title' => t('ID or Service ID'),
'help' => t('Displays entities that have either id or service IDs'),
'argument' => [
'field' => 'id',
'name table' => 'tpr_service_field_data',
'name field' => 'id',
'id' => 'id_or_service_id_handler',
],
];

}
1 change: 0 additions & 1 deletion helfi_tpr.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ services:
arguments: ['@config.factory']
tags:
- { name: event_subscriber }

6 changes: 6 additions & 0 deletions migrations/tpr_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ source:
process:
id: id
name: title
name_synonyms: name_synonyms
service_id: service_id
description/summary: description_short
description/value: description_long
description/format:
Expand All @@ -24,6 +26,10 @@ process:
errand_services:
plugin: get
source: exact_errand_services
has_unit:
plugin: callback
callable: boolval
source: unit_ids
links:
plugin: sub_process
source: links
Expand Down
33 changes: 33 additions & 0 deletions src/Entity/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,38 @@ protected function getErrandServiceIndex(ErrandService $errand_service) {
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);

$fields['name_synonyms'] = BaseFieldDefinition::create('string_long')
->setTranslatable(TRUE)
->setRevisionable(FALSE)
->setLabel(new TranslatableMarkup('Name synonyms'))
->setDescription(new TranslatableMarkup('Name synonyms for the service title.'))
->setDisplayOptions('form', [
'type' => 'readonly_field_widget',
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);

$fields['has_unit'] = BaseFieldDefinition::create('boolean')
->setTranslatable(FALSE)
->setRevisionable(FALSE)
->setLabel(new TranslatableMarkup('Has Unit'))
->setDescription(new TranslatableMarkup('If service have unit its true else false.'))
->setDisplayOptions('form', [
'type' => 'readonly_field_widget',
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);

$fields['service_id'] = BaseFieldDefinition::create('integer')
->setLabel(new TranslatableMarkup('Service grouping ID'))
->setDescription(new TranslatableMarkup('Value from service_id property'))
->setDisplayOptions('form', [
'type' => 'readonly_field_widget',
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setSetting('unsigned', TRUE);

$fields['description'] = BaseFieldDefinition::create('text_with_summary')
->setTranslatable(TRUE)
->setRevisionable(FALSE)
Expand Down Expand Up @@ -185,6 +217,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);

$fields['menu_link'] = BaseFieldDefinition::create('entity_reference')
->setLabel(new TranslatableMarkup('Menu link'))
->setSettings([
Expand Down
6 changes: 6 additions & 0 deletions src/Fixture/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public function getMockData() : array {
'url' => sprintf('https://localhost/2/%s/%s', $language, $id),
],
],
'unit_ids' => $id != 2 ? [] : [
1563,
1940,
],
'name_synonyms' => sprintf('Name synonyms %s %s', $language, $id),
'service_id' => 10554,
];
}
}
Expand Down
Loading

0 comments on commit f7e1e09

Please sign in to comment.