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']]); }); }
/** * 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']]); }); }
/** * {@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']]); }); }
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'); }); }
/** * 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']]); }); }
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); } }); }