parses config object from extjs

@param object $config lazy configuration of extjs
@param Form_FormModel $form
@return Form_Elements_FieldsetModel
511068
public static function fromJson($config, Form_Elements_FieldsetModel $form=null)
	{
		$contextProfile = AgaviConfig::get('core.default_context');
		if(is_null($contextProfile))
		{
			$contextProfile = md5(microtime());
			AgaviConfig::set('core.default_context', $contextProfile);
		}
		$context = AgaviContext::getInstance();
		$fieldset = $context->getModel('Elements.Fieldset', 'Form', array($config, $form));
		$children = array();
		$columns = count($config->items);
		$rows = count($config->items[0]->items);
		for($i=0; $i<$rows; $i++)
		{
			for($j=0; $j<$columns; $j++)
			{
				if(isset($config->items[$j]->items[$i]))
				{
					$children[] = $config->items[$j]->items[$i];
				}
			}
		}
		$tmp = new stdClass();
		$tmp->items = $children;
		self::parseChildren($tmp, $fieldset);
		$form->addChild($fieldset);
		if(!is_null($form))
			foreach($fieldset->children as $child)
			{
				$form->addChild($child);
			}
		return $fieldset;
	}
966032
protected function parseConfig(string $config): array
    {
        $config = json_decode($config, true);
        if ($config === null) {
            throw new ConfigFileFormatException("Config files should be written in valid JSON");
        }
        return $config;
    }
98356
protected function prepareForm(Form $form)
	{
		$form->getElementPrototype()->class[] = 'form-horizontal';
		$translator = $form->getTranslator();
		foreach ($form->controls as $control) {
			/** @var BaseControl $control */
			if ($control instanceof HiddenField) {
				continue;
			} elseif ($control instanceof Button) {
				$control->controlPrototype->class[] = "btn-block btn-lg";
			} else {
				if ($control->getLabel()) {
					$control->setAttribute('placeholder', $control->caption);
					if (empty($control->controlPrototype->attrs['title'])) {
						$control->setAttribute('title', $translator ? $translator->translate($control->caption) : $control->caption);
					}
					$control->getLabelPrototype()->attrs["style"] = "display:none";
				}
			}
		}
		BootstrapHelper::ApplyBootstrapToControls($form);
	}
216185
public function form($form = null)
    {
        if (func_num_args() === 1) {
            $form = $form ?: [];
            $this->_form = $form;
            $this->set($form);
            return $this;
        }
        return $this->_form;
    }
720921
protected function buildFieldName(FormInterface $form, array &$tree = array())
    {
        $config = $form->getConfig();
        $parent = $form->getParent();
        $hasParent = null !== $parent;

        if (null !== $proprietyPath = $config->getPropertyPath()) {
            $name = (string)$proprietyPath;
        } else {
            $name = $config->getName();

            if ($name === null) {
                $name = '';
            } elseif ($name !== '' && $hasParent) {
                $name = "[$name]";
            }
        }

        array_unshift($tree, $name);

        if (!$hasParent) {
            return implode("", $tree);
        }

        return $this->buildFieldName($parent, $tree);
    }
626688
public static function parseChildren($config, Form_Elements_FieldsetModel $container)
	{
		$contextProfile = AgaviConfig::get('core.default_context');
		if(is_null($contextProfile))
		{
			$contextProfile = md5(microtime());
			AgaviConfig::set('core.default_context', $contextProfile);
		}
		$context = AgaviContext::getInstance();
		if(isset($config->items) and is_array($config->items))
		{
			foreach($config->items as $item)
			{
				if(isset($item->xtype))
				{
					switch($item->xtype)
					{
						case 'textfield':
							if(isset($item->inputType) and $item->inputType=='password')
								$model = array('Elements.PasswordField', 'Form');
							else
								$model = array('Elements.TextField', 'Form');
							break;
						case 'numberfield':
							$model = array('Elements.NumberField', 'Form');
							break;
						case 'combo':
							$model = array('Elements.ResourceField', 'Form');
							break;
						case 'datefield':
							$model = array('Elements.DateField', 'Form');
							break;
						case 'radiogroup':
							$model = array('Elements.RadioGroup', 'Form');
							break;
						case 'checkbox':
							$model = array('Elements.Checkbox', 'Form');
							break;
						case 'fieldset':
							$model = Form_Elements_FieldsetModel::fromJson($item, $container);
							break;
						case 'textarea':
							$model = array('Elements.TextArea', 'Form');
							break;
						default:
							$model = null;
					}
					if(is_array($model))
					{
						$el = $context->getModel($model[0], $model[1], array($item, $container));
						$container->addChild($el);
					}
					elseif(!is_null($model))
					{
						$container->addChild($model);
					}
				}
			}
		}
	}
384393
public function modal($config = array())
    {
        $config = new ObjectConfigJson($config);
        $config->append(array(
            'debug'    => \Kodekit::getInstance()->isDebug(),
            'selector' => '[data-k-modal]',
            'data'     => 'k-modal',
            'options_callback' => null,
            'options'  => array('type' => 'image')
        ));

        $html = '';

        if(!static::isLoaded('modal'))
        {
            $html .= $this->jquery();
            $html .= '<ktml:script src="assets://js/'.($config->debug ? 'build/' : 'min/').'jquery.magnific-popup.js" />';

            static::setLoaded('modal');
        }

        if(!static::isLoaded('modal-select2-fix'))
        {
            $html .= "<script>

                // WORKAROUND FOR ISSUE: #873

                kQuery(function($)
                {
                    $.magnificPopup.instance._onFocusIn = function(e)
                    {
                        // Do nothing if target element is select2 input
                        if( $(e.target).hasClass('select2-search__field') ) {
                            return true;
                        }
            
                        // Else call parent method
                        $.magnificPopup.proto._onFocusIn.call(this,e);
                    };
                });
            </script>";

            static::setLoaded('modal-select2-fix');
        }

        $options   = (string)$config->options;
        $signature = md5('modal-'.$config->selector.$config->options_callback.$options);

        if (!static::isLoaded($signature))
        {
            if ($config->options_callback) {
                $options = $config->options_callback.'('.$options.')';
            }

            $html .= "<script>
            kQuery(function($){
                $('$config->selector').each(function(idx, el) {
                    var el = $(el);
                    var data = el.data('$config->data');
                    var options = ".$options.";
                    if (data) {
                        $.extend(true, options, data);
                    }
                    el.magnificPopup(options);
                });
            });
            </script>";

            static::setLoaded($signature);
        }

        return $html;
    }
734991
protected function parseConfig(array $config)
    {
        $config = $this->setHost($config);
        $config = $this->setPort($config);
        $config = $this->setProtocol($config);
        $config = $this->setServiceId($config);
        $config = $this->setTNS($config);
        $config = $this->setCharset($config);

        return $config;
    }
56153
public function createJsModel(Form $form)
    {
        $this->currentElement = $form;

        $conf = $form->getConfig();
        // If field is disabled or has no any validations
        if (false === $conf->getOption('js_validation')) {
            return null;
        }

        $model                 = new JsFormElement;
        $model->id             = $this->getElementId($form);
        $model->name           = $form->getName();
        $model->type           = get_class($conf->getType()->getInnerType());
        $model->invalidMessage = $this->translateMessage(
            $conf->getOption('invalid_message'),
            $conf->getOption('invalid_message_parameters')
        );
        $model->transformers   = $this->normalizeViewTransformers(
            $form,
            $this->parseTransformers($conf->getViewTransformers())
        );
        $model->bubbling       = $conf->getOption('error_bubbling');
        $model->data           = $this->getValidationData($form);
        $model->children       = $this->processChildren($form);

        $prototype = $form->getConfig()->getAttribute('prototype');
        if ($prototype) {
            $model->prototype = $this->createJsModel($prototype);
        }

        // Return self id to add it as child to the parent model
        return $model;
    }
1014090
protected function extractFormValues(Form $form)
    {
        $values = array();

        foreach ($form->getChildrenByType('\\Zepi\\Web\\UserInterface\\Form\\Field\\FieldAbstract', true) as $field) {
            if ($field->getValue() === null) {
                continue;
            }
            
            $values[$field->getPath($form)] = $field->getValue();
        }
        
        return $values;
    }
1299127
public function inputStringPreparer($config)
    {
        $inputString = '';
        $beforeAfterCondition = ($this->before($config) > '' || $this->after($config) > '');
        $method = $this->getGeneratorMethod($config['inputType']);

        if ($beforeAfterCondition) {
            $inputString .= '<div class="'.config('form-maker.form.before_after_input_wrapper', 'input-group').'">';
        }

        $inputString .= $this->before($config);
        $inputString .= $this->inputStringGenerator($config);
        $inputString .= $this->after($config);

        if ($beforeAfterCondition) {
            $inputString .= '</div>';
        }

        if (config('form-maker.form.orientation') == 'horizontal' && !in_array($method, $this->selectedMethods)) {
            return '<div class="'.config('form-maker.form.input-column', '').'">'.$inputString.'</div>';
        }

        return $inputString;
    }
1126943
protected function buildForm(array $config)
    {
        return isset($config['form'])
            ? $config['form']
            : ClassUtils::getClass($this->filterFormRegistry[$this->buildType($config)]);
    }
958727
protected function getElementId(Form $form)
    {
        /** @var Form $parent */
        $parent = $form->getParent();
        if (null !== $parent) {
            return $this->getElementId($parent) . '_' . $form->getName();
        } else {
            return $form->getName();
        }
    }
778642
public function render(Form $form, $mode = null): string
	{
		$usedPrimary = false;

		$form->getElementPrototype()->setNovalidate(true);

		foreach ($form->getControls() as $control) {

			if ($control instanceof Controls\BaseControl
				&& !($control instanceof Controls\Checkbox)
				&& !($control instanceof Controls\CheckboxList)
				&& !($control instanceof Controls\RadioList)) {
				$control->getLabelPrototype()->addClass('col-form-label col col-sm-3');
			}

			switch (true) {
				case $control instanceof Controls\Button:
					/** @var string|null $class */
					$class = $control->getControlPrototype()->getAttribute('class');
					if ($class === null || mb_strpos($class, 'btn') === false) {
						$control->getControlPrototype()->addClass($usedPrimary === false ? 'btn btn-primary' : 'btn btn-secondary');
						$usedPrimary = true;
					}
					break;

				case $control instanceof Controls\TextBase:
				case $control instanceof Controls\SelectBox:
				case $control instanceof Controls\MultiSelectBox:
					$control->getControlPrototype()->addClass('form-control');
					break;

				case $control instanceof Controls\Checkbox:
				case $control instanceof Controls\CheckboxList:
				case $control instanceof Controls\RadioList:
					$control->getSeparatorPrototype()->setName('div')->addClass('form-check');
					$control->getControlPrototype()->addClass('form-check-input');
					$control->getLabelPrototype()->addClass('form-check-label');
					break;
			}
		}

		return parent::render($form, $mode);
	}
817736
public function renderForm( $config = [], $html = [] ) {

		$formView = CodeGenUtil::isAbsolutePath( $this->formView, true ) ? $this->formView : "$this->template/$this->formView";

		return $this->render( $formView, [
			'widget' => $this,
			'infoHtml' => $html[ 'infoHtml' ],
			'fieldsHtml' => $html[ 'fieldsHtml' ]
		] );
	}
594028
public function format(?string $format = null, array $config = []): self
    {
        if (! \is_null($format) && ! empty($format)) {
            $this->setFormat($format);

            if (! empty($config)) {
                $this->when($format, $config);
            }
        }

        return $this;
    }
67522
public static function config_set_edit_form_data(moodleform $editform, array $config) {
        $data = array();
        $data['server'] = $config['server'];
        $data['prefix'] = !empty($config['prefix']) ? $config['prefix'] : '';
        $data['password'] = !empty($config['password']) ? $config['password'] : '';
        if (!empty($config['serializer'])) {
            $data['serializer'] = $config['serializer'];
        }
        $editform->set_data($data);
    }