Para realizar esto, se debe de utilizar una clase que implemente la interfaz EventSubscriberInterface y suscribirla al objeto de la Forma en el evento PRE-BIND, luego esta verificará si el usuario no envió valor al campo, si es asi se eliminará el campo para que no sea considerado al momento de la actualización.
Mas Información
Asociarlo al objeto en sonata:
protected function configureFormFields(FormMapper $formMapper) { ///BLLA ////..... $subscriber = new IgnoreBlankFieldListener($formMapper->getFormBuilder()->getFormFactory(), 'password'); $formMapper->getFormBuilder()->addEventSubscriber($subscriber); //SEGUIR }Este es la clase que utilice que cree, sirve para objetos normales o arreglos.
namespace Acme\TestBundle\Admin; use Symfony\Component\Form\FormEvent; use Symfony\Component\Form\FormEvents; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class IgnoreBlankFieldListener implements EventSubscriberInterface { private $factory; private $name; public function __construct(FormFactoryInterface $factory, $name) { $this->factory = $factory; $this->name = $name; } public static function isNotEmpty($var ) { if(is_array($var)) { $notempty = false; foreach( $var as $v ) { $notempty = $notempty || !IgnoreBlankFieldListener::isNotEmpty($v); } return $notempty; } else return !empty ($var); } public static function isEmpty( $var ) { return IgnoreBlankFieldListener::isNotEmpty($var); } public function preBind(FormEvent $event) { $data = $event->getData(); $data_name = $data[$this->name]; if( IgnoreBlankFieldListener::isEmpty($data_name) ) { $form = $event->getForm(); unset( $data[$this->name] ); $event->setData($data); $form->remove($this->name); } } public static function getSubscribedEvents() { return array(FormEvents::PRE_BIND => 'preBind'); } }
Casinos Near Casino, NC, PA - Mapyro
ReplyDeleteFind the 고양 출장안마 closest casinos to Casino, NC, PA near melbet you. Discover short videos, 부산광역 출장샵 video and high definition local 김제 출장마사지 gems. Search for similar 김천 출장샵