init() 공개 메소드

If you override this method, make sure you call the parent implementation first.
public init ( )
예제 #1
2
 public function init()
 {
     $this->id = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->id;
     $this->_options = ['serverUrl' => Url::to(['upload']), 'initialFrameWidth' => '100%', 'initialFrameHeight' => '300', 'lang' => strtolower(Yii::$app->language) == 'en-us' ? 'en' : 'zh-cn'];
     $this->clientOptions = ArrayHelper::merge($this->_options, $this->clientOptions);
     parent::init();
 }
예제 #2
1
 public function init()
 {
     parent::init();
     \Yii::setAlias('@webuploader', __DIR__);
     if (empty($this->driver)) {
         $this->driver = isset(\Yii::$app->params['webuploader_driver']) ? \Yii::$app->params['webuploader_driver'] : 'local';
     }
     if ($this->driver == 'local') {
         // 初始化@static别名,默认@web/static,最好根据自己的需求提前设置好@static别名
         $static = \Yii::getAlias('@static', false);
         $staticroot = \Yii::getAlias('@staticroot', false);
         if (!$static || !$staticroot) {
             \Yii::setAlias('@static', '@web/static');
             \Yii::setAlias('@staticroot', '@webroot/static');
         }
     }
     $this->server = $this->server ?: Url::to(['/site/webupload', 'driver' => $this->driver]);
     $this->options['boxId'] = isset($this->options['boxId']) ? $this->options['boxId'] : 'picker';
     $this->options['previewWidth'] = isset($this->options['previewWidth']) ? $this->options['previewWidth'] : '250';
     $this->options['previewHeight'] = isset($this->options['previewHeight']) ? $this->options['previewHeight'] : '150';
     if ($this->hasModel()) {
         $this->hiddenInput = Html::activeHiddenInput($this->model, $this->attribute);
     } else {
         $this->hiddenInput = Html::hiddenInput($this->name, $this->value);
     }
 }
예제 #3
0
 public function init()
 {
     parent::init();
     if (!isset($this->options['id'])) {
         $this->options['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId();
     }
 }
 /**
  * 
  * @see \yii\base\Object::init()
  */
 public function init()
 {
     if (isset($this->selector)) {
         $this->name = '';
     }
     parent::init();
 }
예제 #5
0
 public function init()
 {
     parent::init();
     if (!$this->buttonText) {
         $this->buttonText = \Yii::t('app', 'Setting property');
     }
 }
예제 #6
0
 public function init()
 {
     parent::init();
     if (!isset($this->htmlOptions['class'])) {
         $this->htmlOptions['class'] = 'editor';
     }
 }
예제 #7
0
 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->registerMessages();
     if ($this->maxNumberOfFiles > 1 || $this->multiple) {
         $this->multiple = true;
     }
     if ($this->hasModel()) {
         $this->name = $this->name ?: Html::getInputName($this->model, $this->attribute);
         $this->value = $this->value ?: Html::getAttributeValue($this->model, $this->attribute);
     }
     if (!array_key_exists('name', $this->clientOptions)) {
         $this->clientOptions['name'] = $this->name;
     }
     if ($this->multiple && $this->value && !is_array($this->value)) {
         throw new InvalidParamException('In "multiple" mode, value must be an array.');
     }
     if (!array_key_exists('fileparam', $this->url)) {
         $this->url['fileparam'] = $this->getFileInputName();
     }
     if (!$this->files && $this->value) {
         $this->files = $this->multiple ? $this->value : [$this->value];
     }
     if ($this->files) {
         foreach ($this->files as &$file) {
             if (!isset($file['alias_url']) && is_array($file)) {
                 $option = isset($this->clientOptions['baseUrlAttribute']) ? $this->clientOptions['baseUrlAttribute'] : null;
                 $file['alias_url'] = $option ? isset($file[$option]) ? Yii::getAlias($file[$option]) : null : null;
             }
         }
     }
     $this->clientOptions = ArrayHelper::merge(['url' => Url::to($this->url), 'multiple' => $this->multiple, 'sortable' => $this->sortable, 'maxNumberOfFiles' => $this->maxNumberOfFiles, 'maxFileSize' => $this->maxFileSize, 'minFileSize' => $this->minFileSize, 'acceptFileTypes' => $this->acceptFileTypes, 'files' => $this->files, 'showPreviewFilename' => $this->showPreviewFilename, 'pathAttribute' => 'path', 'baseUrlAttribute' => 'base_url', 'pathAttributeName' => 'path', 'baseUrlAttributeName' => 'base_url', 'messages' => ['maxNumberOfFiles' => Yii::t($this->messagesCategory, 'Maximum number of files exceeded'), 'acceptFileTypes' => Yii::t($this->messagesCategory, 'File type not allowed'), 'maxFileSize' => Yii::t($this->messagesCategory, 'File is too large'), 'minFileSize' => Yii::t($this->messagesCategory, 'File is too small')]], $this->clientOptions);
 }
예제 #8
0
 public function init()
 {
     parent::init();
     $this->view = $this->getView();
     AssetBundle::register($this->view);
     $this->cropperOptions = array_merge($this->cropperOptions, $this->defaultCropperOptions);
 }
예제 #9
0
 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     $this->registerMessages();
     if ($this->maxNumberOfFiles > 1) {
         $this->multiple = true;
     }
     if ($this->hasModel()) {
         $this->name = $this->name ?: Html::getInputName($this->model, $this->attribute);
         $this->value = $this->value ?: Html::getAttributeValue($this->model, $this->attribute);
     }
     if (!array_key_exists('name', $this->clientOptions)) {
         $this->clientOptions['name'] = $this->name;
     }
     if ($this->multiple && $this->value && !is_array($this->value)) {
         throw new InvalidParamException('In "multiple" mode, value must be an array.');
     }
     if (!array_key_exists('fileparam', $this->url)) {
         $this->url['fileparam'] = $this->getFileInputName();
     }
     if (!$this->files && $this->value) {
         $this->files = $this->multiple ? $this->value : [$this->value];
     }
     $this->clientOptions = ArrayHelper::merge(['url' => Url::to($this->url), 'multiple' => $this->multiple, 'sortable' => $this->sortable, 'maxNumberOfFiles' => $this->maxNumberOfFiles, 'maxFileSize' => $this->maxFileSize, 'minFileSize' => $this->minFileSize, 'acceptFileTypes' => $this->acceptFileTypes, 'files' => $this->files, 'messages' => ['maxNumberOfFiles' => Yii::t($this->messagesCategory, 'Maximum number of files exceeded', [], 'en'), 'acceptFileTypes' => Yii::t($this->messagesCategory, 'File type not allowed', [], 'en'), 'maxFileSize' => Yii::t($this->messagesCategory, 'File is too large', [], 'en'), 'minFileSize' => Yii::t($this->messagesCategory, 'File is too small', [], 'en')]], $this->clientOptions);
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->target === null) {
         $this->target = '#' . $this->getId();
     }
 }
 public function init()
 {
     parent::init();
     if ($this->dateFormat === null) {
         $this->dateFormat = Yii::$app->formatter->dateFormat;
     }
 }
예제 #12
0
 public function init()
 {
     parent::init();
     if ($this->backendUrl === null) {
         $this->backendUrl = UrlHelper::construct('cms/admin-storage-files/link-to-models')->enableAdmin()->toString();
     }
 }
예제 #13
0
파일: Rating.php 프로젝트: vetoni/toko
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!isset($this->options['name'])) {
         $this->options['name'] = $this->hasModel() ? Html::getInputName($this->model, $this->attribute) : $this->name;
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if ($this->selector === null) {
         $this->selector = '#' . $this->options['id'];
     }
 }
예제 #15
0
 public function init()
 {
     if (is_null($this->name)) {
         throw new InvalidConfigException('Name property must be specified.');
     }
     parent::init();
     $view = $this->getView();
     JoyrideAsset::register($view);
     if (isset($this->joyride_options['cookieMonster']) && $this->joyride_options['cookieMonster'] === true) {
         $this->publishAndRegisterFile('@vendor/branchonline/yii2-joyride/src/assets/jquery.cookie.js', ['depends' => JoyrideAsset::className()]);
     }
     $joyride_options_strings = [];
     $this->joyride_options['autoStart'] = 'true';
     foreach ($this->joyride_options as $k => $v) {
         if (is_bool($v)) {
             $value = $v ? 'true' : 'false';
         } else {
             $value = "'" . $v . "'";
         }
         $joyride_options_strings[] = $k . ': ' . $value;
     }
     $view->registerJs('console.log($("#' . $this->getId() . '")); $("#' . $this->getId() . '").joyride({
          ' . implode(', ', $joyride_options_strings) . '
     });');
 }
예제 #16
0
 /**
  * @inheritdoc
  * @throws InvalidConfigException
  */
 public function init()
 {
     if (!isset($this->clientOptions['data-sitekey'])) {
         throw new InvalidConfigException('You should set data-sitekey');
     }
     parent::init();
 }
예제 #17
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (is_null($this->language)) {
         $this->language = Yii::$app->language;
         if (is_null($this->language)) {
             $this->language = 'en-US';
         }
     }
     $formatter = Yii::$app->getFormatter();
     if (is_null($this->items)) {
         $this->items = $formatter->booleanFormat;
         if (is_null($this->items)) {
             $this->items = [Yii::t('yii', 'No', [], $this->language), Yii::t('yii', 'Yes', [], $this->language)];
         }
     }
     if (is_null($this->prompt)) {
         $this->prompt = $formatter->nullDisplay;
         if (is_null($this->prompt)) {
             $this->prompt = Yii::t('yii', '(not set)', [], $this->language);
         }
     }
     Html::addCssClass($this->options, 'form-control');
     if (array_key_exists('value', $this->options)) {
         $this->value = $this->options['value'];
         unset($this->options['value']);
     }
     if (is_string($this->prompt) && !array_key_exists('prompt', $this->options)) {
         $this->options['prompt'] = strip_tags($this->prompt);
     }
 }
예제 #18
0
 public function init()
 {
     if (!isset($this->options['class'])) {
         $this->options['class'] = 'form-control';
     }
     if (!isset($this->jsOptions['isRTL'])) {
         $this->jsOptions['isRTL'] = true;
     }
     if (!isset($this->jsOptions['changeMonth'])) {
         $this->jsOptions['changeMonth'] = true;
     }
     if (!isset($this->jsOptions['changeYear'])) {
         $this->jsOptions['changeYear'] = true;
     }
     if (!isset($this->jsOptions['dateFormat'])) {
         $this->jsOptions['dateFormat'] = 'yy/mm/dd';
     }
     if (!isset($this->jsOptions['weekStart'])) {
         $this->jsOptions['weekStart'] = 0;
     }
     if (!isset($this->value)) {
         $this->setValue();
     }
     parent::init();
 }
예제 #19
0
 public function init()
 {
     parent::init();
     if (!array_key_exists('id', $this->clientOptions)) {
         $this->clientOptions['id'] = $this->id;
     }
 }
예제 #20
0
 public function init()
 {
     parent::init();
     if (empty($this->language)) {
         $this->language = ElFinder::getSupportedLanguage(Yii::$app->language);
     }
     if (empty($this->buttonOptions['id'])) {
         $this->buttonOptions['id'] = $this->options['id'] . '_button';
     }
     $this->buttonOptions['type'] = 'button';
     $managerOptions = [];
     if (!empty($this->filter)) {
         $managerOptions['filter'] = $this->filter;
     }
     $managerOptions['callback'] = $this->options['id'];
     if (!empty($this->language)) {
         $managerOptions['lang'] = $this->language;
     }
     if (!empty($this->multiple)) {
         $managerOptions['multiple'] = $this->multiple;
     }
     if (!empty($this->path)) {
         $managerOptions['path'] = $this->path;
     }
     $this->_managerOptions['url'] = ElFinder::getManagerUrl($this->controller, $managerOptions);
     $this->_managerOptions['width'] = $this->width;
     $this->_managerOptions['height'] = $this->height;
     $this->_managerOptions['id'] = $this->options['id'];
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     $formatter = Yii::$app->getFormatter();
     if (is_null($this->dateFormat)) {
         $this->dateFormat = $formatter->dateFormat;
         if (is_null($this->dateFormat)) {
             $this->dateFormat = 'medium';
         }
     }
     if (is_null($this->timeFormat)) {
         $this->timeFormat = $formatter->timeFormat;
         if (is_null($this->timeFormat)) {
             $this->timeFormat = 'medium';
         }
     }
     if (is_null($this->altDateFormat)) {
         $this->altDateFormat = 'yyyy-MM-dd';
     }
     if (is_null($this->altTimeFormat)) {
         $this->altTimeFormat = 'HH:mm:ss';
     }
     Html::addCssClass($this->options, 'form-control');
     $this->altOptions['id'] = $this->options['id'] . '-alt';
     $this->clientOptions = array_merge(array_diff_assoc(['numberOfMonths' => $this->numberOfMonths, 'showButtonPanel' => $this->showButtonPanel], get_class_vars(__CLASS__)), $this->clientOptions, ['dateFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->dateFormat), 'separator' => static::SEPARATOR, 'timeFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->timeFormat, 'time'), 'altField' => '#' . $this->altOptions['id'], 'altFieldTimeOnly' => false, 'altFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->altDateFormat), 'altSeparator' => static::SEPARATOR, 'altTimeFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->altTimeFormat, 'time')]);
     if (array_key_exists('readonly', $this->options) && $this->options['readonly']) {
         if (!array_key_exists('beforeShow', $this->clientOptions)) {
             $this->clientOptions['beforeShow'] = new JsExpression('function (input, inst) { return false; }');
         }
     }
 }
예제 #22
0
 public function init()
 {
     if (isset($this->name) || isset($this->model) || isset($this->attribute)) {
         parent::init();
     }
     $this->config = ArrayHelper::merge(['style_formats_merge' => true, 'theme' => $this->theme, 'plugins' => $this->plugins, 'templates' => $this->templates, 'height' => $this->height], $this->config);
     $this->config['fontsize_formats'] = "6pt 7pt 8pt 9pt 10pt 11pt 12pt 13pt 14pt 15pt 16pt 18pt 20pt 24pt 28pt 36pt 40pt 48pt";
     if (!isset($this->options['rows'])) {
         $this->options['rows'] = 10;
     }
     if (!empty($this->toolbar)) {
         $this->config['toolbar'] = implode(' | ', $this->toolbar);
     }
     if (!empty($this->removeToolbar)) {
         foreach ($this->removeToolbar as $toolbar) {
             $this->config['toolbar'] = str_replace($toolbar, '', $this->config['toolbar']);
         }
     }
     if ($this->toggle['active']) {
         if (!isset($this->toggle['id'])) {
             $this->toggle['id'] = $this->getId();
         }
     }
     if ($this->showAdvancedImageTab) {
         $this->config['image_advtab'] = 'true';
     }
 }
예제 #23
0
 public function init()
 {
     parent::init();
     $clientValue = self::toClientFormat($this->model->{$this->attribute});
     if ($clientValue === false) {
         throw new InvalidConfigException();
     }
     $this->model->{$this->attribute} = $clientValue;
     if (!isset($this->select2Config['pluginOptions']['allowClear'])) {
         $this->select2Config['pluginOptions']['placeholder'] = '';
         $this->select2Config['pluginOptions']['allowClear'] = true;
     }
     if (!isset($this->select2Config['options'])) {
         $this->select2Config['options'] = null;
     }
     $this->setDataTarget($this->select2Config['options']);
     Html::addCssClass($this->select2Config['options'], 'combowidget-select2');
     if (!isset($this->select2Config['value'])) {
         $this->select2Config['value'] = $this->inputValue(self::STATE_LIST);
     }
     // ugly workaround (InputWidget must have name or model)
     $this->select2Config['name'] = Html::getInputId($this->model, $this->attribute) . '-ignored-combowidget-select2';
     $this->setDataTarget($this->switchOptions);
     Html::addCssClass($this->switchOptions, 'combowidget-switch');
     $this->setDataTarget($this->textInputOptions);
     Html::addCssClass($this->textInputOptions, 'combowidget-textinput');
 }
예제 #24
0
 /**
  * Initializes the widget.
  */
 public function init()
 {
     parent::init();
     if (empty($this->id)) {
         $this->id = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId();
     }
     if (empty($this->name)) {
         $this->name = $this->hasModel() ? Html::getInputName($this->model, $this->attribute) : $this->id;
     }
     if (empty($this->value) && $this->hasModel() && $this->model->hasAttribute($this->attribute)) {
         $this->value = $this->model->getAttribute($this->attribute);
     }
     if (!$this->autoHeightEnable) {
         if (empty($this->width)) {
             $this->width = '100%';
         }
         if (empty($this->height)) {
             $this->height = '350';
         }
     }
     $options = ['id' => $this->id, 'style' => 'width:100%;height:350px'];
     $this->options = array_merge($options, $this->options);
     $jsOptions = ['serverUrl' => Url::to(['ueditor', 'type' => 'ueditor']), 'autoHeightEnable' => $this->autoHeightEnable, 'autoFloatEnable' => true, 'textarea' => $this->name];
     $this->jsOptions = array_merge($jsOptions, $this->jsOptions);
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (!$this->hasModel() && $this->name === null) {
         throw new InvalidConfigException("'model' and 'attribute' properties must be specified.");
     }
     parent::init();
     $this->registerTranslations();
     Asset::register($this->getView());
     foreach ($this->model->behaviors as $b) {
         if ($b instanceof Behavior) {
             foreach ($b->attributes as $attr => $options) {
                 Behavior::ensureAttribute($attr, $options);
                 if ($attr == $this->attribute) {
                     if ($b->needCrop($attr)) {
                         $this->crop = true;
                         CropAsset::register($this->getView());
                         $this->jcropSettings = array_merge($this->jcropDefaultSettings, $this->jcropSettings);
                         $this->jcropSettings['onSelect'] = new JsExpression('function (c) {
                             setCoords("' . $this->getSelector() . '", c);
                         }');
                         if (isset($options['width'], $options['height'])) {
                             $this->jcropSettings['aspectRatio'] = $options['width'] / $options['height'];
                         }
                     }
                     break;
                 }
             }
             break;
         }
     }
 }
예제 #26
0
 /**
  * Initializes the widget.
  */
 public function init()
 {
     if ($this->style === null) {
         $this->style = static::STYLE_INPUT;
     }
     parent::init();
 }
예제 #27
0
 public function init()
 {
     $id = $this->getId();
     $buttonId = 'fm-btn-' . $id;
     $this->fileManager = ArrayHelper::merge(['controller' => Adm::getInstance()->id . '/elfinder', 'filter' => 'image', 'template' => '<div class="input-group fm-input-cont"><span class="input-group-addon">{button}</span>{input}</div>', 'options' => ['class' => 'form-control'], 'buttonTag' => 'a', 'buttonName' => '', 'buttonOptions' => ['class' => 'glyphicon glyphicon-folder-open filemanager-btn', 'href' => 'javascript:void(0);', 'id' => $buttonId, 'data' => ['placement' => 'top']], 'multiple' => true], $this->fileManager);
     if ($this->enablePreview) {
         $basePath = Yii::getAlias($this->basePath);
         $this->getView()->registerJs('
         $("#' . $buttonId . '").tooltip({
             html: true,
             title: function(){
                 var v = $(this).closest(".fm-input-cont").find("#' . Html::getInputId($this->model, $this->attribute) . '").val();
                 var $img = $("<img src=\\"' . $basePath . '" + v + "\\" class=\\"hide file-input-img\\">");
                 var $loading = $("<span class=\\"file-input-loading fa fa-spinner rotating\\"></span>");
                 $img.on("load", function(){
                     $img.removeClass("hide");
                     $loading.hide();
                 })
                 return $("<div class=\\"file-input-cont\\"><div>").append($loading).append($img);
             },
         });
     ');
     }
     parent::init();
 }
 /**
  * Initializes the widget.
  * @throws InvalidConfigException if the "mask" property is not set.
  */
 public function init()
 {
     parent::init();
     if (empty($this->mask)) {
         throw new InvalidConfigException('The "mask" property must be set.');
     }
 }
예제 #29
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     self::registerTranslations();
     if ($this->uploadUrl === null) {
         throw new InvalidConfigException(Yii::t('cropper', 'MISSING_ATTRIBUTE', ['attribute' => 'uploadUrl']));
     } else {
         $this->uploadUrl = rtrim(Yii::getAlias($this->uploadUrl), '/') . '/';
     }
     if ($this->KeyFolder) {
         $this->previewUrl = $this->previewUrl . '/' . $this->KeyFolder;
     }
     if ($this->label == '') {
         $this->label = Yii::t('cropper', 'DEFAULT_LABEL');
     }
     // keep aspect ratio
     $ratio1 = $this->width / $this->height;
     $ratio2 = $this->display_width / $this->display_height;
     if ($ratio1 != $ratio2) {
         if ($ratio1 > 1) {
             $target_width = $this->display_width;
             $target_height = $this->display_width / $ratio1;
         } else {
             $target_width = $this->display_height * $ratio1;
             $target_height = $this->display_height;
         }
         $this->display_width = $target_width;
         $this->display_height = $target_height;
     }
 }
예제 #30
-1
 public function init()
 {
     if ($this->name === null && !$this->hasModel() && $this->selector === null) {
         throw new InvalidConfigException("Either 'name', or 'model' and 'attribute' properties must be specified.");
     }
     if (null === $this->schema) {
         throw new InvalidConfigException("You must specify 'schema' property.");
     }
     if ($this->hasModel() && !isset($this->options['id'])) {
         $this->options['id'] = Html::getInputId($this->model, $this->attribute);
     }
     if ($this->hasModel()) {
         $this->name = empty($this->options['name']) ? Html::getInputName($this->model, $this->attribute) : $this->options['name'];
         $this->value = Html::getAttributeValue($this->model, $this->attribute);
     }
     if (!isset($this->containerOptions['id'])) {
         $this->containerOptions['id'] = ($this->hasModel() ? Html::getInputId($this->model, $this->attribute) : $this->getId()) . '-container';
     }
     if ($this->inputId === null) {
         $this->inputId = $this->options['id'];
     } else {
         $this->_renderInput = false;
     }
     parent::init();
     JsonEditorAsset::register($this->getView());
 }