Multiple content type selection working

This commit is contained in:
2026-01-24 13:59:58 -06:00
parent 2e1878280e
commit f0e38a4b9c
4 changed files with 116 additions and 14 deletions

View File

@@ -26,7 +26,7 @@ class ArchiveTreeBlock extends BlockBase {
public function defaultConfiguration() {
return [
'expand_years' => FALSE,
'content_types' => ['article'],
'content_types' => [],
] + parent::defaultConfiguration();
}
@@ -39,13 +39,11 @@ class ArchiveTreeBlock extends BlockBase {
$options[$type->id()] = $type->label();
}
$form['content_types'] = [
'#type' => 'select',
'#type' => 'checkboxes',
'#title' => $this->t('Content types to include'),
'#options' => $options,
'#default_value' => $this->configuration['content_types'],
'#default_value' => isset($this->configuration['content_types']) ? $this->configuration['content_types'] : [],
'#description' => $this->t('Select one or more content types to include in the archive tree.'),
'#multiple' => TRUE,
'#size' => min(8, count($options)),
'#required' => TRUE,
];
$form['expand_years'] = [
@@ -61,7 +59,7 @@ class ArchiveTreeBlock extends BlockBase {
public function blockSubmit($form, FormStateInterface $form_state) {
parent::blockSubmit($form, $form_state);
$this->configuration['expand_years'] = $form_state->getValue('expand_years');
$selected_types = array_filter($form_state->getValue('content_types'));
$selected_types = array_keys(array_filter($form_state->getValue('content_types')));
$this->configuration['content_types'] = $selected_types;
}
@@ -104,15 +102,16 @@ class ArchiveTreeBlock extends BlockBase {
$output = '';
$expand = !empty($this->configuration['expand_years']);
$type_arg = implode(',', $types);
foreach ($tree as $year => $data) {
$year_url = '/archive-tree/' . $year;
$year_url = '/archive-tree/' . $year . '/' . $type_arg;
$open = $expand ? ' open' : '';
$output .= '<details' . $open . '><summary class="archive-tree-year">';
$output .= '<a href="' . $year_url . '">' . $year . '</a> (' . $data['count'] . ')';
$output .= '</summary>';
if (!empty($data['months'])) {
foreach ($data['months'] as $month => $month_data) {
$month_url = '/archive-tree/' . $year . '/' . $month;
$month_url = '/archive-tree/' . $year . '/' . $month . '/' . $type_arg;
$output .= '<div class="archive-tree-month">';
$output .= '<a href="' . $month_url . '">' . $month . '</a> (' . $month_data['count'] . ')';
$output .= '</div>';