Exemplo n.º 1
0
 /**
  * Build for for editing component parameters.
  * The form creation is based on XML widget's data received per POST request.
  *
  * @throws SystemException 'ERR_INSUFFICIENT_DATA'
  * @throws SystemException 'ERR_BAD_XML_DESCR'
  */
 protected function buildParamsForm()
 {
     if (!isset($_POST['modalBoxData'])) {
         throw new SystemException('ERR_INSUFFICIENT_DATA');
     }
     if (!($widgetXML = simplexml_load_string($_POST['modalBoxData']))) {
         throw new SystemException('ERR_BAD_XML_DESCR');
     }
     list($componentName) = $this->getStateParams();
     $component = ComponentManager::findBlockByName($widgetXML, $componentName);
     $dd = new DataDescription();
     $d = new Data();
     $this->setType(self::COMPONENT_TYPE_FORM_ALTER);
     $this->setDataDescription($dd);
     $this->setData($d);
     $this->setBuilder(new Builder());
     $this->js = $this->buildJS();
     foreach ($component->params->children() as $param) {
         $paramName = (string) $param['name'];
         $paramType = isset($param['type']) ? (string) $param['type'] : FieldDescription::FIELD_TYPE_STRING;
         $fd = new FieldDescription($paramName);
         if (isset($param['nullable'])) {
             $fd->setProperty('nullable', true);
         }
         $fd->setType($paramType)->setProperty('tabName', E()->Utils->translate('TAB_PARAMS'));
         if ($paramType == FieldDescription::FIELD_TYPE_SELECT && isset($param['values'])) {
             $availableValues = array();
             foreach (explode('|', (string) $param['values']) as $value) {
                 array_push($availableValues, array('key' => $value, 'value' => $value));
             }
             $fd->loadAvailableValues($availableValues, 'key', 'value');
         }
         $dd->addFieldDescription($fd);
         $f = new Field($paramName);
         $f->setRowData(0, $param);
         $d->addField($f);
     }
     $this->addToolbar($this->loadToolbar());
 }