src/widgets/ModalButton.php
protected function initOptions()
    {
        if (!($this->model instanceof Model)) {
            throw new InvalidConfigException('Model is required');
        }

        if (!($this->model->getPrimaryKey())) {
            throw new InvalidConfigException('Model has empty primary key');
        }

        if ($this->button !== false) {
            $this->button['position'] = isset($this->button['position']) ? $this->button['position'] : static::BUTTON_OUTSIDE;
        }

        if (empty($this->scenario)) {
            $this->scenario = $this->model->scenario;
        } else {
            $this->_oldScenario = $this->model->scenario;
            $this->model->scenario = $this->scenario;
        }

        if ($this->form !== false) {
            $formConfig = [
                'method' => 'POST',
                'action' => $this->scenario,
                'options' => [
                    'class' => 'inline',
                    'data' => [
                        'modal-form' => true,
                    ],
                ],
            ];
            if ($this->submit === static::SUBMIT_PJAX) {
                $formConfig['options'] = ArrayHelper::merge($formConfig['options'], [
                    'data' => ['pjax' => 1, 'pjax-push' => 0],
                ]);
            } elseif ($this->submit === static::SUBMIT_AJAX) {
                $formConfig['options'] = ArrayHelper::merge($formConfig['options'], [
                    'data' => ['ajax-submit' => 1],
                ]);

                $this->registerAjaxSubmit();
            }

            $this->form = ArrayHelper::merge($formConfig, $this->form);
        }

        if (is_array($footer = $this->modal['footer'])) {
            $tag = ArrayHelper::remove($footer, 'tag', 'input');
            $label = ArrayHelper::remove($footer, 'label', 'OK');
            $footer = ArrayHelper::merge([
                'data-modal-submit' => true,
                'data-loading-text' => '<i class="fa fa-circle-o-notch fa-spin"></i> ' . Yii::t('hipanel', 'loading'),
            ], $footer);

            if ($tag === 'input') {
                $footer['type']  = 'submit';
                $footer['value'] = $label;
            }

            $this->modal['footer'] = Html::tag($tag, $label, $footer);
            $this->registerFooterButtonScript();
        }

        $this->modal = ArrayHelper::merge([
            'id' => $this->getModalId(),
            'toggleButton' => ($this->button['position'] === static::BUTTON_IN_MODAL) ? $this->button : false,
        ], $this->modal);
    }
protected function initOptions()
    {
        if (!($this->model instanceof Model)) {
            throw new InvalidConfigException('Model is required');
        }

        if (!($this->model->getPrimaryKey())) {
            throw new InvalidConfigException('Model has empty primary key');
        }

        if ($this->button !== false) {
            $this->button['position'] = isset($this->button['position']) ? $this->button['position'] : static::BUTTON_OUTSIDE;
        }

        if (empty($this->scenario)) {
            $this->scenario = $this->model->scenario;
        } else {
            $this->_oldScenario = $this->model->scenario;
            $this->model->scenario = $this->scenario;
        }

        if ($this->form !== false) {
            $formConfig = [
                'method' => 'POST',
                'action' => $this->scenario,
                'options' => [
                    'class' => 'inline',
                    'data' => [
                        'modal-form' => true,
                    ],
                ],
            ];
            if ($this->submit === static::SUBMIT_PJAX) {
                $formConfig['options'] = ArrayHelper::merge($formConfig['options'], [
                    'data' => ['pjax' => 1, 'pjax-push' => 0],
                ]);
            } elseif ($this->submit === static::SUBMIT_AJAX) {
                $formConfig['options'] = ArrayHelper::merge($formConfig['options'], [
                    'data' => ['ajax-submit' => 1],
                ]);

                $this->registerAjaxSubmit();
            }

            $this->form = ArrayHelper::merge($formConfig, $this->form);
        }

        if (is_array($footer = $this->modal['footer'])) {
            $tag = ArrayHelper::remove($footer, 'tag', 'input');
            $label = ArrayHelper::remove($footer, 'label', 'OK');
            $footer = ArrayHelper::merge([
                'data-modal-submit' => true,
                'data-loading-text' => '<i class="fa fa-circle-o-notch fa-spin"></i> ' . Yii::t('hipanel', 'loading'),
            ], $footer);

            if ($tag === 'input') {
                $footer['type']  = 'submit';
                $footer['value'] = $label;
            }

            $this->modal['footer'] = Html::tag($tag, $label, $footer);
            $this->registerFooterButtonScript();
        }

        $this->modal = ArrayHelper::merge([
            'id' => $this->getModalId(),
            'toggleButton' => ($this->button['position'] === static::BUTTON_IN_MODAL) ? $this->button : false,
        ], $this->modal);
    }
protected function initOptions ( ) { if ( ! ( $ this -> model instanceof Model ) ) { throw new InvalidConfigException ( 'Model is required' ) ; } if ( ! ( $ this -> model -> getPrimaryKey ( ) ) ) { throw new InvalidConfigException ( 'Model has empty primary key' ) ; } if ( $ this -> button !== false ) { $ this -> button [ 'position' ] = isset ( $ this -> button [ 'position' ] ) ? $ this -> button [ 'position' ] : static :: BUTTON_OUTSIDE ; } if ( empty ( $ this -> scenario ) ) { $ this -> scenario = $ this -> model -> scenario ; } else { $ this -> _oldScenario = $ this -> model -> scenario ; $ this -> model -> scenario = $ this -> scenario ; } if ( $ this -> form !== false ) { $ formConfig = [ 'method' => 'POST' , 'action' => $ this -> scenario , 'options' => [ 'class' => 'inline' , 'data' => [ 'modal-form' => true , ] , ] , ] ; if ( $ this -> submit === static :: SUBMIT_PJAX ) { $ formConfig [ 'options' ] = ArrayHelper :: merge ( $ formConfig [ 'options' ] , [ 'data' => [ 'pjax' => 1 , 'pjax-push' => 0 ] , ] ) ; } elseif ( $ this -> submit === static :: SUBMIT_AJAX ) { $ formConfig [ 'options' ] = ArrayHelper :: merge ( $ formConfig [ 'options' ] , [ 'data' => [ 'ajax-submit' => 1 ] , ] ) ; $ this -> registerAjaxSubmit ( ) ; } $ this -> form = ArrayHelper :: merge ( $ formConfig , $ this -> form ) ; } if ( is_array ( $ footer = $ this -> modal [ 'footer' ] ) ) { $ tag = ArrayHelper :: remove ( $ footer , 'tag' , 'input' ) ; $ label = ArrayHelper :: remove ( $ footer , 'label' , 'OK' ) ; $ footer = ArrayHelper :: merge ( [ 'data-modal-submit' => true , 'data-loading-text' => '<i class="fa fa-circle-o-notch fa-spin"></i> ' . Yii :: t ( 'hipanel' , 'loading' ) , ] , $ footer ) ; if ( $ tag === 'input' ) { $ footer [ 'type' ] = 'submit' ; $ footer [ 'value' ] = $ label ; } $ this -> modal [ 'footer' ] = Html :: tag ( $ tag , $ label , $ footer ) ; $ this -> registerFooterButtonScript ( ) ; } $ this -> modal = ArrayHelper :: merge ( [ 'id' => $ this -> getModalId ( ) , 'toggleButton' => ( $ this -> button [ 'position' ] === static :: BUTTON_IN_MODAL ) ? $ this -> button : false , ] , $ this -> modal ) ; }
Initialization of options.
@throws InvalidConfigException
Initialization of options .