Skip to content

Commit

Permalink
Updates to release v3.0.5 fixes #119
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Jun 1, 2022
1 parent b37e19a commit 5c09512
Show file tree
Hide file tree
Showing 24 changed files with 126 additions and 54 deletions.
34 changes: 34 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
Change Log: `yii2-krajee-base`
==============================

## Version 3.0.5

**Date:** 01-Jun-2022

- (enh #119): Allow translations to work better when widget is extended (new widget property sourcePath).
New property `sourcePath` added to `WidgetTrait` and used in `Widget` and `InputWidget`.
```php
/**
* @var string directory path to the original widget source. If not set, will default to the working directory for
* the current widget's class. Setting this property can be useful in specific cases, like when you are extending
* the Krajee widget with your own custom namespaced class. In that case, set this property to the original Krajee
* Widget Base path. Yii path alias parsing is supported (using `@` symbols). For example:
* ~~~
* // your custom extended widget
* namespace myapp\widgets;
* class MyDateRangePicker extends kartik\daterange\DateRangePicker {
* // directly set the property to the original Krajee base widget directory
* // you can use Yii path aliases
* public $sourcePath = '@vendor/kartik-v/yii2-date-range/src';
* }
*
* // Alternatively you can also override this property while rendering the widget
* // view.php: where widget is rendered
* use myapp\widgets\MyDateRangePicker;
*
* echo MyDateRangePicker::widget([
* 'name' => 'custom',
* 'sourcePath' => '@vendor/kartik-v/yii2-date-range/src'
* ]);
* ~~~
*/
public $sourcePath;
```

## Version 3.0.4

**Date:** 26-Feb-2022
Expand Down
2 changes: 1 addition & 1 deletion src/AddonTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/AnimateAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/AssetBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/BaseAssetBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapIconsAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/BootstrapInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
10 changes: 5 additions & 5 deletions src/BootstrapTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down Expand Up @@ -205,9 +205,9 @@ trait BootstrapTrait
/**
* @var bool flag to detect whether bootstrap 4.x version is set
*
* This property is deprecated since v3.0.4 and replaced by the more flexible [[_bsVer]] flag.
* This property is deprecated since v3.0.0 and replaced by the more flexible [[_bsVer]] flag.
*
* @deprecated since v3.0.4 and replaced by [[_bsVer]] flag
* @deprecated since v3.0.0 and replaced by [[_bsVer]] flag
*/
protected $_isBs4;

Expand Down Expand Up @@ -332,9 +332,9 @@ public function getBsVer()
/**
* Validate if Bootstrap 4.x version.
*
* This property is deprecated since v3.0.4 and replaced by the [[isBs]] method.
* This property is deprecated since v3.0.0 and replaced by the [[isBs]] method.
*
* @deprecated since v3.0.4 and replaced by the [[isBs]] method
* @deprecated since v3.0.0 and replaced by the [[isBs]] method
*
* @return bool
* @throws Exception
Expand Down
2 changes: 1 addition & 1 deletion src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/Html5Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/Html5InputAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @package yii2-krajee-base
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
48 changes: 26 additions & 22 deletions src/InputWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down Expand Up @@ -113,11 +113,12 @@ public function init()

/**
* Initializes the input widget.
*
* @throws ReflectionException
*/
protected function initInputWidget()
{
$this->initI18N(__DIR__, 'kvbase');
$this->initI18N($this->getBaseSourcePath(), 'kvbase');
if (!isset($this->language)) {
$this->language = Yii::$app->language;
}
Expand All @@ -137,7 +138,7 @@ protected function initInputWidget()
/**
* Validates and sets disabled or readonly inputs.
*
* @param array $options the HTML attributes for the input
* @param array $options the HTML attributes for the input
*/
protected function initDisability(&$options)
{
Expand All @@ -152,8 +153,8 @@ protected function initDisability(&$options)
/**
* Initialize the plugin language.
*
* @param string $property the name of language property in [[pluginOptions]].
* @param boolean $full whether to use the full language string. Defaults to `false`
* @param string $property the name of language property in [[pluginOptions]].
* @param boolean $full whether to use the full language string. Defaults to `false`
* which is the 2 (or 3) digit ISO-639 format.
* Defaults to 'language'.
*/
Expand All @@ -167,14 +168,14 @@ protected function initLanguage($property = 'language', $full = false)
/**
* Sets the language JS file if it exists.
*
* @param string $prefix the language filename prefix
* @param string $assetPath the path to the assets
* @param string $filePath the path to the JS file with the file name prefix
* @param string $suffix the file name suffix - defaults to '.js'
* @param string $prefix the language filename prefix
* @param string $assetPath the path to the assets
* @param string $filePath the path to the JS file with the file name prefix
* @param string $suffix the file name suffix - defaults to '.js'
*/
protected function setLanguage($prefix, $assetPath = null, $filePath = null, $suffix = '.js')
{
$pwd = Config::getCurrentDir($this);
$pwd = $this->getBaseSourcePath();
$s = DIRECTORY_SEPARATOR;
if ($assetPath === null) {
$assetPath = "{$pwd}{$s}assets{$s}";
Expand All @@ -186,16 +187,16 @@ protected function setLanguage($prefix, $assetPath = null, $filePath = null, $su
} elseif (Lib::substr($filePath, -1) != $s) {
$filePath .= $s;
}
$full = $filePath . $prefix . $this->language . $suffix;
$fullLower = $filePath . $prefix . strtolower($this->language) . $suffix;
$short = $filePath . $prefix . $this->_lang . $suffix;
if (Config::fileExists($assetPath . $full)) {
$full = $filePath.$prefix.$this->language.$suffix;
$fullLower = $filePath.$prefix.strtolower($this->language).$suffix;
$short = $filePath.$prefix.$this->_lang.$suffix;
if (Config::fileExists($assetPath.$full)) {
$this->_langFile = $full;
$this->pluginOptions['language'] = $this->language;
} elseif (Config::fileExists($assetPath . $fullLower)) {
} elseif (Config::fileExists($assetPath.$fullLower)) {
$this->_langFile = $fullLower;
$this->pluginOptions['language'] = strtolower($this->language);
} elseif (Config::fileExists($assetPath . $short)) {
} elseif (Config::fileExists($assetPath.$short)) {
$this->_langFile = $short;
$this->pluginOptions['language'] = $this->_lang;
} else {
Expand All @@ -207,15 +208,16 @@ protected function setLanguage($prefix, $assetPath = null, $filePath = null, $su
/**
* Generates an input.
*
* @param string $type the input type
* @param boolean $list whether the input is of dropdown list type
* @param string $type the input type
* @param boolean $list whether the input is of dropdown list type
*
* @return string the rendered input markup
*/
protected function getInput($type, $list = false)
{
if ($this->hasModel()) {
$input = 'active' . ucfirst($type);
$input = 'active'.ucfirst($type);

return $list ?
Html::$input($this->model, $this->attribute, $this->data, $this->options) :
Html::$input($this->model, $this->attribute, $this->options);
Expand All @@ -230,6 +232,7 @@ protected function getInput($type, $list = false)
$checked = false;
}
}

return $list ?
Html::$input($this->name, $this->value, $this->data, $this->options) :
(($type == 'checkbox' || $type == 'radio') ?
Expand All @@ -243,7 +246,7 @@ protected function getInput($type, $list = false)
* @see http://php.net/manual/en/function.date.php
* @see http://bootstrap-datetimepicker.readthedocs.org/en/release/options.html#format
*
* @param string $format the PHP date format string
* @param string $format the PHP date format string
*
* @return string
*/
Expand Down Expand Up @@ -291,7 +294,7 @@ protected static function convertDateFormat($format)
* Parses and sets plugin date format based on attribute type using [[FormatConverter]]. Currently this method is
* used only within the [[\kartik\date\DatePicker]] and [[\kartik\datetime\DateTimePicker\]] widgets.
*
* @param string $type the attribute type whether date, datetime, or time.
* @param string $type the attribute type whether date, datetime, or time.
*
* @throws InvalidConfigException
*/
Expand All @@ -305,9 +308,10 @@ protected function parseDateFormat($type)
$format = Lib::strncmp($format, 'php:', 4) === 0 ? Lib::substr($format, 4) :
FormatConverter::convertDateIcuToPhp($format, $type);
$this->pluginOptions['format'] = static::convertDateFormat($format);

return;
}
$attrib = $type . 'Format';
$attrib = $type.'Format';
$format = isset(Yii::$app->formatter->$attrib) ? Yii::$app->formatter->$attrib : '';
if (empty($format)) {
throw new InvalidConfigException("Error parsing '{$type}' format.");
Expand Down
2 changes: 1 addition & 1 deletion src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/PluginAssetBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/TranslationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion src/WidgetAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <kartikv2@gmail.com>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2022
* @version 3.0.4
* @version 3.0.5
*/

namespace kartik\base;
Expand Down
Loading

0 comments on commit 5c09512

Please sign in to comment.