Example #1
0
 /** @inheritdoc */
 public function init()
 {
     parent::init();
     if ($this->item instanceof Category) {
         $this->id = $this->item->id;
         $this->setAttributes($this->item->getAttributes());
         $this->setIsNewRecord($this->item->getIsNewRecord());
     }
 }
Example #2
0
 /** @inheritdoc */
 public function bootstrap($app)
 {
     /** @var Module $module */
     /** @var \yii\db\ActiveRecord $modelName */
     if ($app->hasModule('content') && ($module = $app->getModule('content')) instanceof Module) {
         Yii::$container->setSingleton(ContentFinder::className(), ['categoryQuery' => \jarrus90\Content\Models\Category::find(), 'pageQuery' => \jarrus90\Content\Models\Page::find(), 'blockQuery' => \jarrus90\Content\Models\Block::find()]);
         if (!isset($app->get('i18n')->translations['content*'])) {
             $app->get('i18n')->translations['content*'] = ['class' => PhpMessageSource::className(), 'basePath' => __DIR__ . '/messages', 'sourceLanguage' => 'en-US'];
         }
         if (!$app instanceof ConsoleApplication) {
             $module->controllerNamespace = 'jarrus90\\Content\\Controllers';
             $configUrlRule = ['prefix' => $module->urlPrefix, 'rules' => $module->urlRules];
             if ($module->urlPrefix != 'content') {
                 $configUrlRule['routePrefix'] = 'content';
             }
             $configUrlRule['class'] = 'yii\\web\\GroupUrlRule';
             $rule = Yii::createObject($configUrlRule);
             $app->urlManager->addRules([$rule], false);
             $app->params['admin']['menu']['content'] = function () use($module) {
                 return $module->getAdminMenu();
             };
         } else {
             if (empty($app->controllerMap['migrate'])) {
                 $app->controllerMap['migrate']['class'] = 'yii\\console\\controllers\\MigrateController';
             }
             $app->controllerMap['migrate']['migrationNamespaces'][] = 'jarrus90\\Content\\migrations';
         }
     }
 }
Example #3
0
 /**
  * Validation rules
  * @return array
  */
 public function rules()
 {
     return ['required' => [['key', 'title', 'content', 'lang_code'], 'required', 'on' => ['create', 'update']], 'keyValid' => ['key', 'validateKeyCodePair', 'on' => ['create', 'update']], 'langExists' => ['lang_code', 'exist', 'targetClass' => Language::className(), 'targetAttribute' => 'code'], 'safeSearch' => [['key', 'title', 'lang_code'], 'safe', 'on' => ['search']], 'categoryExists' => ['category_key', 'exist', 'targetClass' => Category::className(), 'targetAttribute' => 'key'], 'metaSafe' => [['meta_keywords', 'meta_description'], 'safe', 'on' => ['create', 'update']]];
 }