Commit 92ef333a by semenov

Merge branch 'master' into 'release'

Master

See merge request !6
parents 1ad2ec2f 2cd58c22
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 16.03.2015
*/
namespace yii\web;
use skeeks\modules\cms\form\components\FormRegisteredElements;
use skeeks\modules\cms\form\components\FormRegisteredWidgets;
/**
*
* @property FormRegisteredElements $formRegisteredElements
*
* Class Application
* @package yii\web
*/
class Application
{}
\ No newline at end of file
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 16.03.2015
*/
namespace skeeks\modules\cms\form\components;
use skeeks\cms\base\db\ActiveRecord;
use skeeks\cms\components\CollectionComponents;
use skeeks\cms\components\RegisteredWidgets;
use skeeks\cms\models\StorageFile;
use skeeks\cms\models\WidgetDescriptor;
use skeeks\modules\cms\form\elements\Base;
use Yii;
use yii\base\Component;
use yii\helpers\ArrayHelper;
use yii\web\UploadedFile;
/**
* Class FormRegisteredElements
* @package skeeks\modules\cms\form\components
*/
class FormRegisteredElements extends RegisteredWidgets
{
public function baseElements()
{
return [
'skeeks\modules\cms\form\elements\textarea\Textarea' =>
[
'name' => 'Текстовое поле (textarea)',
],
'skeeks\modules\cms\form\elements\textInput\TextInput' =>
[
'name' => 'Текстовый input (TextInput)',
],
'skeeks\modules\cms\form\elements\button\Button' =>
[
'name' => 'Кнопка отправки формы',
'description' => '',
],
];
}
public function init()
{
parent::init();
$this->components = ArrayHelper::merge($this->baseElements(), (array) $this->components);
}
}
\ No newline at end of file
......@@ -9,6 +9,35 @@
* @since 1.0.0
*/
return [
'components' =>
[
'formRegisteredElements' =>
[
'class' => 'skeeks\modules\cms\form\components\FormRegisteredElements',
'components' =>
[
/*'skeeks\modules\cms\form\elements\textarea\Textarea' =>
[
'name' => 'Текстовое поле (textarea)',
'description' => 'Виджет выводит нужные одразделы',
],*/
]
],
"registeredWidgets" =>
[
'components' =>
[
'skeeks\modules\cms\form\widgets\form\FormWidget' =>
[
'name' => 'Конструктор форм',
'description' => 'Виджет показа сконструированной формы',
],
]
],
],
'modules' =>
[
'form' => [
......
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 15.03.2015
*/
namespace skeeks\modules\cms\form\controllers;
use skeeks\cms\base\Controller;
use skeeks\modules\cms\form\models\Form;
use yii\filters\VerbFilter;
use yii\helpers\ArrayHelper;
use yii\web\Response;
use yii\widgets\ActiveForm;
/**
* Class BackendController
* @package skeeks\modules\cms\form\controllers
*/
class BackendController extends Controller
{
/**
* @return array
*/
public function behaviors()
{
return ArrayHelper::merge(parent::behaviors(), [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'validate' => ['post'],
'submit' => ['post'],
],
],
]);
}
/**
* Процесс отправки формы
* @return array
*/
public function actionSubmit()
{
if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax)
{
\Yii::$app->response->format = Response::FORMAT_JSON;
$response = [
'success' => false,
'message' => 'Произошла ошибка',
];
if ($formId = \Yii::$app->request->post(Form::FROM_PARAM_ID_NAME))
{
/**
* @var $modelForm Form
*/
$modelForm = Form::find()->where(['id' => $formId])->one();
$model = $modelForm->createValidateModel();
if ($model->load(\Yii::$app->request->post()) && $model->validate())
{
$response['success'] = true;
$response['message'] = 'Успешно отправлена';
}
return $response;
}
}
}
/**
* Валидация данных с формы
* @return array
*/
public function actionValidate()
{
if (\Yii::$app->request->isAjax && !\Yii::$app->request->isPjax)
{
if ($formId = \Yii::$app->request->post(Form::FROM_PARAM_ID_NAME))
{
/**
* @var $modelForm Form
*/
$modelForm = Form::find()->where(['id' => $formId])->one();
$model = $modelForm->createValidateModel();
$model->load(\Yii::$app->request->post());
\Yii::$app->response->format = Response::FORMAT_JSON;
return ActiveForm::validate($model);
}
}
}
}
\ No newline at end of file
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 16.03.2015
*/
namespace skeeks\modules\cms\form\elements;
use skeeks\cms\base\Widget;
class Base extends Widget
{
public $elementCode = '';
public $value;
public $attributeClass;
public function rules()
{
return ArrayHelper::merge(parent::rules(), [
[['attributeClass'], 'string'],
[['value'], 'safe'],
]);
}
public function attributeLabels()
{
return ArrayHelper::merge(parent::attributeLabels(), [
'attributeClass' => 'Класс',
'value' => 'Значение',
]);
}
}
\ No newline at end of file
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 16.03.2015
*/
namespace skeeks\modules\cms\form\elements\button;
use skeeks\cms\base\InputWidget;
use skeeks\cms\widgets\formInputs\storageFiles\Widget;
use skeeks\modules\cms\form\elements\Base;
use yii\helpers\Html;
class Button extends InputWidget
{
public function run()
{
$submit = Html::submitButton("Отправить", ['class' => 'btn btn-primary']);
return Html::tag('div',
$submit,
['class' => 'form-group']
);
}
}
\ No newline at end of file
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 16.03.2015
*/
namespace skeeks\modules\cms\form\elements\TextInput;
use skeeks\modules\cms\form\elements\Base;
class TextInput extends Base
{
public $elementCode = 'textInput';
}
\ No newline at end of file
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 16.03.2015
*/
namespace skeeks\modules\cms\form\elements\textarea;
use skeeks\modules\cms\form\elements\Base;
class Textarea extends Base
{
public $elementCode = 'textarea';
}
\ No newline at end of file
......@@ -35,7 +35,9 @@ class m150307_162735_create_form_field_table extends Migration
'label' => Schema::TYPE_STRING . '(255) NULL',
'hint' => Schema::TYPE_TEXT . ' NULL',
'widget' => Schema::TYPE_TEXT . ' NULL',
'element' => Schema::TYPE_STRING . '(255) NULL',
'element_config' => Schema::TYPE_TEXT . ' NULL',
'rules' => Schema::TYPE_TEXT . ' NULL',
'priority' => Schema::TYPE_INTEGER . ' NOT NULL DEFAULT 0',
......@@ -52,6 +54,7 @@ class m150307_162735_create_form_field_table extends Migration
$this->execute("ALTER TABLE {{%form_field}} ADD INDEX(updated_at);");
$this->execute("ALTER TABLE {{%form_field}} ADD INDEX(label);");
$this->execute("ALTER TABLE {{%form_field}} ADD INDEX(element);");
$this->execute("ALTER TABLE {{%form_field}} ADD INDEX(priority);");
$this->execute("ALTER TABLE {{%form_field}} ADD UNIQUE(attribute,form_id);");
......
......@@ -12,6 +12,9 @@ use skeeks\cms\models\behaviors\HasDescriptionsBehavior;
use skeeks\cms\models\behaviors\HasStatus;
use skeeks\cms\models\behaviors\Implode;
use skeeks\cms\models\Core;
use yii\base\Exception;
use yii\base\UserException;
use yii\web\ErrorHandler;
/**
* Class Form
......@@ -19,6 +22,8 @@ use skeeks\cms\models\Core;
*/
class Form extends Core
{
const FROM_PARAM_ID_NAME = 'sx-auto-form';
/**
* @inheritdoc
*/
......@@ -121,5 +126,57 @@ class Form extends Core
}
/**
* @return FormValidateModel
*/
public function createValidateModel()
{
return new FormValidateModel([
'modelForm' => $this
]);
}
/**
* @var FormField[]
*/
protected $_fields = null;
/**
* @return FormField[]
*/
public function fields()
{
if ($this->_fields === null)
{
$this->_fields = $this->getFormFields()->orderBy('priority DESC')->all();
}
return $this->_fields;
}
public function render()
{
/**
* @var $moduleForm \skeeks\modules\cms\form\Module
*/
$moduleForm = \Yii::$app->getModule('form');
try
{
return $moduleForm->renderFile('blank-form.php', [
'module' => $moduleForm,
'modelForm' => $this,
'fields' => $this->fields(),
'model' => $this->createValidateModel()
]);
} catch (\Exception $e)
{
ob_end_clean();
ErrorHandler::convertExceptionToError($e);
return 'Ошибка рендеринга формы: ' . $e->getMessage();
}
}
}
\ No newline at end of file
......@@ -12,6 +12,11 @@ use skeeks\cms\models\behaviors\HasDescriptionsBehavior;
use skeeks\cms\models\behaviors\HasStatus;
use skeeks\cms\models\behaviors\Implode;
use skeeks\cms\models\Core;
use skeeks\modules\cms\form\elements\Base;
use yii\base\Model;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveField;
use yii\widgets\ActiveForm;
/**
* Class FormEmail
......@@ -32,7 +37,25 @@ class FormField extends Core
*/
public function behaviors()
{
return array_merge(parent::behaviors(), []);
return ArrayHelper::merge(parent::behaviors(), [
Implode::className() =>
[
'class' => Implode::className(),
'fields' => ['rules']
]
]);
}
/**
* @return array
*/
static public function availableRules()
{
return [
'required' => 'Обязательно к заполнению',
'email' => 'Проверка на email',
'integer' => 'Целое число'
];
}
/**
......@@ -43,11 +66,13 @@ class FormField extends Core
return array_merge(parent::rules(), [
[['created_by', 'updated_by', 'created_at', 'updated_at', 'form_id'], 'integer'],
[['hint'], 'string'],
[['widget', 'rules'], 'safe'],
[[ 'form_id'], 'required'],
[['element_config'], 'safe'],
[['priority'], 'integer'],
[['rules'], 'safe'],
[[ 'form_id', 'element'], 'required'],
['attribute', 'default', 'value' => function(FormField $model, $attribute)
{
return "sx-field-" . md5(rand(1, 10) . time());
return "sx_field_" . md5(rand(1, 10) . time());
}],
[['label', 'attribute'], 'string', 'max' => 255],
[['attribute', 'form_id'], 'unique', 'targetAttribute' => ['attribute', 'form_id'], 'message' => 'Этот элемент уже привязан к форме']
......@@ -96,4 +121,85 @@ class FormField extends Core
{
return $this->findForm()->one();
}
/**
* @return \skeeks\cms\models\WidgetDescriptor
*/
public function elenentDescriptor()
{
return \Yii::$app->formRegisteredElements->getComponent($this->element);
}
/**
* @return array
*/
public function rulesForActiveForm()
{
$result = [];
if ((array) $this->rules)
{
foreach ((array) $this->rules as $ruleCode)
{
$result[] = [[$this->attribute], $ruleCode];
}
} else
{
$result[] = [[$this->attribute], 'safe'];
}
return $result;
}
/**
* @param ActiveForm $activeForm
* @param Model $model
* @return mixed
*/
public function renderActiveForm(ActiveForm $activeForm, Model $model)
{
if ($element = $this->elenentDescriptor())
{
$elementConfig = (array) $this->element_config;
/**
* @var $field ActiveField
*/
$field = $activeForm
->field($model, $this->attribute);
if (!$field)
{
return '';
}
//Элемент или виджет
if (is_subclass_of($this->element, Base::className()))
{
$element = new $this->element;
$field->{$element->elementCode}($elementConfig);
} else
{
$field->widget($this->element, $elementConfig);
}
if ($this->hint)
{
$field->hint((string) $this->hint);
}
if ($this->label)
{
$field->label($this->label);
} else
{
$field->label(false);
}
return $field;
}
return '';
}
}
\ No newline at end of file
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 07.03.2015
*/
namespace skeeks\modules\cms\form\models;
use skeeks\cms\base\db\ActiveRecord;
use skeeks\cms\models\behaviors\HasDescriptionsBehavior;
use skeeks\cms\models\behaviors\HasStatus;
use skeeks\cms\models\behaviors\Implode;
use skeeks\cms\models\Core;
use yii\base\Exception;
use yii\base\InvalidConfigException;
use yii\base\Model;
use yii\helpers\ArrayHelper;
use yii\helpers\BaseHtml;
/**
* Class FormValidateModel
* @package skeeks\modules\cms\form\models
*/
class FormValidateModel extends Model
{
/**
* @var Form
*/
public $modelForm = null;
public function init()
{
parent::init();
if (!$this->modelForm instanceof Form)
{
throw new InvalidConfigException;
}
if ($fields = $this->modelForm->fields())
{
foreach ($fields as $field)
{
$this->_attributes[$field->attribute] = '';
}
}
}
/**
* @var array attribute values indexed by attribute names
*/
private $_attributes = [];
private $_related = [];
public function rules()
{
$result = parent::rules();
foreach ($this->modelForm->fields() as $field)
{
$result = ArrayHelper::merge($result, $field->rulesForActiveForm());
}
return $result;
}
/**
* PHP getter magic method.
* This method is overridden so that attributes and related objects can be accessed like properties.
*
* @param string $name property name
* @throws \yii\base\InvalidParamException if relation name is wrong
* @return mixed property value
* @see getAttribute()
*/
public function __get($name)
{
if (isset($this->_attributes[$name]) || array_key_exists($name, $this->_attributes)) {
return $this->_attributes[$name];
} elseif ($this->hasAttribute($name)) {
return null;
} else {
if (isset($this->_related[$name]) || array_key_exists($name, $this->_related)) {
return $this->_related[$name];
}
$value = parent::__get($name);
if ($value instanceof ActiveQueryInterface) {
return $this->_related[$name] = $value->findFor($name, $this);
} else {
return $value;
}
}
}
/**
* PHP setter magic method.
* This method is overridden so that AR attributes can be accessed like properties.
* @param string $name property name
* @param mixed $value property value
*/
public function __set($name, $value)
{
if ($this->hasAttribute($name)) {
$this->_attributes[$name] = $value;
} else {
parent::__set($name, $value);
}
}
/**
* Checks if a property value is null.
* This method overrides the parent implementation by checking if the named attribute is null or not.
* @param string $name the property name or the event name
* @return boolean whether the property value is null
*/
public function __isset($name)
{
try {
return $this->__get($name) !== null;
} catch (\Exception $e) {
return false;
}
}
/**
* Sets a component property to be null.
* This method overrides the parent implementation by clearing
* the specified attribute value.
* @param string $name the property name or the event name
*/
public function __unset($name)
{
if ($this->hasAttribute($name)) {
unset($this->_attributes[$name]);
} elseif (array_key_exists($name, $this->_related)) {
unset($this->_related[$name]);
} elseif ($this->getRelation($name, false) === null) {
parent::__unset($name);
}
}
/**
* Returns a value indicating whether the model has an attribute with the specified name.
* @param string $name the name of the attribute
* @return boolean whether the model has an attribute with the specified name.
*/
public function hasAttribute($name)
{
return isset($this->_attributes[$name]) || in_array($name, $this->attributes());
}
/**
* Returns the named attribute value.
* If this record is the result of a query and the attribute is not loaded,
* null will be returned.
* @param string $name the attribute name
* @return mixed the attribute value. Null if the attribute is not set or does not exist.
* @see hasAttribute()
*/
public function getAttribute($name)
{
return isset($this->_attributes[$name]) ? $this->_attributes[$name] : null;
}
/**
* Sets the named attribute value.
* @param string $name the attribute name
* @param mixed $value the attribute value.
* @throws InvalidParamException if the named attribute does not exist.
* @see hasAttribute()
*/
public function setAttribute($name, $value)
{
if ($this->hasAttribute($name)) {
$this->_attributes[$name] = $value;
} else {
throw new InvalidParamException(get_class($this) . ' has no attribute named "' . $name . '".');
}
}
/*public function scenarios()
{
$scenarios = parent::scenarios();
$scenarios['create'] = $scenarios[self::SCENARIO_DEFAULT];
$scenarios['update'] = $scenarios[self::SCENARIO_DEFAULT];
return $scenarios;
}*/
/**
* @inheritdoc
*/
public function attributeLabels()
{
$result = [];
foreach ($this->modelForm->fields() as $field)
{
$result[$field->attribute] = $field->label;
}
return $result;
}
}
\ No newline at end of file
<?php
/**
* LoginForm
*
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010-2014 SkeekS (Sx)
* @date 28.10.2014
* @since 1.0.0
*/
namespace skeeks\modules\cms\form\models\forms;
use Yii;
use yii\base\Model;
/**
* Login form
*/
class EmailForm extends Model
{
public $value;
/**
* @inheritdoc
*/
public function rules()
{
return [
// username and password are both required
[['value'], 'required'],
// rememberMe must be a boolean value
['value', 'email'],
];
}
}
......@@ -16,7 +16,8 @@ use common\models\User;
<? if ($form_id = \Yii::$app->request->get('form_id')) : ?>
<?= $form->field($model, 'form_id')->hiddenInput(['value' => $form_id])->label(false); ?>
<? else: ?>
<?= $form->field($model, 'form_id')->label('Форма')->widget(
<?= $form->field($model, 'form_id')->hiddenInput(['value' => $form_id])->label(false); ?>
<?/*= $form->field($model, 'form_id')->label('Форма')->widget(
\skeeks\widget\chosen\Chosen::className(), [
'items' => \yii\helpers\ArrayHelper::map(
\skeeks\modules\cms\form\models\Form::find()->all(),
......@@ -24,12 +25,36 @@ use common\models\User;
"name"
),
]);
*/?>
<? endif; ?>
<?/* if ($model->isNewRecord) : */?>
<?= $form->field($model, 'element')->label('Элемент формы')->widget(
\skeeks\widget\chosen\Chosen::className(), [
'items' => \yii\helpers\ArrayHelper::map(
\Yii::$app->formRegisteredElements->getComponents(),
"id",
"name"
),
]);
?>
<?/* endif ; */?>
<? if (!$model->isNewRecord) : ?>
<?= $form->field($model, 'attribute')->textInput(); ?>
<?= $form->field($model, 'label')->textInput(); ?>
<?= $form->field($model, 'hint')->textInput(); ?>
<?= $form->field($model, 'rules')->widget(
\skeeks\widget\chosen\Chosen::className(),
[
'items' => \skeeks\modules\cms\form\models\FormField::availableRules(),
'multiple' => true
]
); ?>
<? endif; ?>
<?= $form->field($model, 'attribute')->textInput(); ?>
<?= $form->field($model, 'label')->textInput(); ?>
<?= $form->field($model, 'hint')->textInput(); ?>
<?= $form->buttonsCreateOrUpdate($model); ?>
<?php ActiveForm::end(); ?>
......@@ -13,7 +13,7 @@ use common\models\User;
<?php $form = ActiveForm::begin(); ?>
<?php ?>
<?= $form->fieldSet('Общая ниформация')?>
<?= $form->fieldSet('Общая информация')?>
<?= $form->field($model, 'name')->textInput(); ?>
<?= $form->fieldSetEnd(); ?>
......@@ -62,8 +62,18 @@ use common\models\User;
'relation' => [
'form_id' => 'id'
],
'sort' => [
'defaultOrder' =>
[
'priority' => SORT_DESC
]
],
'controllerRoute' => 'form/admin-form-field',
'gridViewOptions' => [
'sortable' => true,
'columns' => [
//['class' => 'yii\grid\SerialColumn'],
'attribute',
......@@ -72,7 +82,20 @@ use common\models\User;
],
],
]); ?>
<?= $form->fieldSetEnd(); ?>
<?= $form->buttonsCreateOrUpdate($model); ?>
<?php ActiveForm::end(); ?>
<div class="row">
<div class="col-md-12">
<div class="" style="border: 1px solid rgba(32, 168, 216, 0.23); padding: 10px; margin-top: 10px;">
<h2>Вот так будет выглядеть форма:</h2>
<hr />
<?= $model->render(); ?>
</div>
</div>
</div>
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 17.03.2015
*
* @var $formField \skeeks\modules\cms\form\models\FormField
* @var $model \skeeks\modules\cms\form\models\FormValidateModel
*/
use skeeks\modules\cms\form\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin([
'modelForm' => $model->modelForm,
]);
?>
<? if ($fields) : ?>
<? foreach ($fields as $formField) : ?>
<?= $formField->renderActiveForm($form, $model)?>
<? endforeach; ?>
<? endif; ?>
<?php ActiveForm::end(); ?>
\ No newline at end of file
<?php
/**
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010 SkeekS (СкикС)
* @date 18.03.2015
*/
namespace skeeks\modules\cms\form\widgets;
use skeeks\modules\cms\form\models\Form;
/**
* Class ActiveForm
* @package skeeks\modules\cms\form\widgets
*/
class ActiveForm extends \skeeks\cms\base\widgets\ActiveForm
{
/**
* @var Form
*/
public $modelForm;
public function __construct($config = [])
{
$this->validationUrl = \skeeks\cms\helpers\UrlHelper::construct('form/backend/validate')->toString();
$this->action = \skeeks\cms\helpers\UrlHelper::construct('form/backend/submit')->toString();
$this->enableAjaxValidation = true;
parent::__construct($config);
}
public function init()
{
parent::init();
echo \yii\helpers\Html::hiddenInput(Form::FROM_PARAM_ID_NAME, $this->modelForm->id);
}
public function run()
{
parent::run();
$this->view->registerJs(<<<JS
$('#{$this->id}').on('beforeSubmit', function (event, attribute, message) {
return false;
});
$('#{$this->id}').on('afterValidate', function (event, attribute, message) {
var Jform = $(this);
var ajax = sx.ajax.preparePostQuery($(this).attr('action'), $(this).serialize());
new sx.classes.AjaxHandlerBlocker(ajax, {
'wrapper': '#' + $(this).attr('id')
});
//new sx.classes.AjaxHandlerNoLoader(ajax); //отключение глобального загрузчика
new sx.classes.AjaxHandlerNotifyErrors(ajax, {
'error': "Не удалось отправить форму",
}); //отключение глобального загрузчика
ajax.onError(function(e, data)
{
})
.onSuccess(function(e, data)
{
var response = data.response;
if (response.success == true)
{
$('input', Jform).each(function(i,s)
{
if ($(this).attr('name') != '_csrf' && $(this).attr('name') != 'sx-auto-form')
{
$(this).val('');
}
});
sx.notify.success(response.message);
} else
{
sx.notify.error(response.message);
}
})
.execute();
return false;
});
JS
);
}
}
<?php
/**
* Publications
*
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010-2014 SkeekS (Sx)
* @date 08.12.2014
* @since 1.0.0
*/
namespace skeeks\modules\cms\form\widgets\form;
use skeeks\cms\base\Widget;
use skeeks\cms\models\Publication;
use skeeks\cms\models\Search;
use skeeks\cms\models\Tree;
use skeeks\cms\widgets\base\hasModels\WidgetHasModels;
use skeeks\cms\widgets\base\hasModelsSmart\WidgetHasModelsSmart;
use skeeks\cms\widgets\WidgetHasTemplate;
use skeeks\modules\cms\form\models\Form;
use skeeks\modules\cms\slider\models\Slide;
use Yii;
use yii\data\Pagination;
use yii\helpers\ArrayHelper;
/**
* Class FormWidget
* @package skeeks\modules\cms\form\widgets\form
*/
class FormWidget extends Widget
{
/**
* @var null|string
*/
public $form_id = '';
public function rules()
{
return ArrayHelper::merge(parent::rules(), [
[['form_id'], 'required'],
[['form_id'], 'integer'],
]);
}
public function attributeLabels()
{
return ArrayHelper::merge(parent::attributeLabels(), [
'form_id' => 'Форма',
]);
}
public function run()
{
parent::run();
$formModel = Form::find()->where(['id' => $this->form_id])->one();
if ($formModel)
{
return $formModel->render();
}
return '';
}
}
<?php
/**
* _form
*
* @author Semenov Alexander <semenov@skeeks.com>
* @link http://skeeks.com/
* @copyright 2010-2014 SkeekS (Sx)
* @date 09.11.2014
* @since 1.0.0
*/
use yii\helpers\Html;
use skeeks\cms\modules\admin\widgets\form\ActiveFormUseTab as ActiveForm;
/* @var $this yii\web\View */
/* @var $model \skeeks\cms\models\WidgetConfig */
?>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'form_id')->widget(
\skeeks\cms\widgets\formInputs\EditedSelect::className(), [
'items' => \yii\helpers\ArrayHelper::map(
\skeeks\modules\cms\form\models\Form::find()->all(),
'id', 'name'
),
'controllerRoute' => 'form/admin-form',
]);
?>
<?= $form->buttonsCreateOrUpdate($model); ?>
<?php $form = ActiveForm::end(); ?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment