This commit is contained in:
2026-01-24 13:18:20 -06:00
parent 8797b7c96e
commit 2e1878280e

View File

@@ -25,7 +25,6 @@ class ArchiveTreeBlock extends BlockBase {
public function defaultConfiguration() { public function defaultConfiguration() {
return [ return [
// Todo: query for all content types.
'expand_years' => FALSE, 'expand_years' => FALSE,
'content_types' => ['article'], 'content_types' => ['article'],
] + parent::defaultConfiguration(); ] + parent::defaultConfiguration();
@@ -40,11 +39,13 @@ class ArchiveTreeBlock extends BlockBase {
$options[$type->id()] = $type->label(); $options[$type->id()] = $type->label();
} }
$form['content_types'] = [ $form['content_types'] = [
'#type' => 'checkboxes', '#type' => 'select',
'#title' => $this->t('Content types to include'), '#title' => $this->t('Content types to include'),
'#options' => $options, '#options' => $options,
'#default_value' => $this->configuration['content_types'], '#default_value' => $this->configuration['content_types'],
'#description' => $this->t('Select one or more content types to include in the archive tree.'), '#description' => $this->t('Select one or more content types to include in the archive tree.'),
'#multiple' => TRUE,
'#size' => min(8, count($options)),
'#required' => TRUE, '#required' => TRUE,
]; ];
$form['expand_years'] = [ $form['expand_years'] = [
@@ -90,15 +91,15 @@ class ArchiveTreeBlock extends BlockBase {
$tree[$year] = ['count' => 0, 'months' => []]; $tree[$year] = ['count' => 0, 'months' => []];
} }
if (!isset($tree[$year]['months'][$month])) { if (!isset($tree[$year]['months'][$month])) {
$tree[$year]['months'][$month] = 0; $tree[$year]['months'][$month] = ['count' => 0];
} }
$tree[$year]['count']++; $tree[$year]['count']++;
$tree[$year]['months'][$month]++; $tree[$year]['months'][$month]['count']++;
} }
krsort($tree); // Descending years krsort($tree); // Descending years
foreach ($tree as &$data) { foreach ($tree as $year => $data) {
krsort($data['months']); // Descending months krsort($tree[$year]['months']); // Descending months
} }
$output = ''; $output = '';
@@ -109,11 +110,13 @@ class ArchiveTreeBlock extends BlockBase {
$output .= '<details' . $open . '><summary class="archive-tree-year">'; $output .= '<details' . $open . '><summary class="archive-tree-year">';
$output .= '<a href="' . $year_url . '">' . $year . '</a> (' . $data['count'] . ')'; $output .= '<a href="' . $year_url . '">' . $year . '</a> (' . $data['count'] . ')';
$output .= '</summary>'; $output .= '</summary>';
foreach ($data['months'] as $month => $count) { if (!empty($data['months'])) {
$month_url = '/archive-tree/' . $year . '/' . $month; foreach ($data['months'] as $month => $month_data) {
$output .= '<div class="archive-tree-month">'; $month_url = '/archive-tree/' . $year . '/' . $month;
$output .= '<a href="' . $month_url . '">' . $month . '</a> (' . $count . ')'; $output .= '<div class="archive-tree-month">';
$output .= '</div>'; $output .= '<a href="' . $month_url . '">' . $month . '</a> (' . $month_data['count'] . ')';
$output .= '</div>';
}
} }
$output .= '</details>'; $output .= '</details>';
} }