Skip to content

Commit

Permalink
Issue #455: Make data_set_column_name formatter return only the names
Browse files Browse the repository at this point in the history
This allows Views formatting to control how the multiple values are combined.
  • Loading branch information
lkmorlan committed May 2, 2024
1 parent fcbbe57 commit dff63ac
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 54 deletions.
3 changes: 1 addition & 2 deletions config/sync/views.view.site_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions html/modules/custom/bc_dc/config/schema/bc_dc.schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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}
*/
Expand All @@ -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;
}
Expand Down

0 comments on commit dff63ac

Please sign in to comment.