Multiple content type selection working
This commit is contained in:
18
archive_tree.install
Normal file
18
archive_tree.install
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall hooks for the Archive Tree module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_uninstall().
|
||||
*/
|
||||
function archive_tree_uninstall() {
|
||||
// Remove the views provided by this module on uninstall.
|
||||
$view_ids = ['archive_by_year', 'archive_by_month'];
|
||||
foreach ($view_ids as $view_id) {
|
||||
if ($view = \Drupal::entityTypeManager()->getStorage('view')->load($view_id)) {
|
||||
$view->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 .= '<details' . $open . '><summary class="archive-tree-year">';
|
||||
$output .= '<a href="' . $year_url . '">' . $year . '</a> (' . $data['count'] . ')';
|
||||
$output .= '</summary>';
|
||||
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 .= '<div class="archive-tree-month">';
|
||||
$output .= '<a href="' . $month_url . '">' . $month . '</a> (' . $month_data['count'] . ')';
|
||||
$output .= '</div>';
|
||||
|
||||
Reference in New Issue
Block a user