diff --git a/archive_tree.install b/archive_tree.install new file mode 100644 index 0000000..338406e --- /dev/null +++ b/archive_tree.install @@ -0,0 +1,18 @@ +getStorage('view')->load($view_id)) { + $view->delete(); + } + } +} diff --git a/config/install/views.view.archive_by_month.yml b/config/install/views.view.archive_by_month.yml index dd48141..6961fdc 100644 --- a/config/install/views.view.archive_by_month.yml +++ b/config/install/views.view.archive_by_month.yml @@ -1,8 +1,14 @@ +uuid: 9b5fc989-a450-4343-ab3f-e57ab584ba12 langcode: en status: true dependencies: + config: + - core.entity_view_mode.node.teaser module: - node + - user +_core: + default_config_hash: I60ibtlfXj35KEEGlqxYTFsTGaFcX9lYVHthkH8gu7s id: archive_by_month label: 'Archive by month' module: views @@ -74,8 +80,8 @@ display: total_pages: null id: 0 tags: - next: '››' - previous: '‹‹' + next: ›› + previous: ‹‹ expose: items_per_page: false items_per_page_label: 'Items per page' @@ -179,6 +185,45 @@ display: type: none fail: 'not found' validate_options: { } + type: + id: type + table: node_field_data + field: type + relationship: none + group_type: group + admin_label: '' + entity_type: node + plugin_id: string + default_action: ignore + exception: + value: all + title_enable: false + title: All + title_enable: false + title: '' + default_argument_type: fixed + default_argument_options: + argument: '' + summary_options: + base_path: '' + count: true + override: false + items_per_page: 25 + summary: + sort_order: asc + number_of_records: 0 + format: default_summary + specify_validation: false + validate: + type: none + fail: 'not found' + validate_options: { } + glossary: false + limit: 0 + case: none + path_case: none + transform_dash: false + break_phrase: true filters: status: id: status @@ -226,7 +271,7 @@ display: position: 1 display_options: display_extenders: { } - path: archive-tree/%/% + path: archive-tree/%/%/% cache_metadata: max-age: -1 contexts: diff --git a/config/install/views.view.archive_by_year.yml b/config/install/views.view.archive_by_year.yml index bf03a59..b040863 100644 --- a/config/install/views.view.archive_by_year.yml +++ b/config/install/views.view.archive_by_year.yml @@ -1,3 +1,4 @@ +uuid: 258b2d2d-134b-4d7d-a144-8ae6a3c5fd70 langcode: en status: true dependencies: @@ -6,6 +7,8 @@ dependencies: module: - node - user +_core: + default_config_hash: 7b984zuFjzuh4whcCt-ScrAjD2Swi86IATSQS4HY-dI id: archive_by_year label: 'Archive by year' module: views @@ -77,8 +80,8 @@ display: total_pages: null id: 0 tags: - next: '››' - previous: '‹‹' + next: ›› + previous: ‹‹ expose: items_per_page: false items_per_page_label: 'Items per page' @@ -146,10 +149,47 @@ display: number_of_records: 0 format: default_summary specify_validation: false + validate: + type: none + type: + id: type + table: node_field_data + field: type + relationship: none + group_type: group + admin_label: '' + entity_type: node + plugin_id: string + default_action: ignore + exception: + value: all + title_enable: false + title: All + title_enable: false + title: '' + default_argument_type: fixed + default_argument_options: + argument: '' + summary_options: + base_path: '' + count: true + override: false + items_per_page: 25 + summary: + sort_order: asc + number_of_records: 0 + format: default_summary + specify_validation: false validate: type: none fail: 'not found' validate_options: { } + glossary: false + limit: 0 + case: none + path_case: none + transform_dash: false + break_phrase: true filters: status: id: status @@ -197,7 +237,7 @@ display: position: 1 display_options: display_extenders: { } - path: archive-tree/% + path: archive-tree/%/% cache_metadata: max-age: -1 contexts: diff --git a/src/Plugin/Block/ArchiveTreeBlock.php b/src/Plugin/Block/ArchiveTreeBlock.php index 8860d13..601ee02 100644 --- a/src/Plugin/Block/ArchiveTreeBlock.php +++ b/src/Plugin/Block/ArchiveTreeBlock.php @@ -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 .= ''; $output .= '' . $year . ' (' . $data['count'] . ')'; $output .= ''; 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 .= '
'; $output .= '' . $month . ' (' . $month_data['count'] . ')'; $output .= '
';