From dff63acbf1e4a79a2a67848e768231225b819eb6 Mon Sep 17 00:00:00 2001 From: Liam Morland Date: Thu, 2 May 2024 13:39:56 -0400 Subject: [PATCH] Issue #455: Make data_set_column_name formatter return only the names This allows Views formatting to control how the multiple values are combined. --- config/sync/views.view.site_search.yml | 3 +- .../bc_dc/config/schema/bc_dc.schema.yml | 8 ---- .../DataSetColumnNameFieldFormatter.php | 48 ++----------------- 3 files changed, 5 insertions(+), 54 deletions(-) diff --git a/config/sync/views.view.site_search.yml b/config/sync/views.view.site_search.yml index 8f03840b4..2ade32812 100644 --- a/config/sync/views.view.site_search.yml +++ b/config/sync/views.view.site_search.yml @@ -1129,8 +1129,7 @@ display: hide_alter_empty: true click_sort_column: target_id type: data_set_column_name - settings: - display_inline: true + settings: { } group_column: '' group_columns: { } group_rows: true diff --git a/html/modules/custom/bc_dc/config/schema/bc_dc.schema.yml b/html/modules/custom/bc_dc/config/schema/bc_dc.schema.yml index 2b3f8c2dc..2d102661e 100644 --- a/html/modules/custom/bc_dc/config/schema/bc_dc.schema.yml +++ b/html/modules/custom/bc_dc/config/schema/bc_dc.schema.yml @@ -15,14 +15,6 @@ bc_dc.settings: type: label label: 'Information schedule term pre-title' -field.formatter.settings.data_set_column_name: - type: mapping - label: 'Data set column name settings' - mapping: - display_inline: - type: boolean - label: 'Display inline' - block.settings.bc_dc_edit_button: type: block_settings mapping: diff --git a/html/modules/custom/bc_dc/src/Plugin/Field/FieldFormatter/DataSetColumnNameFieldFormatter.php b/html/modules/custom/bc_dc/src/Plugin/Field/FieldFormatter/DataSetColumnNameFieldFormatter.php index 3f1b72ccc..ab0a83f22 100644 --- a/html/modules/custom/bc_dc/src/Plugin/Field/FieldFormatter/DataSetColumnNameFieldFormatter.php +++ b/html/modules/custom/bc_dc/src/Plugin/Field/FieldFormatter/DataSetColumnNameFieldFormatter.php @@ -4,7 +4,6 @@ use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FormatterBase; -use Drupal\Core\Form\FormStateInterface; /** * Field Formatter that displays just the name of a data_set column. @@ -28,32 +27,6 @@ public function settingsSummary() { return $summary; } - /** - * {@inheritdoc} - */ - public static function defaultSettings(): array { - return [ - // When TRUE, display comma-separated, otherwise are HTML 'ul'. - 'display_inline' => FALSE, - ] + parent::defaultSettings(); - } - - /** - * {@inheritdoc} - */ - public function settingsForm(array $form, FormStateInterface $form_state): array { - $form = parent::settingsForm($form, $form_state); - - $form['display_inline'] = [ - '#title' => $this->t('Display inline'), - '#description' => $this->t('When checked, the column names will display as a comma-separated list. Otherwise, they will display as an HTML unordered list.'), - '#type' => 'checkbox', - '#default_value' => $this->getSetting('display_inline') ?? FALSE, - ]; - - return $form; - } - /** * {@inheritdoc} */ @@ -64,25 +37,12 @@ public function viewElements(FieldItemListInterface $items, $langcode) { $column_names[] = $item->entity->field_column_name->value; } - if ($this->getSetting('display_inline')) { - // Theme as comma-separated list of the column names. - $list = [ - '#markup' => implode(', ', $column_names), - ]; - } - else { - // Theme as unordered list of the column names. - $list = [ - '#theme' => 'item_list', - '#list_type' => 'ul', - '#items' => $column_names, - '#empty' => $this->t('None'), - ]; - } - $element = []; - $element[] = $list; + // Display each column name as a markup element. + foreach ($column_names as $column_name) { + $element[] = ['#markup' => $column_name]; + } return $element; }