Skip to content

Commit

Permalink
Merge pull request #9 from City-of-Helsinki/UHF-212_service
Browse files Browse the repository at this point in the history
UHF-212: Service integration
  • Loading branch information
tuutti authored Jan 26, 2021
2 parents 3a07778 + 86a9508 commit c1c22e2
Show file tree
Hide file tree
Showing 18 changed files with 620 additions and 106 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
langcode: en
status: true
dependencies:
module:
- content_translation
- helfi_tpr
third_party_settings:
content_translation:
enabled: true
bundle_settings:
untranslatable_fields_hide: '0'
id: tpr_service.tpr_service
target_entity_type_id: tpr_service
target_bundle: tpr_service
default_langcode: site_default
language_alterable: true
58 changes: 58 additions & 0 deletions helfi_tpr.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/**
* @file
* Contains helfi_tpr installation procedures.
*/

use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
* Installs the service entity type.
*/
function helfi_tpr_update_8001() : void {
$manager = \Drupal::entityDefinitionUpdateManager();
$entity_type = \Drupal::entityTypeManager()->getDefinition('tpr_service');
$manager->installEntityType($entity_type);
}

/**
* Install TPR service description field.
*/
function helfi_tpr_update_8002() : void {
$manager = \Drupal::entityDefinitionUpdateManager();
$fields = [];
$fields['description'] = BaseFieldDefinition::create('text_with_summary')
->setTranslatable(TRUE)
->setLabel(new TranslatableMarkup('Description'))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);

foreach ($fields as $name => $field) {
$manager->installFieldStorageDefinition($name, 'tpr_service', 'helfi_tpr', $field);
}
}

/**
* Install TPR unit service reference field.
*/
function helfi_tpr_update_8003() : void {
$manager = \Drupal::entityDefinitionUpdateManager();
$fields = [];
$fields['services'] = BaseFieldDefinition::create('entity_reference')
->setLabel(new TranslatableMarkup('Services'))
->setSettings([
'target_type' => 'tpr_service',
'handler_settings' => [
'target_bundles' => ['tpr_service'],
],
])
->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED)
->setDisplayConfigurable('view', TRUE)
->setDisplayConfigurable('form', TRUE);

foreach ($fields as $name => $field) {
$manager->installFieldStorageDefinition($name, 'tpr_unit', 'helfi_tpr', $field);
}
}
14 changes: 13 additions & 1 deletion helfi_tpr.links.menu.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
entity.tpr_unit.settings:
tpr_unit.settings:
title: TPR - Unit settings
description: Configure TPR unit entity type
route_name: tpr_unit.settings
Expand All @@ -9,3 +9,15 @@ entity.tpr_unit.collection:
description: List of TPR unit entities
route_name: entity.tpr_unit.collection
parent: system.admin_content

tpr_service.settings:
title: TPR - Service settings
description: Configure TPR service entity type
route_name: tpr_service.settings
parent: system.admin_structure

entity.tpr_service.collection:
title: TPR - Service entities
description: List of TPR service entities
route_name: entity.tpr_service.collection
parent: system.admin_content
33 changes: 32 additions & 1 deletion helfi_tpr.links.task.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,52 @@ tpr_unit.settings:
title: Settings
route_name: tpr_unit.settings
base_route: tpr_unit.settings

entity.tpr_unit.view:
title: View
route_name: entity.tpr_unit.canonical
base_route: entity.tpr_unit.canonical

entity.tpr_unit.edit_form:
title: Edit
route_name: entity.tpr_unit.edit_form
base_route: entity.tpr_unit.canonical

entity.tpr_unit.delete_form:
title: Delete
route_name: entity.tpr_unit.delete_form
base_route: entity.tpr_unit.canonical
weight: 10
entity.tpr_unit.collection:

tpr_unit.content_list:
title: TPR - Unit
route_name: entity.tpr_unit.collection
base_route: system.admin_content
weight: 10

tpr_service.settings:
title: Settings
route_name: tpr_service.settings
base_route: tpr_service.settings

entity.tpr_service.view:
title: View
route_name: entity.tpr_service.canonical
base_route: entity.tpr_service.canonical

entity.tpr_service.edit_form:
title: Edit
route_name: entity.tpr_service.edit_form
base_route: entity.tpr_service.canonical

entity.tpr_service.delete_form:
title: Delete
route_name: entity.tpr_service.delete_form
base_route: entity.tpr_service.canonical
weight: 10

tpr_service.content_list:
title: TPR - Service
route_name: entity.tpr_service.collection
base_route: system.admin_content
weight: 10
24 changes: 24 additions & 0 deletions migrations/tpr_service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
langcode: en
status: true
dependencies:
enforced:
module:
- helfi_tpr
id: tpr_service
migration_tags:
- tpr
label: 'TPR service'
source:
plugin: tpr_service_register
track_changes: true
url: 'http://www.hel.fi/palvelukarttaws/rest/vpalvelurekisteri/description/'
ids:
id:
type: string
process:
id: id
destination:
plugin: tpr_service
migration_dependencies:
required:
- tpr_unit
5 changes: 1 addition & 4 deletions migrations/tpr_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ dependencies:
module:
- helfi_tpr
id: tpr_unit
field_plugin_method: null
cck_plugin_method: null
migration_tags:
- tpr
migration_group: tpr
label: 'TPR unit'
source:
plugin: tpr
plugin: tpr_service_map
track_changes: true
url: 'https://www.hel.fi/palvelukarttaws/rest/v4/unit/'
ids:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* Provides a list controller for the tpr_unit entity type.
* Provides a list controller for the tpr entity types.
*/
class UnitListBuilder extends EntityListBuilder {
class ListBuilder extends EntityListBuilder {

/**
* The date formatter service.
Expand Down
83 changes: 83 additions & 0 deletions src/Entity/Service.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

declare(strict_types = 1);

namespace Drupal\helfi_tpr\Entity;

use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
* Defines the tpr_service entity class.
*
* @ContentEntityType(
* id = "tpr_service",
* label = @Translation("TPR - Service"),
* label_collection = @Translation("TPR - Service"),
* handlers = {
* "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
* "list_builder" = "Drupal\helfi_tpr\Entity\Listing\ListBuilder",
* "views_data" = "Drupal\views\EntityViewsData",
* "access" = "Drupal\helfi_api_base\Entity\Access\RemoteEntityAccess",
* "form" = {
* "default" = "Drupal\Core\Entity\ContentEntityForm",
* "delete" = "Drupal\Core\Entity\ContentEntityDeleteForm"
* },
* "route_provider" = {
* "html" = "Drupal\helfi_api_base\Entity\Routing\EntityRouteProvider",
* },
* },
* base_table = "tpr_service",
* data_table = "tpr_service_field_data",
* revision_table = "tpr_service_revision",
* revision_data_table = "tpr_service_field_revision",
* show_revision_ui = TRUE,
* translatable = TRUE,
* admin_permission = "administer remote entities",
* entity_keys = {
* "id" = "id",
* "revision" = "revision_id",
* "langcode" = "langcode",
* "uid" = "uid",
* "label" = "name",
* "uuid" = "uuid"
* },
* revision_metadata_keys = {
* "revision_created" = "revision_timestamp",
* "revision_user" = "revision_user",
* "revision_log_message" = "revision_log"
* },
* links = {
* "canonical" = "/tpr-service/{tpr_service}",
* "edit-form" = "/admin/content/tpr-service/{tpr_service}/edit",
* "delete-form" = "/admin/content/tpr-service/{tpr_service}/delete",
* "collection" = "/admin/content/tpr-service"
* },
* field_ui_base_route = "tpr_service.settings"
* )
*/
class Service extends TprEntityBase {

/**
* {@inheritdoc}
*/
public static function getMigration(): ?string {
return 'tpr_service';
}

/**
* {@inheritdoc}
*/
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields['description'] = BaseFieldDefinition::create('text_with_summary')
->setTranslatable(TRUE)
->setLabel(new TranslatableMarkup('Description'))
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);

return $fields;
}

}
1 change: 1 addition & 0 deletions src/Entity/TprEntityBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ protected static function createLinkField(string $label, int $cardinality = 1) :
public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
$fields = parent::baseFieldDefinitions($entity_type);
$fields += static::revisionLogBaseFieldDefinitions($entity_type);
$fields['name'] = static::createStringField('Name');

return $fields;
}
Expand Down
Loading

0 comments on commit c1c22e2

Please sign in to comment.