Register an event to submit a form
default is the form before the element which launch the event
@param string $elmId (without #)
@param string $formId (without #)
@param string $event
@param string $targetId
@return $this
511996
public function registerSubmitLink(string $elmId, string $formId = '', string $event = self::EVENT_CLIC, string $targetId = '', bool $preventDefault = true)
    {
        $linkSelector = '$("#' . $elmId . '").';
        $script  = $linkSelector . $event . '(function(e){';
        $script .= $preventDefault ? 'e.preventDefault();' : '';
        $target  = $targetId ? ", '" . $targetId . "'" : '';
        $formSelector = $formId
                      ? '$("#' . $formId . '")' 
                      : $linkSelector . 'prev("form")';
        //$script .= 'console.log(' . $formSelector . ');';
        $script .= '$.ajaxCall(' . $formSelector . $target . ')});';
        return $this->registerScript($script);
    }
216987
function onQuickFormEvent($event, $arg, &$caller)
    {
        switch ($event) {
            case 'createElement':
                $caller->setType($arg[0], PARAM_INT);
                break;
        }
        return parent::onQuickFormEvent($event, $arg, $caller);
    }
658856
public function createTarget($targetId, $base)
    {

        if(!is_string($base) && !is_array($base)){
            throw new \common_Exception('Invalid base format');
        }

        $array = array(
            'base'  => $base,
            'available' => array()
        );
        $this->set($targetId, $array);
    }
101639
public function onBind(FormEvent $event)
    {
        // BC prevention for class extending this one.
        if (self::class !== \get_called_class()) {
            @trigger_error(
                __METHOD__.' is deprecated since 2.3 and will be renamed in 4.0.'
                .' Use '.__CLASS__.'::onSubmit instead.',
                E_USER_DEPRECATED
            );
        }

        $this->onSubmit($event);
    }
56531
function onQuickFormEvent($event, $arg, &$caller)
    {
        switch ($event) {
            case 'createElement':
                static::__construct($arg[0], $arg[1], $arg[2], $arg[3], $arg[4]);
                if ($caller->getAttribute('data-random-ids') && !$this->getAttribute('id')) {
                    $this->_generateId();
                    $this->updateAttributes(array('id' => $this->getAttribute('id') . '_' . random_string()));
                }
                break;
            case 'addElement':
                $this->onQuickFormEvent('createElement', $arg, $caller);
                $this->onQuickFormEvent('updateValue', null, $caller);
                break;
            case 'updateValue':
                // constant values override both default and submitted ones
                // default values are overriden by submitted
                $value = $this->_findValue($caller->_constantValues);
                if (null === $value) {
                    $value = $this->_findValue($caller->_submitValues);
                    if (null === $value) {
                        $value = $this->_findValue($caller->_defaultValues);
                    }
                }
                if (null !== $value) {
                    $this->setValue($value);
                }
                break;
            case 'setGroupValue':
                $this->setValue($arg);
        }
        return true;
    }
135142
public function onSubmit(FormRuntime $formRuntime, &$elementValue)
    {
        $fileTypeValidator = new FileTypeValidator(array('allowedExtensions' => $this->properties['allowedExtensions']));
        $this->addValidator($fileTypeValidator);
    }
921822
function onQuickFormEvent($event, $arg, &$caller)
    {
        switch ($event) {
            case 'createElement':
                $this->_formid = $caller->getAttribute('id');
                break;
        }
        return parent::onQuickFormEvent($event, $arg, $caller);
    }
36171
public function setId($id)
    {
        if (($content = $this->getContent()) instanceof FormInterface) {
            $content->setId($id);
        }

        return $this;
    }
921190
protected function attachEvent(EventManagerInterface $events, $id, $event, $callback)
    {
        /** @var \Zend\EventManager\SharedEventManager $sharedEvents */
        $sharedEvents = $events->getSharedManager();

        $this->listeners[] = $sharedEvents->attach($id, $event, array($this, $callback), 100);
    }
195590
public function onSubmit(FormEvent $event)
    {
        $form = $event->getForm()->getParent();
        $data = $form->getData();

        if (!\is_object($data)) {
            return;
        }

        $accessor = PropertyAccess::createPropertyAccessor();
        $newCollection = $accessor->getValue($data, $this->name);
        if (!$newCollection instanceof Collection) {
            return;
        }
        /* @var $newCollection Collection */

        $newCollection->clear();

        /** @var $item FormBuilder */
        foreach ($form->get($this->name) as $key => $item) {
            if ($item->get('_delete')->getData()) {
                // do not re-add a deleted child
                continue;
            }
            if ($item->getName() && !is_numeric($item->getName())) {
                // keep key in collection
                $newCollection[$item->getName()] = $item->getData();
            } else {
                $newCollection[] = $item->getData();
            }
        }
    }
334629
public function copyAction($sourceId, $targetId, $lang)
    {
        $em = $this->getDoctrine()->getManager();
        $source = $this->getPage($sourceId);
        $target = $this->getPage($targetId);
        $newPage = clone($source);
        $newPage->setParent($target);
        // Children page
        if ($target->getLang())
        {
            $newPage->setLang($target->getLang());
        }
        else
        {
            $newPage->setLang($lang);
            $newPage->setPosition($em->getRepository('FulgurioLightCMSBundle:Page')->getNextPosition($target));
        }
        $newPage->setStatus('draft');
        $newPage->setSourceId($sourceId);
        $models = $this->container->getParameter('fulgurio_light_cms.models');
        return $this->createPage($newPage, array('pageMetas' => $this->getPageMetas($sourceId), 'parent' => $target, 'sourceId' => $sourceId), $models);
    }
413105
public function moveNode($headId, $targetId = null, $mode = self::MODE_UNDER)
    {
        $head = $this->getNode($headId);
        $target = $this->getNode($targetId);

        switch ($mode) {
            case self::MODE_BEFORE:
                $operation = new MoveBefore($head, $target, $this->config, $this);
                break;
            case self::MODE_AFTER:
                $operation = new MoveAfter($head, $target, $this->config, $this);
                break;
            case self::MODE_UNDER:
                $operation = new MoveUnderEnd($head, $target, $this->config, $this);
                break;
        }

        $operation->run();
    }
832276
protected void setForm(final T bean, final AjaxRequestTarget target) {
        LOG.debug("Setting form to {}", bean);

        // update the model with the new bean
        formModel.setObject(bean);

        // add the form to the target
        target.add(form);

        // update the button
        updateSaveButton.setModel(Model.of("Update"));
        target.add(updateSaveButton);
    }
869184
public function submit(FormEvent $event)
    {
        $image = $event->getData();

        if ($image && $image->isNew() && !$image->hasFile()) {
            $event->setData(null);
        }
    }
645642
public function onPreSubmit(FormEvent $event)
    {
        $contentLanguages = [];
        $form = $event->getForm();
        $data = $event->getData();

        if (isset($data['contentType'])) {
            try {
                $contentType = $this->contentTypeService->loadContentTypeByIdentifier($data['contentType']);
            } catch (NotFoundException $e) {
                $contentType = null;
            }

            if (null !== $contentType) {
                $contentLanguages = array_keys($contentType->getNames());
            }
        }

        $this->addLanguageFields($form, $contentLanguages);
    }
1310933
public function createEvent(
        $event,
        $entityType,
        $entityId,
        $targetEntityType=null,
        $targetEntityId=null,
        array $properties=null,
        $eventTime=null
    ) {
        if (!isset($eventTime)) {
            $eventTime = new \DateTime();
        } elseif (!($eventTime instanceof \DateTime)) {
            $eventTime = new \DateTime($eventTime);
        }
        $eventTime = $eventTime->format(\DateTime::ISO8601);

        $data = [
            'event' => $event,
            'entityType' => $entityType,
            'entityId' => $entityId,
            'eventTime' => $eventTime,
        ];

        if (isset($targetEntityType)) {
            $data['targetEntityType'] = $targetEntityType;
        }

        if (isset($targetEntityId)) {
            $data['targetEntityId'] = $targetEntityId;
        }

        if (isset($properties)) {
            $data['properties'] = $properties;
        }

        $json = $this->jsonEncode($data);

        $this->export($json);
    }
1152172
public function setEvent(EventInterface $event)
    {
        $target = $this;

        if (!($event instanceof AuthenticationEvent)) {
            $eventParams = $event->getParams();
            $eventTarget = $event->getTarget();

            if ($eventTarget) {
                $target = $eventTarget;
            }

            $event = new AuthenticationEvent();

            $event->setParams($eventParams);
        }

        $event->setIdentity(null)->setTarget($target);

        $this->event = $event;

        return $this;
    }