Last active
February 13, 2022 09:47
-
-
Save drmzio/984c05930fa7060eac8acf8607b636d3 to your computer and use it in GitHub Desktop.
October CMS RainLab.Blog media manager plugin extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<img src="{{ post.metadata.banner_image|media }}"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\BlogBanner; | |
use System\Classes\PluginBase; | |
use Event; | |
/** | |
* Class Plugin | |
* | |
* @package Acme\BlogBanner | |
*/ | |
class Plugin extends PluginBase | |
{ | |
public $require = ['RainLab.Blog']; | |
/** | |
* @inheritdoc | |
*/ | |
public function pluginDetails(): array | |
{ | |
return [ | |
'name' => 'Blog Banner', | |
'description' => 'A RainLab.Blog extension adding banner image via Media Manager to posts.', | |
'author' => 'Acme', | |
'icon' => 'icon-file-image-o', | |
]; | |
} | |
public function register() | |
{ | |
Event::listen('backend.form.extendFields', function (\Backend\Widgets\Form $formWidget) { | |
if (!$formWidget->getController() instanceof \RainLab\Blog\Controllers\Posts) { | |
return; | |
} | |
if (!$formWidget->model instanceof \RainLab\Blog\Models\Post) { | |
return; | |
} | |
$formWidget->addSecondaryTabFields([ | |
'metadata[banner_image]' => [ | |
'tab' => 'rainlab.blog::lang.post.tab_manage', | |
'label' => 'Banner Image', | |
'type' => 'mediafinder', | |
'mode' => 'image' | |
], | |
]); | |
$formWidget->removeField('featured_images'); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment