_form.php 7.85 KB
<?php
    
    use artbox\weblog\models\Article;
    use artbox\weblog\models\ArticleLang;
    
    //    use artweb\artbox\blog\models\BlogCategory;
    //    use artweb\artbox\blog\models\BlogTag;
    use kartik\select2\Select2;
    use noam148\imagemanager\components\ImageManagerInputWidget;
    use yii\helpers\Html;
    use yii\helpers\Url;
    use yii\web\View;
    use yii\widgets\ActiveForm;
    use artbox\core\widgets\LanguageForm;
    use yii\web\JsExpression;
    
    /**
     * @var View           $this
     * @var Article        $model
     * @var ActiveForm     $form
     * @var ArticleLang[]  $modelLangs
     * @var BlogCategory[] $categories
     * @var BlogTag[]      $tags
     * @var array          $products
     * @var array          $articles
     */
?>

<div class="blog-article-form">
    
    <?php $form = ActiveForm::begin(
        [
            'options' => [ 'enctype' => 'multipart/form-data' ],
        ]
    ); ?>
    
    <?php
        echo LanguageForm::widget(
            [
                'modelLangs' => $modelLangs,
                'formView'   => '@artbox/weblog/views/blog-article/_form_language',
                'form'       => $form,
            ]
        );
    ?>
    
    <?php
        //        echo $form->field($model, 'blogCategories')
        //                  ->widget(
        //                      Select2::className(),
        //                      [
        //                          'data'          => $categories,
        //                          'theme'         => Select2::THEME_BOOTSTRAP,
        //                          'options'       => [
        //                              'placeholder' => \Yii::t('blog', 'Select category'),
        //                              'multiple'    => true,
        //                          ],
        //                          'pluginOptions' => [
        //                              'allowClear' => true,
        //                          ],
        //                      ]
        //                  );
    ?>
    
    <?php
        //        echo $form->field($model, 'blogTags')
        //                  ->widget(
        //                      Select2::className(),
        //                      [
        //                          'data'          => $tags,
        //                          'theme'         => Select2::THEME_BOOTSTRAP,
        //                          'options'       => [
        //                              'placeholder' => \Yii::t('blog', 'Select tag'),
        //                              'multiple'    => true,
        //                          ],
        //                          'pluginOptions' => [
        //                              'allowClear' => true,
        //                          ],
        //                      ]
        //                  );
    ?>
    
    <?= $form->field($model, 'image_id')
             ->widget(
                 ImageManagerInputWidget::className(),
                 [
                     'aspectRatio'                  => ( 16 / 9 ),
                     //set the aspect ratio
                     'showPreview'                  => true,
                     //false to hide the preview
                     'showDeletePickedImageConfirm' => false,
                     //on true show warning before detach image
                 ]
             ); ?>
    
    <?php
        //        echo $form->field($model, 'products')
        //                  ->widget(
        //                      Select2::className(),
        //                      [
        //                          'data'          => $products,
        //                          'options'       => [
        //                              'placeholder' => \Yii::t('blog', 'Select related products'),
        //                              'multiple'    => true,
        //                          ],
        //                          'pluginOptions' => [
        //                              'allowClear'         => true,
        //                              'minimumInputLength' => 3,
        //                              'language'           => [
        //                                  'errorLoading' => new JsExpression(
        //                                      "function () { return '" . \Yii::t('blog', 'Waiting for results') . "'; }"
        //                                  ),
        //                              ],
        //                              'ajax'               => [
        //                                  'url'      => yii\helpers\Url::to([ '/blog/blog-article/product-list' ]),
        //                                  'dataType' => 'json',
        //                                  'data'     => new JsExpression('function(params) { return {q:params.term}; }'),
        //                              ],
        //                              'templateResult'     => new JsExpression('function(product) { return product.text; }'),
        //                              'templateSelection'  => new JsExpression('function (product) { return product.text; }'),
        //                          ],
        //                      ]
        //                  );
    ?>
    
    <?php
        //        if (empty( $model->id )) {
        //            $data = 'function(params) { return {q:params.term}; }';
        //        } else {
        //            $data = 'function(params) { return {q:params.term, id:' . $model->id . '}; }';
        //        }
        //        echo $form->field($model, 'blogArticles')
        //                  ->widget(
        //                      Select2::className(),
        //                      [
        //                          'data'          => $articles,
        //                          'options'       => [
        //                              'placeholder' => \Yii::t('blog', 'Select related articles'),
        //                              'multiple'    => true,
        //                          ],
        //                          'pluginOptions' => [
        //                              'allowClear'         => true,
        //                              'minimumInputLength' => 3,
        //                              'language'           => [
        //                                  'errorLoading' => new JsExpression(
        //                                      "function () { return '" . \Yii::t('blog', 'Waiting for results') . "'; }"
        //                                  ),
        //                              ],
        //                              'ajax'               => [
        //                                  'url'      => yii\helpers\Url::to([ '/blog/blog-article/article-list' ]),
        //                                  'dataType' => 'json',
        //                                  'data'     => new JsExpression(
        //                                      $data
        //                                  ),
        //                              ],
        //                              'templateResult'     => new JsExpression('function(article) { return article.text; }'),
        //                              'templateSelection'  => new JsExpression('function (article) { return article.text; }'),
        //                          ],
        //                      ]
        //                  );
    ?>
    
    <?= $form->field($model, 'sort')
             ->textInput() ?>
    
    <?= $form->field($model, 'status')
             ->checkbox(
                 [
                     'class' => 'flat',
                 ]
             ) ?>
    
    <?= $form->field($model, 'author_id')
             ->textInput() ?>
    
    <div class="form-group">
        <?= Html::submitButton(
            $model->isNewRecord ? 'Create' : 'Update',
            [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]
        ) ?>
    </div>
    
    <?php ActiveForm::end(); ?>

</div>