diff --git a/composer.json b/composer.json index 73cca1e9..82836774 100644 --- a/composer.json +++ b/composer.json @@ -64,6 +64,13 @@ "build/themes/contrib/{$name}": ["type:drupal-theme"] }, "patches": {}, + "patches-ignore": { + "openeuropa/open_vocabularies" : { + "drupal/core" : { + "Entity display entities are incorrectly unserialized @see https://www.drupal.org/project/drupal/issues/3171333" : "https://www.drupal.org/files/issues/2020-09-17/3171333-6.patch" + } + } + }, "drupal-scaffold": { "locations": { "web-root": "./build" diff --git a/src/Plugin/MultiselectFilterField/ListField.php b/src/Plugin/MultiselectFilterField/ListField.php index 33e76bc6..e9420cfa 100644 --- a/src/Plugin/MultiselectFilterField/ListField.php +++ b/src/Plugin/MultiselectFilterField/ListField.php @@ -53,7 +53,7 @@ public function getDefaultValuesLabel(): string { return ''; } - $filter_value = parent::getDefaultValues(); + $filter_value = array_filter(parent::getDefaultValues()); return implode(', ', array_map(function ($value) use ($field_definition) { return $field_definition->getSetting('allowed_values')[$value]; }, $filter_value)); diff --git a/src/Plugin/facets/widget/CheckboxWidget.php b/src/Plugin/facets/widget/CheckboxWidget.php deleted file mode 100755 index 62898b7e..00000000 --- a/src/Plugin/facets/widget/CheckboxWidget.php +++ /dev/null @@ -1,62 +0,0 @@ -getValue($facet->id()))) { - return []; - } - return parent::prepareValueForUrl($facet, $form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function buildDefaultValueForm(array $form, FormStateInterface $form_state, FacetInterface $facet, ListPresetFilter $preset_filter = NULL): array { - return parent::buildDefaultValueForm($form, $form_state, $facet, $preset_filter); - } - - /** - * {@inheritdoc} - */ - public function getDefaultValuesLabel(FacetInterface $facet, ListSourceInterface $list_source, ListPresetFilter $filter): string { - return parent::getDefaultValuesLabel($facet, $list_source, $filter); - } - - /** - * {@inheritdoc} - */ - public function prepareDefaultFilterValue(FacetInterface $facet, array $form, FormStateInterface $form_state): array { - return parent::prepareDefaultFilterValue($facet, $form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function getValueFromActiveFilters(FacetInterface $facet, string $key): ?string { - return parent::getValueFromActiveFilters($facet, $key); - } - -} diff --git a/src/Plugin/facets/widget/MultiselectCheckboxWidget.php b/src/Plugin/facets/widget/MultiselectCheckboxWidget.php new file mode 100644 index 00000000..ff54d0af --- /dev/null +++ b/src/Plugin/facets/widget/MultiselectCheckboxWidget.php @@ -0,0 +1,94 @@ +get('list_source'); + $plugin_id = $this->multiselectPluginManager->getPluginIdForFacet($facet, $list_source); + $filter_values = $preset_filter ? $preset_filter->getValues() : []; + $form[$facet->id()] = $form[$facet->id()][$plugin_id]; + $form[$facet->id()]['#type'] = 'checkboxes'; + $form[$facet->id()]['#default_value'] = array_filter($filter_values); + return $form; + } + + /** + * {@inheritdoc} + */ + public function prepareDefaultFilterValue(FacetInterface $facet, array $form, FormStateInterface $form_state): array { + echo (__FUNCTION__); + return [ + 'operator' => $form_state->getValue('oe_list_pages_filter_operator'), + 'values' => $form_state->getValue($facet->id()) ?? [], + ]; + } + + /** + * {@inheritdoc} + */ + public function build(FacetInterface $facet) { + $results = $facet->getResults(); + $results = array_filter($results, function (Result $result) { + return $result->getDisplayValue() !== ""; + }); + + $options = $this->transformResultsToOptions($results); + + if ($options) { + $build[$facet->id()] = [ + '#type' => 'checkboxes', + '#title' => $facet->getName(), + '#options' => $options, + '#default_value' => $facet->getActiveItems(), + ]; + } + + $build['#cache']['contexts'] = [ + 'url.query_args', + 'url.path', + ]; + + return $build; + } + + /** + * {@inheritdoc} + */ + public function prepareValueForUrl(FacetInterface $facet, array &$form, FormStateInterface $form_state): array { + $values = $form_state->getValue($facet->id()); + // Remove "0" values, unchecked checkboxes. + $values = array_filter($values); + return $values; + } + +}