Multiple content type selection working
This commit is contained in:
@@ -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