From 319a5a22f5c11bd01049c0bbb621044c71a325de Mon Sep 17 00:00:00 2001 From: Korca Date: Thu, 7 Nov 2024 09:33:41 +0100 Subject: [PATCH 01/11] add-aria-setsize-and-aria-posinset-attr-to-results --- src/Components/AjaxSelect/Entities/AbstractEntity.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index f189e99..5431777 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -125,18 +125,20 @@ public abstract function formatValues($values); public function formatJsonValues($values) { $result = [ ]; $titles = $this->formatValues($values); - + $count = count($titles); + $i = 1; foreach ($titles as $id => $item) { if (!is_array($item)) { $item = [ 'text' => $item, ]; } - $item['id'] = $id; + $item['aria-posinset'] = $i; + $item['aria-setsize'] = $count; $result[] = $item; + $i++; } - return $result; } From 4fbe51b023517a1ee1ee4202864b88fd4ada5ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Konvi=C4=8Dka?= Date: Tue, 19 Nov 2024 12:40:14 +0100 Subject: [PATCH 02/11] Added check before calling method_exists --- src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php b/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php index e3821b0..52edf21 100644 --- a/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php +++ b/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php @@ -19,7 +19,7 @@ public static function applyOrByIdFilter(array $config, \Nette\Forms\Container $ $defaultValue = $form->getEntity()->{'get' . ucfirst($attributeName)}(); //It can be Kdyby\Doctrine\Collections\Readonly\ReadOnlyCollectionWrapper - if (method_exists($defaultValue, 'toArray')) { + if ($defaultValue && method_exists($defaultValue, 'toArray')) { $defaultValue = $defaultValue->toArray(); } From 35f3cc0fe84e358a1b09f1c96853ce0cb098754c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Konvi=C4=8Dka?= Date: Mon, 6 Jan 2025 13:02:43 +0100 Subject: [PATCH 03/11] Check array before calling method_exists toArray --- src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php b/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php index 22591f0..c4b89d4 100644 --- a/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php +++ b/src/Components/AjaxSelect/Traits/OrByIdFilterTrait.php @@ -15,7 +15,7 @@ public function applyOrByIdFilter(array $config, \Nette\Forms\Container $form, s $defaultValue = $form->getEntity()->{'get' . ucfirst($attributeName)}(); //It can be Kdyby\Doctrine\Collections\Readonly\ReadOnlyCollectionWrapper - if ($defaultValue && method_exists($defaultValue, 'toArray')) { + if ($defaultValue && !is_array($defaultValue) && method_exists($defaultValue, 'toArray')) { $defaultValue = $defaultValue->toArray(); } From 08d3b2eabb6075cf983389057d4647b8b076d504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 26 Jan 2025 13:24:05 +0100 Subject: [PATCH 04/11] Update AjaxService.php --- src/Components/AjaxSelect/Services/AjaxService.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Components/AjaxSelect/Services/AjaxService.php b/src/Components/AjaxSelect/Services/AjaxService.php index b309862..54aff8c 100644 --- a/src/Components/AjaxSelect/Services/AjaxService.php +++ b/src/Components/AjaxSelect/Services/AjaxService.php @@ -32,7 +32,7 @@ public function addEntityFactory($entityName, $entityFactory) { * @param AjaxSelect\Interfaces\IAjaxServiceControl $clientControl * @return AjaxSelect\Entities\AbstractEntity */ - public function createEntity($entityName, AjaxSelect\Interfaces\IAjaxServiceControl $clientControl = NULL) { + public function createEntity($entityName, ?AjaxSelect\Interfaces\IAjaxServiceControl $clientControl = NULL) { if ($entityName instanceof AjaxSelect\Entities\AbstractEntity) { $entity = $entityName; } else { From 460dc272cb951859bbe5261ce9f1ff03c6719d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 11 May 2025 12:54:50 +0200 Subject: [PATCH 05/11] Update composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 9afa69f..b78d4b6 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "nette/di": "^3.0", "nette/utils": "^3.0 | ^4.0", "nette/application": "*", - "adt/doctrine-components": "^2.9" + "adt/doctrine-components": "^2.9|^3.0" }, "autoload": { "psr-4": { From 4a58025a41419f7eff7edd9654905d70dbcb7ea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Thu, 15 May 2025 16:03:16 +0200 Subject: [PATCH 06/11] Passes form values to entity hydration Ensures that form values are available during entity hydration, allowing for more context-aware data handling within the AjaxSelect component. This allows hydration logic to take form context into consideration when formatting JSON values, which ensures proper data handling and rendering of selected options. --- src/Components/AjaxSelect/Entities/AbstractEntity.php | 9 +++++---- .../AjaxSelect/Traits/AjaxServiceControlTrait.php | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index 33fe221..607950b 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -15,7 +15,7 @@ abstract class AbstractEntity const OPTION_QUERY = 'q'; public abstract function formatValues($values): array; - public abstract function hydrateValues($values): array; + public abstract function hydrateValues($values, array $formValues = []): array; protected abstract function createQueryObject(): QueryObject; @@ -122,9 +122,9 @@ public function findValues($limit) { * @param array $values * @return array List of items. */ - public function formatJsonValues($values) { + public function formatJsonValues($values, array $formValues = []) { $result = [ ]; - $titles = $this->formatValues($values); + $titles = $this->formatValues($this->hydrateValues($values, $formValues)); $count = count($titles); $i = 1; foreach ($titles as $id => $item) { @@ -200,7 +200,8 @@ public function done() { ? $this->formatJsonValues( is_array($controlValue) ? $controlValue - : [ $controlValue ] + : [ $controlValue ], + $control->getForm()->getUntrustedValues('array') ) : [], 'queryParam' => static::OPTION_QUERY, diff --git a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php index 100d0ec..934e719 100644 --- a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php +++ b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php @@ -53,7 +53,7 @@ protected function processValues($values) { $validValues = array_merge($validValues, $invalidValues); } - $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues)); + $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues, $this->getForm()->getUntrustedValues('array'))); // add to list of valid values $this->setItems($this->getItems() + $validItems); From 2d680f3f69b02d5667cf12dac6fe3c675edb441f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Thu, 15 May 2025 16:13:00 +0200 Subject: [PATCH 07/11] Uses trusted form values Updates the code to use trusted form values instead of untrusted values when hydrating and formatting data. This change ensures that the application processes data that has been properly validated, preventing potential security issues and data integrity problems. --- src/Components/AjaxSelect/Entities/AbstractEntity.php | 2 +- src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index 607950b..1bad32e 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -201,7 +201,7 @@ public function done() { is_array($controlValue) ? $controlValue : [ $controlValue ], - $control->getForm()->getUntrustedValues('array') + $control->getForm()->getValues('array') ) : [], 'queryParam' => static::OPTION_QUERY, diff --git a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php index 934e719..f323d38 100644 --- a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php +++ b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php @@ -53,7 +53,7 @@ protected function processValues($values) { $validValues = array_merge($validValues, $invalidValues); } - $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues, $this->getForm()->getUntrustedValues('array'))); + $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues, $this->getForm()->getValues('array'))); // add to list of valid values $this->setItems($this->getItems() + $validItems); From 330c28691040472332ff7bc6ad77539eb74b30ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sun, 15 Jun 2025 20:54:27 +0200 Subject: [PATCH 08/11] Updates doctrine-components dependency Updates the doctrine-components dependency to the latest major version. This change removes the previous range constraint and ensures compatibility with newer features and bug fixes. Also updates namespace of QueryObject class. --- composer.json | 2 +- src/Components/AjaxSelect/Entities/AbstractEntity.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index b78d4b6..2416ad3 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "nette/di": "^3.0", "nette/utils": "^3.0 | ^4.0", "nette/application": "*", - "adt/doctrine-components": "^2.9|^3.0" + "adt/doctrine-components": "^3.0" }, "autoload": { "psr-4": { diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index 1bad32e..4f637f8 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -3,7 +3,7 @@ namespace ADT\Components\AjaxSelect\Entities; use ADT\Components\AjaxSelect; -use ADT\DoctrineComponents\QueryObject; +use ADT\DoctrineComponents\QueryObject\QueryObject; use Nette\Application\UI\Presenter; use Nette\SmartObject; From 0ae2a4de5d6e998f00b74a97d477dce71f133af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Sat, 31 Jan 2026 08:36:14 +0100 Subject: [PATCH 09/11] Updates dependencies and form validation Updates the dependencies to PHP 8.3 and a new forms component. Uses validated form values instead of all values when formatting and hydrating values, improving data handling and security. --- composer.json | 4 ++-- src/Components/AjaxSelect/Entities/AbstractEntity.php | 2 +- src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 2416ad3..432a857 100644 --- a/composer.json +++ b/composer.json @@ -4,8 +4,8 @@ "type": "library", "license": ["MIT", "BSD-3-Clause", "GPL-2.0", "GPL-3.0"], "require": { - "php": ">=7.1", - "nette/forms": "^3.0", + "php": ">=8.3", + "adt/nette-forms-components": "^2.3", "nette/di": "^3.0", "nette/utils": "^3.0 | ^4.0", "nette/application": "*", diff --git a/src/Components/AjaxSelect/Entities/AbstractEntity.php b/src/Components/AjaxSelect/Entities/AbstractEntity.php index 4f637f8..2bd32cd 100644 --- a/src/Components/AjaxSelect/Entities/AbstractEntity.php +++ b/src/Components/AjaxSelect/Entities/AbstractEntity.php @@ -201,7 +201,7 @@ public function done() { is_array($controlValue) ? $controlValue : [ $controlValue ], - $control->getForm()->getValues('array') + $control->getForm()->getValidatedValues('array') ) : [], 'queryParam' => static::OPTION_QUERY, diff --git a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php index f323d38..4e7f639 100644 --- a/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php +++ b/src/Components/AjaxSelect/Traits/AjaxServiceControlTrait.php @@ -53,7 +53,7 @@ protected function processValues($values) { $validValues = array_merge($validValues, $invalidValues); } - $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues, $this->getForm()->getValues('array'))); + $validItems = $this->getAjaxEntity()->formatValues($this->getAjaxEntity()->hydrateValues($validValues, $this->getForm()->getValidatedValues('array'))); // add to list of valid values $this->setItems($this->getItems() + $validItems); From d0fd9e1e1c5b649579a720d8335bc073131da9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Wed, 24 Jun 2026 08:58:32 +0200 Subject: [PATCH 10/11] Introduce Nette Forms and improve type consistency Adds the `nette/forms` dependency to expand form capabilities. Updates `getHttpData` method signature with type hints for clarity and consistency. --- composer.json | 5 +++-- src/Components/AjaxSelect/Traits/InvalidSetValueTrait.php | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 432a857..38a0b26 100644 --- a/composer.json +++ b/composer.json @@ -9,8 +9,9 @@ "nette/di": "^3.0", "nette/utils": "^3.0 | ^4.0", "nette/application": "*", - "adt/doctrine-components": "^3.0" - }, + "adt/doctrine-components": "^3.0", + "nette/forms": "^3.3" + }, "autoload": { "psr-4": { "ADT\\": "src/" diff --git a/src/Components/AjaxSelect/Traits/InvalidSetValueTrait.php b/src/Components/AjaxSelect/Traits/InvalidSetValueTrait.php index e2f5afe..6f75a61 100644 --- a/src/Components/AjaxSelect/Traits/InvalidSetValueTrait.php +++ b/src/Components/AjaxSelect/Traits/InvalidSetValueTrait.php @@ -35,7 +35,7 @@ public function setInvalidValueMode($mode) { return $this; } - protected abstract function getHttpData($type, ?string $htmlTail = NULL); + protected abstract function getHttpData(int $type, ?string $htmlTail = NULL): mixed; protected abstract function isDisabled(); /** From 4316fe6e15c2192644ff0ce1e3d8e1c9ac716e9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Kud=C4=9Blka?= Date: Wed, 24 Jun 2026 09:05:31 +0200 Subject: [PATCH 11/11] Pin `nette/forms` dependency to `3.2.x` series Restricts the allowed versions to `^3.2.9` to prevent potential compatibility issues with `3.3.x` releases. --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 38a0b26..80c71a3 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "nette/utils": "^3.0 | ^4.0", "nette/application": "*", "adt/doctrine-components": "^3.0", - "nette/forms": "^3.3" + "nette/forms": "^3.2.9" }, "autoload": { "psr-4": {