diff --git a/I18nContent.php b/I18nContent.php
new file mode 100644
index 0000000..1419539
--- /dev/null
+++ b/I18nContent.php
@@ -0,0 +1,53 @@
+
+ * @package centigen\i18ncontent
+ */
+class I18nContent extends Component
+{
+
+ /**
+ * Identity User class name
+ *
+ * @var string
+ */
+ public $userClass = null;
+
+ /**
+ * In texts which may contain or other media object tags (texts which come from WYSIWYG editors)
+ * `$mediaUrlPrefix` strings are replaced with `$mediaUrlReplacement` string when calling `Html::encodeMediaItemUrls`
+ * and vice versa when calling `Html::decodeMediaItemUrls`
+ *
+ * @author Zura Sekhniashvili
+ * @var string
+ */
+ public $mediaUrlPrefix = null;
+
+ /**
+ * See `$mediaUrlPrefix`
+ *
+ * @author Zura Sekhniashvili
+ * @var string
+ */
+ public $mediaUrlReplacement = '{{media_item_url_prefix}}';
+
+ public function init()
+ {
+ parent::init();
+ if (!$this->mediaUrlPrefix){
+ $this->mediaUrlPrefix = Url::base(true);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Module.php b/Module.php
index f85d1a8..1a0bec3 100644
--- a/Module.php
+++ b/Module.php
@@ -10,12 +10,6 @@
*/
class Module extends \yii\base\Module
{
- /**
- * Identity User class name
- *
- * @var string
- */
- public $userClass = null;
/**
* Default layout which will be used in all actions
@@ -24,32 +18,6 @@ class Module extends \yii\base\Module
*/
public $defaultLayout = null;
- /**
- * In texts which may contain or other media object tags (texts which come from WYSIWYG editors)
- * `$mediaUrlPrefix` strings are replaced with `$mediaUrlReplacement` string when calling `Html::encodeMediaItemUrls`
- * and vice versa when calling `Html::decodeMediaItemUrls`
- *
- * @author Zura Sekhniashvili
- * @var string
- */
- public $mediaUrlPrefix = null;
-
- /**
- * See `$mediaUrlPrefix`
- *
- * @author Zura Sekhniashvili
- * @var string
- */
- public $mediaUrlReplacement = '{{media_item_url_prefix}}';
-
- public function __construct($id, $parent = null, $config = [])
- {
- parent::__construct($id, $parent, $config);
- if (!$this->mediaUrlPrefix){
- $this->mediaUrlPrefix = Url::base(true);
- }
- }
-
public function missingTranslation()
{
// @todo
diff --git a/README.md b/README.md
index 62cc1ac..e381d86 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-yii2-i18ncontent
+i18n content module for Yii2 framework
================
yii2-i18ncontent is yii2 module for creating several types of contents in different languages.
@@ -12,7 +12,7 @@ It support creating the following contents:
### Installation
- 1. Run `composer require omcrn/yii2-i18ncontent` or add `"omcrn/yii2-i18ncontent": "^1.0.0"` in your projects `composer.json`.
+ 1. Run `composer require omcrn/yii2-i18ncontent` or add `"omcrn/yii2-i18ncontent": "~2.0.0"` in your projects `composer.json`.
2. Make sure you have `user` table in your database with primary key `id`.
3. Run migrations to create tables by `php console/yii migrate --migrationPath=@yii/i18n/migrations` from projects root directory
4. Run migrations to create tables by `php console/yii migrate --migrationPath=@vendor/omcrn/yii2-i18ncontent/migrations` from projects root directory
@@ -24,13 +24,9 @@ Add the following code in projects configuration file under `modules` section
```php
'i18ncontent' => [
'class' => 'centigen\i18ncontent\Module',
- 'userClass' => 'common\models\User', //User model class. If you do not have user model, generate it from user table. Make sure this models extends \yii\db\ActiveRecord class
'defaultLayout' => '/admin', //Default layout which will be used for rendering i18ncontent pages
- 'mediaUrlPrefix' => null, //In texts which may contain or other media object tags (texts which come from WYSIWYG editors)
- // `$mediaUrlPrefix` strings are replaced with `$mediaUrlReplacement` string when calling `Html::encodeMediaItemUrls`
- // and vice versa when calling `Html::decodeMediaItemUrls`
- 'mediaUrlReplacement' => '{{media_item_url_prefix}}' //See `$mediaUrlPrefix`
],
+
```
Add the following code in project's configuration file under `components` section
@@ -48,6 +44,14 @@ Add the following code in project's configuration file under `components` sectio
'formatter' => [
'class' => 'centigen\base\i18n\Formatter'
],
+'i18ncontent' => [
+ 'class' => 'centigen\i18ncontent\I18nContent',
+ 'userClass' => 'common\models\User', //User model class. If you do not have user model, generate it from user table. Make sure this models extends \yii\db\ActiveRecord class
+ 'mediaUrlPrefix' => null, //In texts which may contain or other media object tags (texts which come from WYSIWYG editors)
+ // `$mediaUrlPrefix` strings are replaced with `$mediaUrlReplacement` string when calling `Html::encodeMediaItemUrls`
+ // and vice versa when calling `Html::decodeMediaItemUrls`
+ 'mediaUrlReplacement' => '{{media_item_url_prefix}}' //See `$mediaUrlPrefix`
+],
```
Add `availableLocales` array to application configuration `params` array.
diff --git a/helpers/Html.php b/helpers/Html.php
index 1008be6..1af45ac 100644
--- a/helpers/Html.php
+++ b/helpers/Html.php
@@ -32,8 +32,8 @@ public static function encodeMediaItemUrls($text)
if (!$text){
return $text;
}
- $module = Yii::$app->getModule('i18ncontent');
- return str_replace($module->mediaUrlPrefix, $module->mediaUrlReplacement, $text);
+ $component = Yii::$app->i18ncontent;
+ return str_replace($component->mediaUrlPrefix, $component->mediaUrlReplacement, $text);
}
/**
@@ -48,11 +48,8 @@ public static function decodeMediaItemUrls($text)
if (!$text){
return $text;
}
- /**
- * @var $module Module
- */
- $module = Yii::$app->getModule('i18ncontent');
- return str_replace($module->mediaUrlReplacement, $module->mediaUrlPrefix, $text);
+ $component = Yii::$app->i18ncontent;
+ return str_replace($component->mediaUrlReplacement, $component->mediaUrlPrefix, $text);
}
/**
diff --git a/models/Article.php b/models/Article.php
index fcaef4b..3c9ca39 100644
--- a/models/Article.php
+++ b/models/Article.php
@@ -175,7 +175,7 @@ public function attributeLabels()
*/
public function getAuthor()
{
- return $this->hasOne(Yii::$app->getModule('i18ncontent')->userClass, ['id' => 'author_id']);
+ return $this->hasOne(Yii::$app->i18ncontent->userClass, ['id' => 'author_id']);
}
/**
@@ -183,7 +183,7 @@ public function getAuthor()
*/
public function getUpdater()
{
- return $this->hasOne(Yii::$app->getModule('i18ncontent')->userClass, ['id' => 'updater_id']);
+ return $this->hasOne(Yii::$app->i18ncontent->userClass, ['id' => 'updater_id']);
}
/**
diff --git a/models/Page.php b/models/Page.php
index 0eb7b5a..0f0a8b6 100644
--- a/models/Page.php
+++ b/models/Page.php
@@ -117,7 +117,7 @@ public function attributeLabels()
*/
public function getAuthor()
{
- return $this->hasOne(Yii::$app->getModule('i18ncontent')->userClass, ['id' => 'author_id']);
+ return $this->hasOne(Yii::$app->i18ncontent->userClass, ['id' => 'author_id']);
}
/**
@@ -125,7 +125,7 @@ public function getAuthor()
*/
public function getUpdater()
{
- return $this->hasOne(Yii::$app->getModule('i18ncontent')->userClass, ['id' => 'updater_id']);
+ return $this->hasOne(Yii::$app->i18ncontent->userClass, ['id' => 'updater_id']);
}
/**