From 689b7ccc004aff52c26d43d596505fcdbf7112fa Mon Sep 17 00:00:00 2001 From: Piotr Szymaszek Date: Thu, 2 Sep 2021 11:53:34 +0200 Subject: [PATCH] More unique identifier for form fields in FormFieldExtension --- .travis.yml | 3 +- .../Symfony/Form/Field/FormFieldExtension.php | 31 ++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0382bb7..e2f6c0b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,10 +11,11 @@ matrix: env: global: - SYMFONY_DEPRECATIONS_HELPER=weak + COMPOSER_MEMORY_LIMIT=-1 before_script: - phpenv config-rm xdebug.ini - - COMPOSER_MEMORY_LIMIT=-1 composer update $COMPOSER_FLAGS + - composer update $COMPOSER_FLAGS script: - vendor/bin/phpcs diff --git a/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php b/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php index f56cd5d..3a0a524 100644 --- a/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php +++ b/DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php @@ -110,23 +110,24 @@ public function postBuildView(FieldEvent\ViewEventArgs $event) public function preBindParameter(FieldEvent\ParameterEventArgs $event) { $field = $event->getField(); + $datasource = $field->getDataSource(); + $datasourceName = $datasource ? $datasource->getName() : null; + if (null === $datasourceName || '' === $datasourceName) { + return; + } + $form = $this->getForm($field); if ($form === null) { return; } - $fieldOid = spl_object_hash($field); + $fieldOid = $this->getFieldHash($datasource, $field); $parameter = $event->getParameter(); if ($form->isSubmitted()) { $form = $this->getForm($field, true); } - $datasourceName = $field->getDataSource() ? $field->getDataSource()->getName() : null; - if (null === $datasourceName || '' === $datasourceName) { - return; - } - if ($this->hasParameterValue($parameter, $field)) { $this->parameters[$fieldOid] = $this->getParameterValue($parameter, $field); @@ -147,8 +148,12 @@ public function preBindParameter(FieldEvent\ParameterEventArgs $event) public function preGetParameter(FieldEvent\ParameterEventArgs $event) { $field = $event->getField(); - $fieldOid = spl_object_hash($field); + $datasource = $field->getDataSource(); + if (null === $datasource) { + return; + } + $fieldOid = $this->getFieldHash($datasource, $field); if (isset($this->parameters[$fieldOid])) { $parameters = []; $this->setParameterValue($parameters, $field, $this->parameters[$fieldOid]); @@ -167,7 +172,7 @@ protected function getForm(FieldTypeInterface $field, bool $force = false): ?For return null; } - $fieldOid = spl_object_hash($field); + $fieldOid = $this->getFieldHash($datasource, $field); if (isset($this->forms[$fieldOid]) && !$force) { return $this->forms[$fieldOid]; } @@ -350,4 +355,14 @@ private function clearParameterValue(array &$array, FieldTypeInterface $field): { unset($array[$field->getDataSource()->getName()][DataSourceInterface::PARAMETER_FIELDS][$field->getName()]); } + + /** + * @param DataSourceInterface $dataSource + * @param object $field + * @return string + */ + private function getFieldHash(DataSourceInterface $dataSource, $field): string + { + return spl_object_hash($dataSource) . spl_object_hash($field); + } }