Пример #1
0
 public function boot()
 {
     Post::extend(function ($model) {
         $model->bindEvent('model.afterFetch', function () use($model) {
             $model->view += 1;
             $model->save();
         });
     });
 }
Пример #2
0
 public function boot()
 {
     PostModel::extend(function ($model) {
         $model->attachMany['featured_files'] = ['System\\Models\\File', 'order' => 'sort_order', 'delete' => true];
     });
     PostsController::extendFormFields(function ($form, $model) {
         if (!$model instanceof PostModel) {
             return;
         }
         $form->addSecondaryTabFields(['featured_files' => ['label' => 'hambern.featuredfiles::lang.plugin.name', 'tab' => 'rainlab.blog::lang.post.tab_manage', 'type' => 'fileupload', 'mode' => 'file']]);
     });
 }
Пример #3
0
 /**
  * Add tags field to blog posts
  */
 public function boot()
 {
     // Extend the posts model to establish the new tags relationship
     PostModel::extend(function ($model) {
         $model->belongsToMany['tags'] = ['Bedard\\BlogTags\\Models\\Tag', 'table' => 'bedard_blogtags_post_tag', 'order' => 'name'];
     });
     // Extend the controller and add the tags field
     PostsController::extendFormFields(function ($form, $model, $context) {
         if (!$model instanceof PostModel) {
             return;
         }
         $form->addSecondaryTabFields(['tags' => ['label' => 'Tags', 'tab' => 'rainlab.blog::lang.post.tab_categories', 'type' => 'tagbox']]);
     });
 }
Пример #4
0
 /**
  * {@inheritdoc}
  */
 public function boot()
 {
     // Extend attachment file to the post relation
     RainLabPost::extend(function (\October\Rain\Database\Model $model) {
         $model->attachMany['attachments'] = [\System\Models\File::class];
     });
     RainLabPosts::extendFormFields(function (\Backend\Widgets\Form $form, $model, $context) {
         if (!$model instanceof RainLabPost) {
             return;
         }
         // Add attachments to the "Manage" tab
         $form->addSecondaryTabFields(['attachments' => ['mode' => 'file', 'label' => 'reizinixc.blogattachment::lang.post.attachments', 'tab' => 'rainlab.blog::lang.post.tab_manage', 'type' => 'fileupload']]);
     });
 }
Пример #5
0
 public function boot()
 {
     // extend post model
     PostModel::extend(function ($model) {
         // add a hasone relationship with the featuredvideo model
         $model->hasOne['featuredvideo'] = ['Simplicitylab\\BlogFeaturedVideo\\Models\\FeaturedVideo'];
     });
     // extend form fields
     PostsController::extendFormFields(function ($widget, $model, $context) {
         if ($context != 'update') {
             return;
         }
         if (!FeaturedVideo::getFromPost($model)) {
             return;
         }
         // add featured video textarea
         $widget->addFields(['featuredvideo[iframe_content]' => ['label' => 'simplicitylab.blogfeaturedvideo::lang.backend.featuredvideo', 'tab' => 'rainlab.blog::lang.post.tab_manage', 'type' => 'textarea', 'size' => 'small', 'comment' => 'simplicitylab.blogfeaturedvideo::lang.backend.description']], 'secondary');
     });
 }
Пример #6
0
 /**
  * Extend rainlab.blog plugin
  *
  * @return void
  */
 public function boot()
 {
     /**
      * create relationship
      */
     PostModel::extend(function ($model) {
         $model->belongsToMany['tags'] = ['Rahman\\BlogTags\\Models\\Tag', 'table' => 'rahman_blogtags_posts_tags'];
     });
     /**
      * extend Rainlab\Blog\Controllers\Post
      * add tag form widget
      */
     PostsController::extendFormFields(function ($widget, $model, $context) {
         if (!$model instanceof \Rainlab\Blog\Models\Post) {
             return;
         }
         $widget->addSecondaryTabFields(['tags' => ['Label' => 'Tags box', 'type' => 'Rahman\\BlogTags\\FormWidgets\\Tagbox', 'tab' => 'Tags']]);
     });
 }
Пример #7
0
 public function boot()
 {
     // Extend the navigation
     Event::listen('backend.menu.extendItems', function ($manager) {
         $manager->addSideMenuItems('RainLab.Blog', 'blog', ['tags' => ['label' => 'Tags', 'icon' => 'icon-tags', 'code' => 'tags', 'owner' => 'RainLab.Blog', 'url' => Backend::url('bedard/blogtags/tags')]]);
     });
     // Extend the controller
     PostsController::extendFormFields(function ($form, $model, $context) {
         if (!$model instanceof PostModel) {
             return;
         }
         $form->addSecondaryTabFields(['tagbox' => ['label' => 'Tags', 'tab' => 'rainlab.blog::lang.post.tab_categories', 'type' => 'owl-tagbox', 'slugify' => true]]);
     });
     // Extend the model
     PostModel::extend(function ($model) {
         // Relationship
         $model->belongsToMany['tags'] = ['Bedard\\BlogTags\\Models\\Tag', 'table' => 'bedard_blogtags_post_tag', 'order' => 'name'];
         // getTagboxAttribute()
         $model->addDynamicMethod('getTagboxAttribute', function () use($model) {
             return $model->tags()->lists('name');
         });
         // setTagboxAttribute()
         $model->addDynamicMethod('setTagboxAttribute', function ($tags) use($model) {
             $this->tags = $tags;
         });
     });
     // Attach tags to model
     PostModel::saved(function ($model) {
         if ($this->tags) {
             $ids = [];
             foreach ($this->tags as $name) {
                 $create = Tag::firstOrCreate(['name' => $name]);
                 $ids[] = $create->id;
             }
             $model->tags()->sync($ids);
         }
     });
 }
Пример #8
0
 public function fixValidations()
 {
     CmsPage::extend(function ($page) {
         $page->rules['url'] = ['required', 'regex:/^\\/[۰-۹آا-یa-z0-9\\/\\:_\\-\\*\\[\\]\\+\\?\\|\\.\\^\\\\$]*$/iu'];
     });
     //edit blog url validation rule
     if (PluginManager::instance()->exists('rainlab.blog')) {
         \RainLab\Blog\Models\Post::extend(function ($post) {
             $post->rules['slug'] = ['required', 'regex:/^[۰-۹آا-یa-z0-9\\/\\:_\\-\\*\\[\\]\\+\\?\\|]*$/iu', 'unique:rainlab_blog_posts'];
         });
     }
     //extending rainlab.pages
     if (PluginManager::instance()->exists('rainlab.pages')) {
         //edit rainlab page url validation rule
         \RainLab\Pages\Classes\Page::extend(function ($page) {
             $page->rules['url'] = ['required', 'regex:/^\\/[۰-۹آا-یa-z0-9\\/_\\-]*$/iu', 'uniqueUrl'];
         });
         //edit rainlab page filename in crating
         \RainLab\Pages\Classes\Page::creating(function ($page) {
             $page->fileName = \Str::ascii($page->fileName);
         }, -1);
     }
 }