Пример #1
0
 /**
  * Select the view layout if bootstrap is enabled.
  *
  * @param ViewEvent $event The event.
  *
  * @return void
  */
 public function setViewLayout(ViewEvent $event)
 {
     if (Bootstrap::isEnabled()) {
         $view = $event->getView();
         $view->setLayout('bootstrap');
         $view->getAttributes()->addClass('form-group');
     }
 }
 /**
  * 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');
     }
 }
Пример #3
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('$(\'#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();
     }
 }
Пример #6
0
 /**
  * Move errors into the container and set css classes.
  *
  * @param ViewEvent $event     The view event.
  * @param \Widget   $widget    The widget.
  * @param Container $container The container.
  *
  * @return void
  */
 private function modifyErrors(ViewEvent $event, \Widget $widget, Container $container)
 {
     $errors = $event->getErrors();
     $errors->addClass('help-block');
     $container->addChild('errors', $errors);
     if ($widget->hasErrors()) {
         $view = $event->getView();
         $view->getAttributes()->addClass('has-feedback')->addClass('has-error');
     }
 }