diff --git a/helfi_tpr.install b/helfi_tpr.install index 88b026c..6e01253 100644 --- a/helfi_tpr.install +++ b/helfi_tpr.install @@ -227,3 +227,57 @@ function helfi_tpr_update_8043() : void { ->installFieldStorageDefinition($name, 'tpr_service', 'helfi_tpr', $field); } } + +/** + * Add multiple missing fields to Unit entity. + */ +function helfi_tpr_update_8044() : void { + $fields['other_info'] = BaseFieldDefinition::create('tpr_connection') + ->setLabel(new TranslatableMarkup('Further information')) + ->setDescription(new TranslatableMarkup('The "OTHER_INFO" connection type')) + ->setTranslatable(TRUE) + ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + + $fields['price_info'] = BaseFieldDefinition::create('tpr_connection') + ->setLabel(new TranslatableMarkup('Charges')) + ->setDescription(new TranslatableMarkup('The "PRICE" connection type')) + ->setTranslatable(TRUE) + ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + + $fields['links'] = BaseFieldDefinition::create('tpr_connection') + ->setLabel(new TranslatableMarkup('Web sites')) + ->setDescription(new TranslatableMarkup('The "LINK" connection type')) + ->setTranslatable(TRUE) + ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + + $fields['contacts'] = BaseFieldDefinition::create('tpr_connection') + ->setLabel(new TranslatableMarkup('Other contact information')) + ->setDescription(new TranslatableMarkup('The "PHONE_OR_EMAIL" connection type')) + ->setTranslatable(TRUE) + ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + + foreach ($fields as $name => $field) { + \Drupal::entityDefinitionUpdateManager() + ->installFieldStorageDefinition($name, 'tpr_unit', 'helfi_tpr', $field); + } +} diff --git a/migrations/tpr_unit.yml b/migrations/tpr_unit.yml index 753d1fb..d996aba 100644 --- a/migrations/tpr_unit.yml +++ b/migrations/tpr_unit.yml @@ -56,6 +56,54 @@ process: value: value data: data type: type + _other_info_connections: + plugin: array_element_equals + source: connections + value: OTHER_INFO + key: type + other_info: + plugin: sub_process + source: '@_other_info_connections' + process: + value: value + data: data + type: type + _price_info_connections: + plugin: array_element_equals + source: connections + value: PRICE + key: type + price_info: + plugin: sub_process + source: '@_price_info_connections' + process: + value: value + data: data + type: type + _links_connections: + plugin: array_element_equals + source: connections + value: LINK + key: type + links: + plugin: sub_process + source: '@_links_connections' + process: + value: value + data: data + type: type + _contacts_connections: + plugin: array_element_equals + source: connections + value: PHONE_OR_EMAIL + key: type + contacts: + plugin: sub_process + source: '@_contacts_connections' + process: + value: value + data: data + type: type accessibility_sentences: plugin: sub_process source: accessibility_sentences diff --git a/src/Entity/Listing/ListBuilder.php b/src/Entity/Listing/ListBuilder.php index 53c4e84..541f7ec 100644 --- a/src/Entity/Listing/ListBuilder.php +++ b/src/Entity/Listing/ListBuilder.php @@ -4,9 +4,9 @@ namespace Drupal\helfi_tpr\Entity\Listing; +use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityListBuilder; -use Drupal\Core\Datetime\DateFormatterInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Routing\RedirectDestinationInterface; diff --git a/src/Entity/Unit.php b/src/Entity/Unit.php index f93f9b2..0f2332d 100644 --- a/src/Entity/Unit.php +++ b/src/Entity/Unit.php @@ -301,6 +301,10 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) : ->setDescription(new TranslatableMarkup('The "OPENING_HOURS" connection type')) ->setTranslatable(TRUE) ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); $fields['provided_languages'] = BaseFieldDefinition::create('string') ->setLabel(new TranslatableMarkup('Provided languages')) @@ -323,6 +327,10 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) : ->setLabel(new TranslatableMarkup('Highlights')) ->setTranslatable(TRUE) ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); $fields['ontologyword_ids'] = BaseFieldDefinition::create('integer') ->setLabel(new TranslatableMarkup('Ontologyword IDs')) @@ -336,6 +344,46 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) : ->setDisplayOptions('form', [ 'region' => 'hidden', ]); + $fields['other_info'] = BaseFieldDefinition::create('tpr_connection') + ->setLabel(new TranslatableMarkup('Further information')) + ->setDescription(new TranslatableMarkup('The "OTHER_INFO" connection type')) + ->setTranslatable(TRUE) + ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]); + $fields['price_info'] = BaseFieldDefinition::create('tpr_connection') + ->setLabel(new TranslatableMarkup('Charges')) + ->setDescription(new TranslatableMarkup('The "PRICE" connection type')) + ->setTranslatable(TRUE) + ->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]); + $fields['links'] = BaseFieldDefinition::create('tpr_connection') + ->setLabel(new TranslatableMarkup('Web sites')) + ->setDescription(new TranslatableMarkup('The "LINK" connection type')) + ->setTranslatable(TRUE) + ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + $fields['contacts'] = BaseFieldDefinition::create('tpr_connection') + ->setLabel(new TranslatableMarkup('Other contact information')) + ->setDescription(new TranslatableMarkup('The "PHONE_OR_EMAIL" connection type')) + ->setTranslatable(TRUE) + ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) + ->setDisplayOptions('form', [ + 'type' => 'readonly_field_widget', + ]) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); return $fields; } diff --git a/src/Field/Connection/Link.php b/src/Field/Connection/Link.php new file mode 100644 index 0000000..a0384e0 --- /dev/null +++ b/src/Field/Connection/Link.php @@ -0,0 +1,19 @@ +get('name')); + + if (function_exists('_filter_autop')) { + $markup = _filter_autop($markup); + } + + return [ + 'name' => [ + '#markup' => $markup, + ], + ]; + } + +} diff --git a/src/Field/Connection/PhoneOrEmail.php b/src/Field/Connection/PhoneOrEmail.php new file mode 100644 index 0000000..3fd2d1a --- /dev/null +++ b/src/Field/Connection/PhoneOrEmail.php @@ -0,0 +1,59 @@ +getFields(); + $fields_data = []; + + foreach ($fields as $field) { + if (!$this->get($field)) { + continue; + } + + $data = Html::escape($this->get($field)); + + $fields_data[] = $data; + } + + $build = [ + 'contact' => [ + '#markup' => '
' . implode('
', $fields_data) . '