Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merged pull request #60 from craue/fix-form
fixed issues with unintentional value changes when using the built-in form
- Loading branch information
Showing
10 changed files
with
240 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Tests/IntegrationTestBundle/Entity/CanBeDisabledSetting.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Craue\ConfigBundle\Tests\IntegrationTestBundle\Entity; | ||
|
||
use Craue\ConfigBundle\Entity\BaseSetting; | ||
|
||
/** | ||
* @author Christian Raue <christian.raue@gmail.com> | ||
* @copyright 2011-2023 Christian Raue | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
class CanBeDisabledSetting extends BaseSetting { | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $disabled = false; | ||
|
||
public function setDisabled(bool $disabled) : void { | ||
$this->disabled = $disabled; | ||
} | ||
|
||
public function isDisabled() : bool { | ||
return $this->disabled; | ||
} | ||
|
||
/** | ||
* Creates a {@code CanBeDisabledSetting}. | ||
* @param string $name | ||
* @param string|null $value | ||
* @param string|null $section | ||
* @param bool $disabled | ||
* @return CanBeDisabledSetting | ||
*/ | ||
public static function create($name, $value = null, $section = null, $disabled = false) { | ||
$setting = parent::create($name, $value, $section); | ||
$setting->setDisabled($disabled); | ||
|
||
return $setting; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
Tests/IntegrationTestBundle/Form/Extension/SettingTypeExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Craue\ConfigBundle\Tests\IntegrationTestBundle\Form\Extension; | ||
|
||
use Craue\ConfigBundle\Entity\SettingInterface; | ||
use Craue\ConfigBundle\Form\Type\SettingType; | ||
use Symfony\Component\Form\AbstractTypeExtension; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
/** | ||
* @author Christian Raue <christian.raue@gmail.com> | ||
* @copyright 2011-2023 Christian Raue | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
class SettingTypeExtension extends AbstractTypeExtension { | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options) : void { | ||
/* @var $formData SettingInterface */ | ||
$formData = $options['data']; | ||
|
||
$config = $builder->get('value')->getForm()->getConfig(); | ||
|
||
$builder->add($config->getName(), get_class($config->getType()->getInnerType()), array_merge($config->getOptions(), [ | ||
'disabled' => $formData->isDisabled(), | ||
])); | ||
} | ||
|
||
public static function getExtendedTypes() : iterable { | ||
return [SettingType::class]; | ||
} | ||
|
||
} |
Oops, something went wrong.