From 2e1878280e4ef376305f229c904ba27558ba1a3c Mon Sep 17 00:00:00 2001 From: Aaron Axvig Date: Sat, 24 Jan 2026 13:18:20 -0600 Subject: [PATCH] Fix loop --- src/Plugin/Block/ArchiveTreeBlock.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Plugin/Block/ArchiveTreeBlock.php b/src/Plugin/Block/ArchiveTreeBlock.php index a2d02f4..8860d13 100644 --- a/src/Plugin/Block/ArchiveTreeBlock.php +++ b/src/Plugin/Block/ArchiveTreeBlock.php @@ -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,11 +110,13 @@ class ArchiveTreeBlock extends BlockBase { $output .= ''; $output .= '' . $year . ' (' . $data['count'] . ')'; $output .= ''; - foreach ($data['months'] as $month => $count) { - $month_url = '/archive-tree/' . $year . '/' . $month; - $output .= '
'; - $output .= '' . $month . ' (' . $count . ')'; - $output .= '
'; + if (!empty($data['months'])) { + foreach ($data['months'] as $month => $month_data) { + $month_url = '/archive-tree/' . $year . '/' . $month; + $output .= '
'; + $output .= '' . $month . ' (' . $month_data['count'] . ')'; + $output .= '
'; + } } $output .= ''; }