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() {
return [
// Todo: query for all content types.
'expand_years' => FALSE,
'content_types' => ['article'],
] + parent::defaultConfiguration();
@@ -40,11 +39,13 @@ class ArchiveTreeBlock extends BlockBase {
$options[$type->id()] = $type->label();
}
$form['content_types'] = [
'#type' => 'checkboxes',
'#type' => 'select',
'#title' => $this->t('Content types to include'),
'#options' => $options,
'#default_value' => $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'] = [
@@ -90,15 +91,15 @@ class ArchiveTreeBlock extends BlockBase {
$tree[$year] = ['count' => 0, 'months' => []];
}
if (!isset($tree[$year]['months'][$month])) {
$tree[$year]['months'][$month] = 0;
$tree[$year]['months'][$month] = ['count' => 0];
}
$tree[$year]['count']++;
$tree[$year]['months'][$month]++;
$tree[$year]['months'][$month]['count']++;
}
krsort($tree); // Descending years
foreach ($tree as &$data) {
krsort($data['months']); // Descending months
foreach ($tree as $year => $data) {
krsort($tree[$year]['months']); // Descending months
}
$output = '';
@@ -109,12 +110,14 @@ class ArchiveTreeBlock extends BlockBase {
$output .= '<details' . $open . '><summary class="archive-tree-year">';
$output .= '<a href="' . $year_url . '">' . $year . '</a> (' . $data['count'] . ')';
$output .= '</summary>';
foreach ($data['months'] as $month => $count) {
if (!empty($data['months'])) {
foreach ($data['months'] as $month => $month_data) {
$month_url = '/archive-tree/' . $year . '/' . $month;
$output .= '<div class="archive-tree-month">';
$output .= '<a href="' . $month_url . '">' . $month . '</a> (' . $count . ')';
$output .= '<a href="' . $month_url . '">' . $month . '</a> (' . $month_data['count'] . ')';
$output .= '</div>';
}
}
$output .= '</details>';
}