Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
- field.field.block_content.ucb_people_list_block.field_people_block_filter_2
- field.field.block_content.ucb_people_list_block.field_people_block_filter_3
- field.field.block_content.ucb_people_list_block.field_people_block_job_type
- field.field.block_content.ucb_people_list_block.field_people_list_block_order_by
module:
- field_group
- text
Expand All @@ -32,6 +33,7 @@ third_party_settings:
- field_people_block_filter_1
- field_people_block_filter_2
- field_people_block_filter_3
- field_people_list_block_order_by
label: Filters
region: content
parent_name: group_content
Expand Down Expand Up @@ -202,19 +204,19 @@ content:
third_party_settings: { }
field_bs_heading:
type: options_select
weight: 7
weight: 13
region: content
settings: { }
third_party_settings: { }
field_bs_heading_alignment:
type: options_select
weight: 8
weight: 14
region: content
settings: { }
third_party_settings: { }
field_bs_heading_style:
type: options_select
weight: 9
weight: 15
region: content
settings: { }
third_party_settings: { }
Expand Down Expand Up @@ -286,6 +288,12 @@ content:
region: content
settings: { }
third_party_settings: { }
field_people_list_block_order_by:
type: options_select
weight: 8
region: content
settings: { }
third_party_settings: { }
info:
type: string_textfield
weight: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies:
- field.field.block_content.ucb_people_list_block.field_people_block_filter_2
- field.field.block_content.ucb_people_list_block.field_people_block_filter_3
- field.field.block_content.ucb_people_list_block.field_people_block_job_type
- field.field.block_content.ucb_people_list_block.field_people_list_block_order_by
module:
- options
- text
Expand Down Expand Up @@ -147,4 +148,11 @@ content:
third_party_settings: { }
weight: 2
region: content
field_people_list_block_order_by:
type: list_key
label: hidden
settings: { }
third_party_settings: { }
weight: 11
region: content
hidden: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
langcode: en
status: true
dependencies:
config:
- block_content.type.ucb_people_list_block
- field.storage.block_content.field_people_list_block_order_by
module:
- options
id: block_content.ucb_people_list_block.field_people_list_block_order_by
field_name: field_people_list_block_order_by
entity_type: block_content
bundle: ucb_people_list_block
label: 'Order By'
description: ''
required: true
translatable: false
default_value:
-
value: last
default_value_callback: ''
settings: { }
field_type: list_string
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
langcode: en
status: true
dependencies:
module:
- block_content
- options
id: block_content.field_people_list_block_order_by
field_name: field_people_list_block_order_by
entity_type: block_content
type: list_string
settings:
allowed_values:
-
value: last
label: 'Last Name'
-
value: type
label: 'Job Type, Last Name'
allowed_values_function: ''
module: options
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
131 changes: 131 additions & 0 deletions cu_boulder_content_types.install
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,134 @@ function cu_boulder_content_types_update_10003() {
return t('Abstract field has been added to person pages.');
}

/**
* Adds Order By field to People List Block (block_content.ucb_people_list_block).
*/
function cu_boulder_content_types_update_10004() {
$config_path = \Drupal::service('extension.list.module')->getPath('cu_boulder_content_types') . '/config/install';

// Ensure field storage exists.
$field_storage = FieldStorageConfig::loadByName('block_content', 'field_people_list_block_order_by');
if (!$field_storage) {
// Create with explicit allowed_values map to satisfy typed config expectations.
FieldStorageConfig::create([
'field_name' => 'field_people_list_block_order_by',
'entity_type' => 'block_content',
'type' => 'list_string',
'settings' => [
'allowed_values' => [
'last' => 'Last Name',
'type' => 'Job Type, Last Name',
],
'allowed_values_function' => '',
],
'locked' => FALSE,
'cardinality' => 1,
'translatable' => TRUE,
'indexes' => [],
'persist_with_no_fields' => FALSE,
'custom_storage' => FALSE,
])->save();
}

// Ensure field instance on the People List Block
$field = FieldConfig::loadByName('block_content', 'ucb_people_list_block', 'field_people_list_block_order_by');
if (!$field) {
$field_config = \Drupal::service('config.storage')->read('field.field.block_content.ucb_people_list_block.field_people_list_block_order_by');
if (!$field_config) {
$field_config = Yaml::parse(file_get_contents($config_path . '/field.field.block_content.ucb_people_list_block.field_people_list_block_order_by.yml'));
}
$field = FieldConfig::create($field_config);
$field->save();
}
// Ensure required and default value are set to 'last'
if ($field) {
$field->setRequired(TRUE);
$field->set('default_value', [['value' => 'last']]);
$field->save();
}

// Update the form display to show the field.
$form_display = EntityFormDisplay::load('block_content.ucb_people_list_block.default');
if ($form_display && !$form_display->getComponent('field_people_list_block_order_by')) {
$form_display->setComponent('field_people_list_block_order_by', [
'type' => 'options_select',
'weight' => 8,
'region' => 'content',
'settings' => [],
'third_party_settings' => [],
]);

// Add to the Filters group if it exists.
$third_party = $form_display->getThirdPartySettings('field_group');
if (isset($third_party['group_people_block_filters'])) {
$children = isset($third_party['group_people_block_filters']['children'])
? $third_party['group_people_block_filters']['children']
: [];
if (!in_array('field_people_list_block_order_by', $children, TRUE)) {
$children[] = 'field_people_list_block_order_by';
$third_party['group_people_block_filters']['children'] = $children;
$form_display->setThirdPartySetting('field_group', 'group_people_block_filters', $third_party['group_people_block_filters']);
}
}

$form_display->save();
}

// Update the view display (hidden label, list_key formatter).
$view_display = EntityViewDisplay::load('block_content.ucb_people_list_block.default');
if ($view_display && !$view_display->getComponent('field_people_list_block_order_by')) {
$view_display->setComponent('field_people_list_block_order_by', [
'type' => 'list_key',
'label' => 'hidden',
'weight' => 11,
'region' => 'content',
'settings' => [],
'third_party_settings' => [],
])->save();
}

// Backfill existing People List Blocks, will have null value set
try {
$storage = \Drupal::entityTypeManager()->getStorage('block_content');
$ids = $storage->getQuery()
->condition('type', 'ucb_people_list_block')
->condition('field_people_list_block_order_by.value', NULL, 'IS NULL')
->accessCheck(FALSE)
->execute();
if (!empty($ids)) {
$entities = $storage->loadMultiple($ids);
foreach ($entities as $entity) {
if (!$entity->hasField('field_people_list_block_order_by')) {
continue;
}
$updated = FALSE;
$languages = $entity->getTranslationLanguages();
if (!empty($languages)) {
foreach ($languages as $langcode => $language) {
$translation = $entity->getTranslation($langcode);
if ($translation->get('field_people_list_block_order_by')->isEmpty()) {
$translation->set('field_people_list_block_order_by', 'last');
$updated = TRUE;
}
}
}
else {
if ($entity->get('field_people_list_block_order_by')->isEmpty()) {
$entity->set('field_people_list_block_order_by', 'last');
$updated = TRUE;
}
}
if ($updated) {
$entity->save();
}
}
}
}
catch (\Throwable $e) {
// Non-fatal: continue even if no entities are present or storage errors occur.
}

return t('Order By field added to People List Block.');
}