示例#1
0
 public function render()
 {
     $value = $this->getValueFromForm();
     if (!empty($value)) {
         $this->attributes['checked'] = 'checked';
     } else {
         $value = 1;
     }
     return $this->addon ? HtmlBuilder::checkboxAddon($this->name, $this->label, $value, $this->attributes, $this->addonValue) : HtmlBuilder::checkbox($this->name, $this->label, $value, $this->getOptions($this->attributes));
 }
示例#2
0
 /**
  * @return string
  */
 public function render()
 {
     $model = $this->form->instance;
     if (empty($model)) {
         return false;
     }
     $fields = array();
     foreach ($this->_getLanguageData() as $languageId => $data) {
         $language = Models\Language::find($languageId);
         foreach ($data as $fieldCode => $fieldData) {
             $name = $this->fields[$fieldCode]['name'];
             $fieldTitle = $this->useTabs ? $name : $name . ' [' . $language->name . ']';
             $validationRules = isset($this->fields[$fieldCode]['validation']) ? explode('|', $this->fields[$fieldCode]['validation']) : [];
             switch ($this->fields[$fieldCode]['type']) {
                 case 'ckeditor':
                     $options = ['id' => lcfirst($fieldCode) . '[' . $languageId . ']', 'data-editor' => Textarea::EDITOR_WYSIHTML];
                     $fields[$languageId][] = HtmlBuilder::textarea(lcfirst($fieldCode) . '[' . $languageId . ']', $fieldTitle, $fieldData, $this->getOptions($options, $validationRules));
                     break;
                 case 'textarea':
                     $options = ['id' => lcfirst($fieldCode) . '[' . $languageId . ']'];
                     $fields[$languageId][] = HtmlBuilder::textarea(lcfirst($fieldCode) . '[' . $languageId . ']', $fieldTitle, $fieldData, $this->getOptions($options, $validationRules));
                     break;
                 case 'checkbox':
                     $hotelLanguage = $model->getRepository()->getHotelLanguage($languageId);
                     $options = array('id' => lcfirst($fieldCode) . '[' . $languageId . ']');
                     $oldCheckbox = Admin::$instance->formBuilder->getSessionStore()->getOldInput(lcfirst($fieldCode));
                     if (is_null($oldCheckbox)) {
                         if ($hotelLanguage && $hotelLanguage->active) {
                             $options = array_merge($options, array('checked' => 'checked'));
                         }
                     } else {
                         if ($oldCheckbox[$languageId] == 1) {
                             $options = array_merge($options, array('checked' => 'checked'));
                         }
                         $allOldInputs = Admin::$instance->formBuilder->getSessionStore()->get('_old_input');
                         $fieldName = lcfirst($fieldCode);
                         if (isset($allOldInputs[$fieldName])) {
                             if (isset($allOldInputs[$fieldName][$languageId])) {
                                 unset($allOldInputs[$fieldName][$languageId]);
                             }
                         }
                         Admin::$instance->formBuilder->getSessionStore()->set('_old_input', $allOldInputs);
                     }
                     $fields[$languageId][] = HtmlBuilder::checkbox(lcfirst($fieldCode) . '[' . $languageId . ']', $fieldTitle, $fieldData, $this->getOptions($options, $validationRules));
                     break;
                 default:
                     $options = ['id' => lcfirst($fieldCode) . '[' . $language->name . ']'];
                     $fields[$languageId][] = HtmlBuilder::text(lcfirst($fieldCode) . '[' . $languageId . ']', $fieldTitle, $fieldData, $this->getOptions($options, $validationRules));
                     break;
             }
         }
     }
     return view('admin/form/languages_fields')->with('code', $this->modelMethod)->with('withTabs', $this->useTabs)->with('languages', $this->_getAvailableLanguages())->with('fields', $fields)->with('blockId', uniqid())->with('title', $this->label);
 }