Наследование: extends Backend\Classes\Controller
Пример #1
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']]);
     });
 }
Пример #2
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']]);
     });
 }
Пример #3
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']]);
     });
 }
Пример #4
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');
     });
 }
Пример #5
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']]);
     });
 }
Пример #6
0
 /**
  * Register method, called when the plugin is first registered.
  */
 public function register()
 {
     PostsController::extend(function ($controller) {
         $controller->addJs('/plugins/rainlab/blogvideo/assets/js/blog-video.js');
         $controller->addCss('/plugins/rainlab/blogvideo/assets/css/blog-video.css');
     });
     /*
      * Register the video tag processing callback
      */
     TagProcessor::instance()->registerCallback(function ($input, $preview) {
         if (!$preview) {
             return $input;
         }
         $popup = file_get_contents(__DIR__ . '/partials/popup.htm');
         return preg_replace('|\\<img alt="([0-9]+)" src="video" \\/>|m', '<span class="video-placeholder" data-index="$1">
                 <a href="#">Click to embed a video...</a>
                 ' . $popup . '
             </span>', $input);
     });
 }
Пример #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);
         }
     });
 }