Skip to content

Commit

Permalink
see cl 1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis Patzer committed Oct 6, 2020
1 parent a7c9e20 commit e443351
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 13 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,12 @@
# Changelog
All notable changes to this project will be documented in this file.

## [1.5.2] - 2020-10-01
- fixed reviseOptions -> now only respects the initial filter elements, since else inconsistent situations can happen
- added dynamicOptions to ChoiceType palette
- added translation
- fixed Intl bug in contao 4.9

## [1.5.1] - 2020-10-01
- added translation and sorting for sorting options

Expand Down
6 changes: 5 additions & 1 deletion src/Choice/CountryChoice.php
Expand Up @@ -57,9 +57,13 @@ protected function collect()
continue;
}

if (!$option['value']) {
continue;
}

if ($translator->getCatalogue()->has($option['label'])) {
$option['label'] = $translator->trans($option['label']);
} elseif (null !== ($label = Intl::getRegionBundle()->getCountryName($option['label']))) {
} elseif (version_compare(VERSION, '4.9', '<') && null !== ($label = Intl::getRegionBundle()->getCountryName($option['label']))) {
$option['label'] = $label;
}

Expand Down
43 changes: 35 additions & 8 deletions src/Choice/FieldOptionsChoice.php
Expand Up @@ -194,17 +194,44 @@ protected function getWidgetOptions(FilterConfigElementModel $element, array $fi
$options = $attributes['options'];
}

// cleanup/revise options (remove options that do not occur result list)
if (true === (bool) $element->reviseOptions && !empty($options) && isset($dca['foreignKey']) && !isset($dca['options']) && !isset($dca['options_callback'])) {
if (null !== ($filterQueryBuilder = System::getContainer()->get('huh.filter.manager')->getQueryBuilder($filter['id'], [$element->id]))) {
$filterQueryBuilder->select([$filter['dataContainer'].'.'.$element->field]);
$filterQueryBuilder->groupBy($filter['dataContainer'].'.'.$element->field);
if (true === (bool) $element->dynamicOptions) {
$options = [];

if (null !== ($queryBuilder = System::getContainer()->get('huh.filter.manager')->getInitialQueryBuilder($filter['id'], [$element->id], true))) {
$items = $queryBuilder->select([$filter['dataContainer'].'.'.$element->field])->execute()->fetchAll(FetchMode::COLUMN, 0);

// make the values unique and don't skip the empty value if available
$items = array_unique($items);

if (isset($dca['reference'])) {
foreach ($items as $item) {
$options[] = [
'value' => $item,
'label' => $dca['reference'][$item] ?? $item,
];
}
} else {
foreach ($items as $item) {
$options[] = [
'value' => $item,
'label' => $item,
];
}
}
}
} else {
// cleanup/revise options (remove options that do not occur result list)
if (true === (bool) $element->reviseOptions && !empty($options)) {
if (null !== ($filterQueryBuilder = System::getContainer()->get('huh.filter.manager')->getInitialQueryBuilder($filter['id'], [$element->id], true))) {
$filterQueryBuilder->select([$filter['dataContainer'].'.'.$element->field]);

$values = $filterQueryBuilder->execute()->fetchAll(FetchMode::COLUMN, 0);

$ids = $filterQueryBuilder->execute()->fetchAll(FetchMode::COLUMN, 0);
// make the values unique and don't skip the empty value if available
$values = array_merge([''], array_unique($values));

if (!empty($ids)) {
foreach ($options as $key => $option) {
if (!\in_array($option['value'], $ids)) {
if (!\in_array($option['value'], $values)) {
unset($options[$key]);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/contao/dca/tl_filter_config_element.php
Expand Up @@ -134,7 +134,7 @@
\HeimrichHannot\FilterBundle\Filter\Type\ColorType::TYPE
=> '{general_legend},title,type,isInitial;{config_legend},field,customName,customOperator,addDefaultValue;{visualization_legend},addPlaceholder,customLabel,hideLabel,inputGroup;{expert_legend},cssClass;{publish_legend},published;',
\HeimrichHannot\FilterBundle\Filter\Type\ChoiceType::TYPE
=> '{general_legend},title,type,isInitial;{config_legend},field,customOptions,adjustOptionLabels,reviseOptions,sortOptionValues,customName,customOperator,addDefaultValue,expanded,multiple,submitOnChange,addGroupChoiceField;{visualization_legend},addPlaceholder,customLabel,hideLabel,inputGroup;{expert_legend},cssClass;{publish_legend},published;',
=> '{general_legend},title,type,isInitial;{config_legend},field,customOptions,adjustOptionLabels,reviseOptions,dynamicOptions,sortOptionValues,customName,customOperator,addDefaultValue,expanded,multiple,submitOnChange,addGroupChoiceField;{visualization_legend},addPlaceholder,customLabel,hideLabel,inputGroup;{expert_legend},cssClass;{publish_legend},published;',
\HeimrichHannot\FilterBundle\Filter\Type\CountryType::TYPE
=> '{general_legend},title,type,isInitial;{config_legend},field,customCountries,customOptions,adjustOptionLabels,reviseOptions,sortOptionValues,customName,customOperator,addDefaultValue,expanded,multiple;{visualization_legend},addPlaceholder,customLabel,hideLabel,inputGroup;{expert_legend},cssClass;{publish_legend},published;',
\HeimrichHannot\FilterBundle\Filter\Type\ProximitySearchType::TYPE
Expand Down
Expand Up @@ -12,7 +12,7 @@
$lang['fields'] = ['Felder', 'Wählen Sie hier mehrere Felder aus, die in der gewählten Reihenfolge verknüpft werden sollen.'];
$lang['parentField'] = ['Eltern-DCA-Feld', 'Wählen Sie hier das verknüpfte Eltern-DCA-Feld aus.'];
$lang['customOptions'] = ['Optionen anpassen', 'Wählen Sie diese Option, um benutzerdefinierte Optionswerte festzulegen.'];
$lang['reviseOptions'] = ['Optionen bereinigen', 'Wählen Sie diese Option, um Optionswerte zu bereinigen (Optionen ohne Vorkommen in der Ergebnismenge auf Basis des aktuellen Filters). Wird nur unterstützt, wenn die Optionswerte über den Fremdschlüssel (foreignKey) des Felds ermittelt werden.'];
$lang['reviseOptions'] = ['Vorhandene Optionen bereinigen', 'Wählen Sie diese Option, um *vorhandene* Optionswerte (bspw. options_callback) zu bereinigen, d.h., Optionen ohne Vorkommen in der Ergebnismenge zu entfernen.'];
$lang['adjustOptionLabels'] = ['Optionen-Labels anpassen', 'Wählen Sie diese Option, wenn Sie die Labels der Optionswerte anpassen möchten.'];
$lang['optionLabelPattern'] = ['Optionen-Label', 'Wählen Sie ein Optionen-Label aus, auf dessen Vorlage die Optionslabels angepasst werden sollen.'];
$lang['sortOptionValues'] = ['Optionen sortieren', 'Wählen Sie diese Option, um die Optionswerte alphabetisch zu sortieren.'];
Expand Down Expand Up @@ -82,7 +82,7 @@
$lang['whereSql'] = ['Zusätzliches WHERE-SQL', 'Geben Sie hier SQL ein, welches dem WHERE-Statement hinzugefügt wird.'];
$lang['submitOnChange'] = ['Formular bei Änderung absenden (submitOnChange)', 'Wählen Sie diese Option, wenn der Nutzer das Formular bei Änderung abschicken soll.'];
$lang['alwaysShow'] = ['Immer anzeigen', 'Das Filterelement immer anzeigen.'];
$lang['dynamicOptions'] = ['Dynamische Optionen', 'Aktivieren Sie diese Option, um die Optionswerte anhand der Daten zu erhalten. Initiale Filterelemente mit Skalaren oder Array-Werten werden beachtet.'];
$lang['dynamicOptions'] = ['Optionswerte aus bestehenden Entitäten berechnen', 'Aktivieren Sie diese Option, um die Optionswerte anhand der vorhandenen Daten zu erhalten. Initiale Filterelemente mit Skalaren oder Array-Werten werden beachtet.'];
$lang['alternativeValueSource'] = ['Filterwert aus alternativer Quelle beziehen', 'Dieses Feld wird durch andere Bundles konfiguriert (bspw. heimrichhannot/contao-reader-bundle).'];
$lang['addGroupChoiceField'] = ['Gruppen-Choice hinzufügen', 'Wählen Sie diese Option, wenn den Choices ein Feld hinzugefügt werden soll, welches mehrere Choices gruppiert. Im Standardfall fungiert dies als Select-All-Field.'];
$lang['modifyGroupChoices'] = ['Gruppen-Choice-Optionen modifizieren', 'Wählen Sie diese Option, wenn Sie die Choices, die in diesem Feld gruppiert werden sollen einschränken wollen.'];
Expand Down
Expand Up @@ -77,7 +77,7 @@
$lang['whereSql'] = ['Additional WHERE-SQL', 'Enter SQL, which will be added to the WHERE statement.'];
$lang['submitOnChange'] = ['Submit form on change (submitOnChange)', 'Select this option if you want the user to submit the form on change.'];
$lang['alwaysShow'] = ['Show always', 'Always show the filter element.'];
$lang['dynamicOptions'] = ['Dynamic options', 'Use this option to get option values based on the underlaying data. Initial filters with skalar or array values are respected.'];
$lang['dynamicOptions'] = ['Dynamic options', 'Use this option to get option values based on the underlaying data. Initial filters with skalar or array values are respected.'];
$lang['addOptionCount'] = ['Show option entries count', 'Output the count of elements for each option. Works only if dynamic options are enabled.'];
$lang['optionCountLabel'] = ['Label for options with count', 'Choose the label format for options with count.'];

Expand Down

0 comments on commit e443351

Please sign in to comment.