Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UFH-8595: Added multiple missing fields to Units #147

Merged
merged 5 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions helfi_tpr.install
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
48 changes: 48 additions & 0 deletions migrations/tpr_unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions src/Entity/Unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,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)
juho-lehmonen marked this conversation as resolved.
Show resolved Hide resolved
->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)
juho-lehmonen marked this conversation as resolved.
Show resolved Hide resolved
->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;
}
Expand Down
65 changes: 65 additions & 0 deletions src/Field/Connection/Link.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

declare(strict_types = 1);

namespace Drupal\helfi_tpr\Field\Connection;

use Drupal\Component\Utility\Html;
use Drupal\Core\Url;

/**
* Provides a domain object for TPR connection type of LINK.
*/
final class Link extends Connection {
dire marked this conversation as resolved.
Show resolved Hide resolved

/**
* The type name.
*
* @var string
*/
public const TYPE_NAME = 'LINK';

/**
* {@inheritdoc}
*/
public function getFields(): array {
return [
'name',
'www',
];
}

/**
* {@inheritdoc}
*/
public function build(): array {
$markup = Html::escape($this->get('name'));

if (function_exists('_filter_autop')) {
$markup = _filter_autop($markup);
}

$build = [
'name' => [
'#markup' => $markup,
],
];

if ($link = $this->get('www')) {
try {
return [
'www' => [
'#title' => $this->get('name'),
'#type' => 'link',
'#url' => Url::fromUri($link),
],
];
}
catch (\InvalidArgumentException) {
}
}

return $build;
}

}
47 changes: 47 additions & 0 deletions src/Field/Connection/OtherInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types = 1);

namespace Drupal\helfi_tpr\Field\Connection;

use Drupal\Component\Utility\Html;

/**
* Provides a domain object for TPR connection type of OPENING_HOUR.
*/
final class OtherInfo extends Connection {

/**
* The type name.
*
* @var string
*/
public const TYPE_NAME = 'OTHER_INFO';

/**
* {@inheritdoc}
*/
public function getFields(): array {
return [
'name',
];
}

/**
* {@inheritdoc}
*/
public function build(): array {
$markup = Html::escape($this->get('name'));

if (function_exists('_filter_autop')) {
$markup = _filter_autop($markup);
}

return [
'name' => [
'#markup' => $markup,
],
];
}

}
59 changes: 59 additions & 0 deletions src/Field/Connection/PhoneOrEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types = 1);

namespace Drupal\helfi_tpr\Field\Connection;

use Drupal\Component\Utility\Html;

/**
* Provides a domain object for TPR connection type of PHONE_OR_EMAIL.
*/
final class PhoneOrEmail extends Connection {

/**
* The type name.
*
* @var string
*/
public const TYPE_NAME = 'PHONE_OR_EMAIL';

/**
* {@inheritdoc}
*/
public function getFields(): array {
return [
'name',
'contact_person',
'phone',
'email',
];
}

/**
* {@inheritdoc}
*/
public function build(): array {
$fields = $this->getFields();
$fields_data = [];

foreach ($fields as $field) {
if (!$this->get($field)) {
continue;
}

$data = Html::escape($this->get($field));

$fields_data[] = $data;
}

$build = [
'contact' => [
'#markup' => '<p>' . implode('<br>', $fields_data) . '</p>',
],
];

return $build;
}

}
47 changes: 47 additions & 0 deletions src/Field/Connection/Price.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types = 1);

namespace Drupal\helfi_tpr\Field\Connection;

use Drupal\Component\Utility\Html;

/**
* Provides a domain object for TPR connection type of PRICE.
*/
final class Price extends Connection {

/**
* The type name.
*
* @var string
*/
public const TYPE_NAME = 'PRICE';

/**
* {@inheritdoc}
*/
public function getFields(): array {
return [
'name',
];
}

/**
* {@inheritdoc}
*/
public function build(): array {
$markup = Html::escape($this->get('name'));

if (function_exists('_filter_autop')) {
$markup = _filter_autop($markup);
}

return [
'name' => [
'#markup' => $markup,
],
];
}

}
4 changes: 4 additions & 0 deletions src/Field/Connection/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ final class Repository {
OpeningHour::TYPE_NAME => OpeningHour::class,
OpeningHourObject::TYPE_NAME => OpeningHourObject::class,
Highlight::TYPE_NAME => Highlight::class,
OtherInfo::TYPE_NAME => OtherInfo::class,
Price::TYPE_NAME => Price::class,
Link::TYPE_NAME => Link::class,
PhoneOrEmail::TYPE_NAME => PhoneOrEmail::class,
];

/**
Expand Down
Loading