Skip to content

Commit

Permalink
Merge pull request #83 from szymach/2.1
Browse files Browse the repository at this point in the history
More unique identifier for form fields in FormFieldExtension
  • Loading branch information
rn0 authored Sep 2, 2021
2 parents 2be6a7d + 689b7cc commit 68762fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 23 additions & 8 deletions DataSource/Extension/Symfony/Form/Field/FormFieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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]);
Expand All @@ -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];
}
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 68762fa

Please sign in to comment.