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

TP-1616 Added re-generation of days since last state change default values #848

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
20 changes: 14 additions & 6 deletions config/sync/core.entity_form_display.node.service.default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies:
- hel_tpm_general
- hel_tpm_group
- hel_tpm_service_dates
- hel_tpm_service_stats
- ief_popup
- inline_entity_form
- link
Expand Down Expand Up @@ -200,6 +201,7 @@ third_party_settings:
- field_responsible_municipality
- field_responsible_updatee
- field_other_services
- field_days_since_last_state_chan
label: 'Additional info'
region: content
parent_name: ''
Expand Down Expand Up @@ -653,6 +655,13 @@ content:
third_party_settings:
ief_popup:
ief_popup_enabled: '1'
field_days_since_last_state_chan:
type: hel_tpm_service_stats_days_since_last_state_change_widget
weight: 16
region: content
settings:
placeholder: ''
third_party_settings: { }
field_description:
type: string_textarea
weight: 28
Expand Down Expand Up @@ -812,7 +821,7 @@ content:
third_party_settings: { }
field_other_services:
type: select2_entity_reference
weight: 16
weight: 15
region: content
settings:
width: 100%
Expand All @@ -828,7 +837,7 @@ content:
third_party_settings: { }
field_responsible_municipality:
type: hel_tpm_group_select2_widget
weight: 14
weight: 13
region: content
settings:
width: 100%
Expand All @@ -838,7 +847,7 @@ content:
third_party_settings: { }
field_responsible_updatee:
type: select2_entity_reference
weight: 15
weight: 14
region: content
settings:
width: 100%
Expand Down Expand Up @@ -938,7 +947,7 @@ content:
third_party_settings: { }
field_service_producer:
type: select2_entity_reference
weight: 12
weight: 11
region: content
settings:
width: 100%
Expand All @@ -948,7 +957,7 @@ content:
third_party_settings: { }
field_service_provider_updatee:
type: select2_entity_reference
weight: 13
weight: 12
region: content
settings:
width: 100%
Expand Down Expand Up @@ -1081,7 +1090,6 @@ content:
match_limit: 10
third_party_settings: { }
hidden:
field_days_since_last_state_chan: true
field_service_radioactivity: true
path: true
promote: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ status: true
dependencies:
config:
- field.storage.node.field_days_since_last_state_chan
- field.storage.node.field_responsible_updatee
- node.type.service
- user.role.admin
- user.role.root
Expand Down Expand Up @@ -161,7 +162,7 @@ display:
group_type: group
admin_label: ''
plugin_id: field
label: 'Päivää nykyisessä julkaisutilassa'
label: 'Päivät tilassa'
exclude: false
alter:
alter_text: false
Expand Down Expand Up @@ -217,6 +218,69 @@ display:
multi_type: separator
separator: ', '
field_api_classes: false
field_responsible_updatee:
id: field_responsible_updatee
table: node__field_responsible_updatee
field: field_responsible_updatee
relationship: nid
group_type: group
admin_label: ''
plugin_id: field
label: 'Kunnan vastuupäivittäjä'
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: "<span class=\"color--red\">\r\nTieto puuttuu\r\n</span>"
hide_empty: false
empty_zero: false
hide_alter_empty: true
click_sort_column: target_id
type: entity_reference_label
settings:
link: false
group_column: target_id
group_columns: { }
group_rows: true
delta_limit: 0
delta_offset: 0
delta_reversed: false
delta_first_last: false
multi_type: separator
separator: ', '
field_api_classes: false
edit_node:
id: edit_node
table: node
Expand Down Expand Up @@ -540,6 +604,7 @@ display:
- user.roles
tags:
- 'config:field.storage.node.field_days_since_last_state_chan'
- 'config:field.storage.node.field_responsible_updatee'
- 'config:workflow_list'
entity_view_1:
id: entity_view_1
Expand All @@ -564,6 +629,8 @@ display:
- 'user.node_grants:view'
- user.roles
tags:
- 'config:field.storage.node.field_days_since_last_state_chan'
- 'config:field.storage.node.field_responsible_updatee'
- 'config:workflow_list'
entity_view_2:
id: entity_view_2
Expand All @@ -590,4 +657,5 @@ display:
- user.roles
tags:
- 'config:field.storage.node.field_days_since_last_state_chan'
- 'config:field.storage.node.field_responsible_updatee'
- 'config:workflow_list'
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,105 @@ function hel_tpm_service_stats_update_10003() {
}

/**
* Helper to create field revisions.
* Re-generate default values for service fields.
*/
function _hel_tpm_service_stats_create_field_revision($revision) {
$database = Drupal::database();
function hel_tpm_service_stats_update_10004() {
$storage = Drupal::service('entity_type.manager')->getStorage('node');
$nodes = $storage->loadByProperties(['type' => 'service']);

foreach ($nodes as $node) {
$languages = $node->getTranslationLanguages();
$revision_ids = $storage->revisionIds($node);
$revision_ids = array_reverse($revision_ids);

foreach ($revision_ids as $revision_id) {
$revision = $storage->loadRevision($revision_id);

foreach ($languages as $langcode => $language) {

if ($revision->isDefaultRevision()) {
_hel_tpm_service_stats_create_default_field_revision($revision, $langcode);
}

if ($revision->hasTranslation($langcode)) {
_hel_tpm_service_stats_create_field_revision($revision, $langcode);
}
}
}
}
}

/**
* Creates a default field revision for the specified entity and language.
*
* @param int $revision
* The revision ID of the entity.
* @param string $langcode
* The language code for which the default field revision is created.
*
* @return void
* This function does not return a value.
*/
function _hel_tpm_service_stats_create_default_field_revision($revision, $langcode) {
$field_table = 'node__field_days_since_last_state_chan';
_hel_tpm_service_stats_insert_default_value($revision, $langcode, $field_table);
}

/**
* Creates a field revision entry for the specified revision and language code.
*
* @param int|string $revision
* The revision ID for which the field revision entry is created.
* @param string $langcode
* The language code for the entry.
*
* @return void
* This method does not return a value.
*/
function _hel_tpm_service_stats_create_field_revision($revision, $langcode) {
$field_revision_table = 'node_revision__field_days_since_last_state_chan';
_hel_tpm_service_stats_insert_default_value($revision, $langcode, $field_revision_table);
}

/**
* Inserts a default value into a specified field table for a given revision.
*
* @param object $revision
* The revision object containing entity information
* for which the operation is performed.
* @param string $langcode
* The language code to associate with the default value entry.
* @param string $field_table
* The name of the database table where the default value should be inserted.
*
* @return void
* No return value.
*/
function _hel_tpm_service_stats_insert_default_value($revision, string $langcode, $field_table) {
$database = Drupal::database();
$table = [
'bundle' => $revision->bundle(),
'deleted' => 0,
'entity_id' => $revision->id(),
'revision_id' => $revision->getRevisionId(),
'langcode' => $revision->language()->getId(),
'langcode' => $langcode,
'delta' => 0,
'field_days_since_last_state_chan_value' => 0,
];

if ($revision->isDefaultRevision()) {
$existing_entry = $database->select($field_table, 't')
->fields('t', ['entity_id', 'revision_id'])
->condition('entity_id', $revision->id())
->condition('revision_id', $revision->getRevisionId())
->condition('langcode', $langcode)
->execute()
->fetchField();

if (!$existing_entry) {
$database->insert($field_table)
->fields(array_keys($table))
->values(array_values($table))
->execute();
}
$database->insert($field_revision_table)
->fields(array_keys($table))
->values(array_values($table))
->execute();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Drupal\hel_tpm_service_stats\Plugin\Field\FieldWidget;

use Drupal\Core\Field\Attribute\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\Plugin\Field\FieldWidget\NumberWidget;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;

/**
* Provides a widget for the "Days Since Last State Change" field type.
*
* This widget extends the default NumberWidget to
* provide specific functionality
* for the "hel_tpm_service_stats_days_since_state_change" field type.
*/
#[FieldWidget(
id: "hel_tpm_service_stats_days_since_last_state_change_widget",
label: new TranslatableMarkup("Days Since Last State Change Widget"),
field_types: ["hel_tpm_service_stats_days_since_state_change"],
)]

final class DaysSinceLastStateChangeWidget extends NumberWidget {

/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state): array {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$element['#access'] = FALSE;
return $element;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.color--red {
color: $red-light;
}
2 changes: 1 addition & 1 deletion public/themes/custom/palvelumanuaali/dist/css/style.css

Large diffs are not rendered by default.

Large diffs are not rendered by default.