Skip to content

Instantly share code, notes, and snippets.

@newradius
Created June 19, 2019 10:44
Show Gist options
  • Save newradius/38a8a76544e07a4cace9698f15e6dd42 to your computer and use it in GitHub Desktop.
Save newradius/38a8a76544e07a4cace9698f15e6dd42 to your computer and use it in GitHub Desktop.
<?php
namespace CuatroOchenta\BackOfficeBundle\Form;
use Symfony\Component\Form\FormConfigInterface;
use Symfony\Component\Form\FormInterface;
class FormOptionReplacer
{
/**
* @param FormInterface $builder
* @param $property
* @param array $newOptions
* @return void
*/
public static function replace(FormInterface $builder, $property, array $newOptions)
{
/** @var FormConfigInterface $config */
$config = $builder->get($property)->getConfig();
$options = $config->getOptions();
$type = $config->getType();
$builder->add($config->getName(), $type->getName(), array_replace($options, $newOptions));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment