Пример #1
0
 /**
  * This method will be called when the component (or component's parent)
  * becomes attached to a monitored object. Do not call this method yourself.
  * @param IComponent $form
  * @return void
  */
 protected function attached($form)
 {
     parent::attached($form);
     if ($form instanceof Form) {
         $this->checkbox->setParent($form, $form->getName());
     }
     if ($form instanceof IPresenter) {
         if (isset($form->imageStorage) && $form->imageStorage instanceof IImageStorage) {
             $this->storage = $form->imageStorage;
         } else {
             $this->storage = $form->context->getByType(IImageStorage::class);
         }
         $this->checkbox->setPrepend($this->getHtmlName());
         $this->checkbox->setStorage($this->storage);
         $this->checkbox->setImageName($this->defaultValue);
         if ($this->required && !$this->checkbox->isOk()) {
             $this->addRule(Form::FILLED, is_string($this->required) ? $this->required : NULL);
         }
     }
 }
Пример #2
0
 /**
  * This method will be called when the component (or component's parent)
  * becomes attached to a monitored object. Do not call this method yourself.
  * @param IComponent $form
  * @return void
  */
 protected function attached($form)
 {
     parent::attached($form);
     if ($form instanceof IPresenter) {
         if (isset($form->imageStorage) && $form->imageStorage instanceof IImageStorage) {
             $this->storage = $form->imageStorage;
         } else {
             $this->storage = $form->context->getByType(IImageStorage::class);
         }
         $form = $this->getForm();
         $htmlName = str_replace('[]', '', $this->getHtmlName());
         foreach ($this->defaultValues as $i => $defaultValue) {
             $checkbox = new Checkbox();
             $checkbox->setParent($form, $i);
             $checkbox->setPrepend($htmlName . $i);
             $checkbox->setStorage($this->storage);
             $checkbox->setImageName($defaultValue);
             $this->checkboxes[] = $checkbox;
         }
         if ($this->required && !$this->getCheckboxesFine()) {
             $this->addRule(Form::FILLED, $this->getRequiredMessage());
         }
     }
 }