/**
  * @param ViewEvent $event
  */
 public static function handleViewEvent(ViewEvent $event)
 {
     $widget = $event->getWidget();
     $inputGroup = $event->getContainer()->getWrapper();
     $template = static::getIconSetTemplateWhenEnabled($inputGroup, $widget);
     self::addIcon($template, $widget, $inputGroup);
 }
 /**
  * Set bootstrap column layout.
  *
  * @param ViewEvent $event The view event.
  *
  * @return void
  */
 public function setColumnLayout(ViewEvent $event)
 {
     $form = $event->getFormModel();
     $widget = $event->getWidget();
     $config = $this->getConfig($form);
     if ($form && $widget->tableless || !$form && !$config->get('form.default-horizontal')) {
         return;
     }
     $container = $event->getContainer();
     $label = $event->getLabel();
     $container->setRenderContainer(true);
     $container->addClass($config->get('form.horizontal.control'));
     if (!$widget->label || !$this->getWidgetConfigValue($config, $widget->type, 'label', true)) {
         $container->addClass($config->get('form.horizontal.offset'));
     } else {
         $label->addClass($config->get('form.horizontal.label'));
     }
     if ($container->hasChild('repeatLabel')) {
         /** @var Label $label */
         $label = $container->getChild('repeatLabel');
         $label->addClass('control-label');
         if ($this->getWidgetConfigValue($config, $widget->type, 'label', true)) {
             $label->addClass($config->get('form.horizontal.label'));
         }
     }
 }
 /**
  * Set all css classes to the widget attributes.
  *
  * @param ViewEvent $event Event listened to.
  *
  * @return void
  */
 public function setCssClasses(ViewEvent $event)
 {
     $view = $event->getView();
     $widget = $view->getWidget();
     $attributes = $view->getAttributes();
     $attributes->addClass('widget')->addClass('widget-' . $widget->type);
     if ($widget->mandatory) {
         $attributes->addClass('mandatory');
     }
 }
Beispiel #4
0
 /**
  * Create modal footer.
  *
  * @param ViewEvent $event Form helper view event.
  *
  * @return void
  */
 public function createModalFooter(ViewEvent $event)
 {
     $widget = $event->getWidget();
     $element = $event->getContainer()->getElement();
     if ($this->isPartOfModalFooter($widget)) {
         $buttons = (array) Bootstrap::getConfigVar('runtime.modal-footer');
         // create copy for footer
         /** @var Element $element */
         $copy = clone $element;
         $copy->setAttribute('onclick', sprintf('jQuery(\'#ctrl_%s\').click();', $widget->id));
         $copy->setId('md_' . $element->getId());
         $copy->addClass('btn');
         $event->getView()->getAttributes()->addClass('sr-only');
         $buttons[] = $copy;
         Bootstrap::setConfigVar('runtime.modal-footer', $buttons);
     }
 }
 /**
  * Generate the password confirmation field.
  *
  * @param ViewEvent $event Event listened to.
  *
  * @return void
  */
 public function generatePasswordConfirmation(ViewEvent $event)
 {
     $view = $event->getView();
     $widget = $view->getWidget();
     if (!$widget instanceof \FormPassword) {
         return;
     }
     $container = $view->getContainer();
     $element = $container->getElement();
     $label = $view->getLabel();
     $widgetId = $element instanceof Element ? $element->getId() : 'ctrl_' . $widget->id;
     $repeatId = $widgetId . '_confirm';
     $repeatLabel = new Label();
     $repeatLabel->setAttribute('class', $label->getAttribute('class'))->addChild($this->createConfirmationLabel($widget))->setAttribute('for', $repeatId);
     if ($widget->mandatory) {
         $mandatory = $this->createMandatoryLabel();
         $repeatLabel->addChild($mandatory);
     }
     /** @var Element $repeat */
     $repeat = clone $element;
     $repeat->setId($repeatId)->setAttribute('name', $repeat->getAttribute('name') . '_confirm')->setAttribute('value', '');
     $container->addChild('repeat', $repeat);
     $container->addChild('repeatLabel', $repeatLabel);
 }
 /**
  * Preset the label.
  *
  * @param ViewEvent $event Event listened to.
  *
  * @return void
  */
 public function presetLabel(ViewEvent $event)
 {
     $view = $event->getView();
     $label = $view->getLabel();
     $widget = $view->getWidget();
     $element = $view->getContainer()->getElement();
     $label->setAttribute('for', 'ctrl_' . $widget->id);
     if ($widget->label) {
         $label->addChild($widget->label);
     }
     if ($widget->mandatory) {
         $mandatory = $this->generateMandatoryLabel();
         $label->addChild($mandatory);
     }
     if ($element instanceof HasLabel && $widget->label) {
         $element->setLabel(new StaticHtml($widget->label));
     }
     if (in_array($widget->type, static::$noLabel)) {
         $label->hide();
     }
 }
 /**
  * Handle the event to style the widgets.
  *
  * @param ViewEvent $event The subscribed events.
  *
  * @return void
  */
 public function handle(ViewEvent $event)
 {
     $container = $event->getContainer();
     $element = $container->getElement();
     if (!$element instanceof Element) {
         return;
     }
     $config = static::getConfig($event->getFormModel());
     $widget = $event->getWidget();
     // Create styled select field.
     if ($config->get('form.styled-select.enabled') && static::getWidgetConfigValue($config, $widget->type, 'styled-select')) {
         $this->registerStyledSelectAssets($config);
         $this->setStyledSelectAttributes($config, $element, $widget);
     }
     // Create styled upload field.
     if ($event->getWidget()->type == 'upload' && $config->get('form.styled-upload.enabled')) {
         $this->generateUpload($config, $container, $widget);
     }
 }
 /**
  * Generate the form wiedget view.
  *
  * @param ViewEvent $event The form widget view event.
  *
  * @return void
  */
 public function handle(ViewEvent $event)
 {
     $container = $event->getContainer();
     $element = $event->getContainer()->getElement();
     $widget = $event->getWidget();
     $label = $event->getLabel();
     $config = $this->getConfig($event->getFormModel());
     $this->modifyLabel($config, $label, $widget);
     $this->modifyElement($config, $element, $widget, $container);
     $this->modifyErrors($event, $widget, $container);
     $this->addInputGroup($config, $widget, $container, $element);
 }