SaidbakR
SaidbakR

Reputation: 13552

Change the JuiAsset theme in yii2

I have using the datePicker from yii2-jui and I want to change the Jquery Ui theme used. I tried harded coded change in myapp\vendor\yiisoft\yii2-jui\JuiAsset.php

class JuiAsset extends AssetBundle
{
    public $sourcePath = '@bower/jquery-ui';
    public $js = [
        'jquery-ui.js',
    ];
    public $css = [
        'themes/THE_OTHER_THEME/jquery-ui.css',
    ];
    public $depends = [
        'yii\web\JqueryAsset',
    ];
}

Here are a snippet of the _form view:

<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\jui\DatePicker;

/* @var $this yii\web\View */
/* @var $model frontend\models\Profile */
/* @var $form yii\widgets\ActiveForm */
?>
...
 <?php $form = ActiveForm::begin(); ?>
 <?= $form->field($model, 'birthdate')->widget(DatePicker::className(), ['clientOptions' => ['dateFormat' => 'yy-mm-dd']]) ?>

However, this way is not solution to get what I want. I don't able to know what I have to do in my view _form.php to make it able to override the JuiAsset object's property $css

Upvotes: 0

Views: 2297

Answers (2)

Stefan Cretu
Stefan Cretu

Reputation: 1

a bit old, but you should put the assetManager override in your config/web.php file under 'components' like so:

$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],

'components' => [
    'assetManager' => [
        'bundles' => [
            'yii\jui\JuiAsset' => [
                'css' => [
                    'themes/flick/jquery-ui.css',
                ]
            ]
        ]
    ],   
],];

i just tested this as i was looking for something simmilar, worked just fine

Upvotes: 0

Mihai P.
Mihai P.

Reputation: 9367

Not only that is not OOP but modifying core Yii files is bad.

2 options:

  1. do this https://github.com/yiisoft/yii2/issues/6170 this is the second link that comes when you search on google. If you put the exact name of the question it is number 4 so you may try that in the future
  2. Register you new theme (css file) after the one registered by default. The classes in the theme registered last will overwrite the ones that are default.

EDIT: You told me you are looking for something in the comments

  Yii::$app->set('assetManager' , [
                'class' => 'yii\web\AssetManager',
                'bundles' => [
                    'yii\widgets\ActiveFormAsset' => [
                        'js' => [],
                        'depends' => [
                            'yii\adminUi\assetsBundle\AdminUiActiveForm',
                        ],
                    ],
                    'yii\grid\GridViewAsset' => [
                        'depends'   => [
                            'backend\assets\AppAsset'
                        ],
                    ],
                ],
                'linkAssets' => true,
            ]);

Upvotes: 1

Related Questions