commit c16a1e6d7e0a5d0dd2f1d92926154ab9faa092a6 Author: Aaron Axvig Date: Fri Jan 23 21:52:25 2026 -0600 Initial commit of archive_tree module diff --git a/archive_tree.info.yml b/archive_tree.info.yml new file mode 100644 index 0000000..338564a --- /dev/null +++ b/archive_tree.info.yml @@ -0,0 +1,6 @@ +name: Archive tree +machine_name: archive_tree +type: module +description: 'Provides an Archive tree block.' +core_version_requirement: ^10 || ^11 +package: Custom diff --git a/archive_tree.libraries.yml b/archive_tree.libraries.yml new file mode 100644 index 0000000..b6823db --- /dev/null +++ b/archive_tree.libraries.yml @@ -0,0 +1,5 @@ +archive_tree_styles: + version: 1.x + css: + theme: + css/archive_tree.css: {} diff --git a/archive_tree.module b/archive_tree.module new file mode 100644 index 0000000..b592714 --- /dev/null +++ b/archive_tree.module @@ -0,0 +1,2 @@ +getStorage('node'); + $query = $storage->getQuery() + ->condition('type', 'article') + ->condition('status', 1) + ->sort('created', 'DESC') + ->accessCheck(TRUE) + ->addTag('DANGEROUS_ACCESS_CHECK_OPT_OUT'); + $nids = $query->execute(); + $nodes = $storage->loadMultiple($nids); + + $tree = []; + foreach ($nodes as $node) { + $created = $node->getCreatedTime(); + $year = date('Y', $created); + $month = date('m', $created); + if (!isset($tree[$year])) { + $tree[$year] = ['count' => 0, 'months' => []]; + } + if (!isset($tree[$year]['months'][$month])) { + $tree[$year]['months'][$month] = 0; + } + $tree[$year]['count']++; + $tree[$year]['months'][$month]++; + } + + krsort($tree); // Descending years + foreach ($tree as &$data) { + krsort($data['months']); // Descending months + } + + $output = ''; + foreach ($tree as $year => $data) { + $year_url = '/archive-tree/' . $year; + $output .= '
'; + $output .= '' . $year . ' (' . $data['count'] . ')'; + $output .= ''; + foreach ($data['months'] as $month => $count) { + $month_url = '/archive-tree/' . $year . '/' . $month; + $output .= '
'; + $output .= '' . $month . ' (' . $count . ')'; + $output .= '
'; + } + $output .= '
'; + } + + return [ + '#markup' => $output, + '#allowed_tags' => ['details', 'summary', 'a', 'div'], + '#attached' => [ + 'library' => [ + 'archive_tree/archive_tree_styles', + ], + ], + ]; + } +}