Skip to content

Commit

Permalink
1.2.5: Indikator.News integration
Browse files Browse the repository at this point in the history
  • Loading branch information
FlusherDock1 committed Nov 28, 2019
1 parent e2b199b commit 92ca8ff
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 34 deletions.
9 changes: 5 additions & 4 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,24 @@ public function pluginDetails()
'description' => 'reazzon.gutenberg::lang.plugin.description',
'author' => 'Nick Khaetsky',
'icon' => 'icon-pencil-square-o',
'homepage' => 'https://github.com/FlusherDock1/Gutenberg'
'homepage' => 'https://github.com/FlusherDock1/Gutenberg'
];
}

/**
* Boot method, called right before the request route.
*
* @return array
* @return array|void
*/
public function boot()
{
Extenders::RainLabBlog();
Extenders::LovataGoodNews();
Extenders::IndikatorNews();

// Coming soon.
// Extenders::StaticPages();
//
//
}

/**
Expand Down
21 changes: 14 additions & 7 deletions behaviors/Gutenbergable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,24 @@ class Gutenbergable extends ModelBehavior
{

/**
* Constructor
* Gutenbergable constructor.
*
* @param $model
*/
public function __construct($model)
{
parent::__construct($model);
$model->morphOne['content'] = [ Content::class,
$model->morphOne['content'] = [
Content::class,
'name' => 'contentable',
'delete' => true
];
}

/**
* Returns the rendered HTML from the Content object
* @return String
*
* @return string
*/
public function renderContent()
{
Expand All @@ -31,7 +35,8 @@ public function renderContent()

/**
* Returns the raw content that came out of Gutenberg
* @return String
*
* @return string
*/
public function getRawContent()
{
Expand All @@ -40,7 +45,8 @@ public function getRawContent()

/**
* Returns the Gutenberg content with some initial rendering done to it
* @return String
*
* @return string
*/
public function getRenderedContent()
{
Expand All @@ -49,8 +55,9 @@ public function getRenderedContent()

/**
* Sets the content object using the raw editor content
* @param String $content
* @param boolean $save - Calls .save() on the Content object if true
*
* @param $content
* @param bool $save Calls .save() on the Content object if true
*/
public function setContent($content, $save = false)
{
Expand Down
48 changes: 43 additions & 5 deletions classes/Extenders.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public static function RainLabBlog()
}
});

// Repalcing original content_html attribute.
// Replacing original content_html attribute.
\RainLab\Blog\Models\Post::extend(function ($model) {
$model->bindEvent('model.getAttribute', function ($attribute, $value) use ($model) {
if ($attribute == 'content_html') {
return "<div class='gutenberg__content wp-embed-responsive'>" .
BlockHelper::renderBlocks(EmbedHelper::renderEmbeds($value))
. "</div>";
. "</div>";
}
});
});
Expand Down Expand Up @@ -76,12 +76,50 @@ public static function LovataGoodNews()
}
});

// Repalcing original content attribute.
// Replacing original content attribute.
\Lovata\GoodNews\Classes\Item\ArticleItem::extend(function ($elementItem) {
$elementItem->addDynamicMethod('getContentAttribute', function () use ($elementItem) {
return "<div class='gutenberg__content wp-embed-responsive'>" .
BlockHelper::renderBlocks(EmbedHelper::renderEmbeds($elementItem->getAttribute('content')))
. "</div>";
. "</div>";
});
});
}
}

public static function IndikatorNews()
{
if (Settings::get('integration_indikator_news', false) &&
PluginManager::instance()->hasPlugin('Indikator.News')) {

Event::listen('backend.form.extendFields', function ($widget) {

// Only for Indikator.News Posts controller
if (!$widget->getController() instanceof \Indikator\News\Controllers\Posts) {
return;
}

// Only for Indikator.News Post model
if (!$widget->model instanceof \Indikator\News\Models\Posts) {
return;
}

// Finding content field and changing it's type regardless whatever it already is.
foreach ($widget->getFields() as $field) {
if ($field->fieldName === 'content') {
$field->config['type'] = 'gutenberg';
$field->config['widget'] = 'ReaZzon\Gutenberg\FormWidgets\Gutenberg';
$field->config['minheight'] = 500;
}
}
});

// Replacing original content_html attribute.
\Indikator\News\Models\Posts::extend(function ($model) {
$model->addDynamicMethod('getContentRenderAttribute', function () use ($model) {
return "<div class='gutenberg__content wp-embed-responsive'>" .
BlockHelper::renderBlocks(EmbedHelper::renderEmbeds($model->getAttribute('content')))
. "</div>";
});
});
}
Expand All @@ -96,7 +134,7 @@ public static function LovataGoodNews()
* - Full work on master tab
*
* TODO:
* - Reload of formwidget everytime tab is changed. Gutenberg.js can't have mulitple instances at one page.
* - I'm helpless here, need to wait for some updates from https://github.com/front/g-editor
*
*/
public static function StaticPages()
Expand Down
19 changes: 12 additions & 7 deletions lang/en/lang.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
return [
'plugin' => [
'name' => 'Gutenberg',
Expand All @@ -13,21 +13,26 @@
'tab' => [
'integrations' => [
'name' => 'Integrations',
'warning' => [
'title' => 'Warning!',
'text' => 'If you have posts that are created via another WISYWIG,
Gutenberg will not work with it! And all your posts will look broken.'
],
'static_pages' => [
'name' => 'RainLab.StaticPages Integration',
'comment' => 'Coming soon.'
],
'blog' => [
'name' => 'RainLab.Blog Integration',
'comment' => 'Switching default visual editor in post editing form to Gutenberg.
Attention! If you have posts that are created via another WISYWIG, Gutenberg will not work with it! And all your posts will look broken.
I\'m not recommending switching visual editor on already working web-site.'
'comment' => 'Switching default visual editor in `content` field to Gutenberg.'
],
'good_news' => [
'name' => 'Lovata.GoodNews Integration',
'comment' => 'Switching default visual editor in post editing form to Gutenberg.
Attention! If you have posts that are created via another WISYWIG, Gutenberg will not work with it! And all your posts will look broken.
I\'m not recommending switching visual editor on already working web-site.'
'comment' => 'Switching default visual editor in `content` field to Gutenberg.'
],
'indikator_news' => [
'name' => 'Indikator.News Integration',
'comment' => 'Switching default visual editor in `content` field to Gutenberg. Use `content_render` attribute to get rendered gutenberg content.'
],
'section_standard' => [
'name' => 'Standard plugins'
Expand Down
19 changes: 12 additions & 7 deletions lang/ru/lang.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php
return [
'plugin' => [
'name' => 'Gutenberg',
Expand All @@ -13,21 +13,26 @@
'tab' => [
'integrations' => [
'name' => 'Интеграции',
'warning' => [
'title' => 'Важно!',
'text' => 'Не рекомендуется заменять визуальный редактор у плагинов, где уже существует контент,
так как Gutenberg вероятнее всего не сможет работать с ними.'
],
'static_pages' => [
'name' => 'RainLab.StaticPages интеграция',
'comment' => 'Скоро.',
],
'blog' => [
'name' => 'RainLab.Blog интеграция',
'comment' => 'Заменяет визуальный редактор, который используется в статьях на Gutenberg.
Важно! Все уже созданые посты, которые были созданны не через Gutenberg НЕ будут работать.
Рекомендую вам не использовать замену визуального редактора в уже работающем проекте.'
'comment' => 'Замена стандартного визуального редактора у поля `content` на Gutenberg.'
],
'good_news' => [
'name' => 'Lovata.GoodNews интеграция',
'comment' => 'Заменяет визуальный редактор, который используется в статьях на Gutenberg.
Важно! Все уже созданые посты, которые были созданны не через Gutenberg НЕ будут работать.
Рекомендую вам не использовать замену визуального редактора в уже работающем проекте.'
'comment' => 'Замена стандартного визуального редактора у поля `content` на Gutenberg.'
],
'indikator_news' => [
'name' => 'Indikator.News интеграция',
'comment' => 'Замена стандартного визуального редактора у поля `content` на Gutenberg.'
],
'section_standard' => [
'name' => 'Стандартные плагины'
Expand Down
15 changes: 13 additions & 2 deletions models/settings/fields.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

tabs:
fields:
warning:
type: partial
tab: 'reazzon.gutenberg::lang.settings.tab.integrations.name'
path: $/reazzon/gutenberg/models/settings/warning.htm

section_standard:
label: 'reazzon.gutenberg::lang.settings.tab.integrations.section_standard.name'
tab: 'reazzon.gutenberg::lang.settings.tab.integrations.name'
Expand All @@ -23,7 +28,6 @@ tabs:
type: switch
span: left


integration_good_news:
label: 'reazzon.gutenberg::lang.settings.tab.integrations.good_news.name'
tab: 'reazzon.gutenberg::lang.settings.tab.integrations.name'
Expand All @@ -38,4 +42,11 @@ tabs:
type: switch
span: left
disabled: true
readOnly: true
readOnly: true

integration_indikator_news:
label: 'reazzon.gutenberg::lang.settings.tab.integrations.indikator_news.name'
tab: 'reazzon.gutenberg::lang.settings.tab.integrations.name'
comment: 'reazzon.gutenberg::lang.settings.tab.integrations.indikator_news.comment'
type: switch
span: right
7 changes: 7 additions & 0 deletions models/settings/warning.htm
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="callout in callout-warning">
<div class="header">
<i class="icon-warning"></i>
<h3><?= e(trans('reazzon.gutenberg::lang.settings.tab.integrations.warning.title')) ?></h3>
<p><?= e(trans('reazzon.gutenberg::lang.settings.tab.integrations.warning.text')) ?></p>
</div>
</div>
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Gutenberg for OctoberCMS
**PLUGIN CURRENTLY IN BETA.**

**RAINLAB.BLOG AND LOVATA.GOODNEWS INTEGRATION READY**

[This text in russian](https://octoclub.ru/d/70-gutenberg-%D0%B2%D0%B8%D0%B7%D1%83%D0%B0%D0%BB%D1%8C%D0%BD%D1%8B%D0%B9-dragdrop-%D1%80%D0%B5%D0%B4%D0%B0%D0%BA%D1%82%D0%BE%D1%80-%D0%B1%D0%BB%D0%BE%D0%BA%D0%BE%D0%B2-%D0%B4%D0%BB%D1%8F-%D0%BF%D0%BB%D0%B0%D0%B3%D0%B8%D0%BD%D0%BE%D0%B2)

Gutenberg is a rich-text visual editor from WordPress, with the features of bulidng content with blocks. With Gutenberg, you can create truly unique content for your website by simply dragging and dropping blocks.
Expand All @@ -16,6 +14,7 @@ Integration of Laraberg by [VanOns\Laraberg](https://github.com/VanOns/laraberg)
**Working integrations:**
- [RainLab.Blog](https://octobercms.com/plugin/rainlab-blog)
- [Lovata.GoodNews](https://octobercms.com/plugin/lovata-goodnews)
- [Indikator.News](https://octobercms.com/plugin/indikator-news)

**Coming Soon integrations:**
- [RainLab.StaticPages](https://octobercms.com/plugin/rainlab-pages)
Expand Down Expand Up @@ -57,6 +56,7 @@ Integration of Laraberg by [VanOns\Laraberg](https://github.com/VanOns/laraberg)
- ~~RainLab.Blog integration~~ **DONE in 1.1.0 update**
- ~~Lovata.GoodNews integration~~ **DONE in 1.1.2 update**
- ~~Migration to release version of Laraberg~~ **DONE in 1.2.0 update**
- ~~Indikator.News integration~~ **DONE in 1.2.5 update**
- RainLab.StaticPages integration

**Later work:**
Expand Down
1 change: 1 addition & 0 deletions updates/version.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
1.2.5: Indikator.News integration
1.2.0: !!! Migration to Larabeg 1.0.0-rc.1.
1.1.25: Sticky sidebar
1.1.2: Lovata.GoodNews integration
Expand Down

0 comments on commit 92ca8ff

Please sign in to comment.