Skip to content

Commit

Permalink
Merge pull request #646 from rainlab/editor
Browse files Browse the repository at this point in the history
Adds support for new Editor
  • Loading branch information
daftspunk authored May 31, 2021
2 parents 898159b + 1228cf4 commit 74b880b
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
10 changes: 8 additions & 2 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function register()
}, -1);

/*
* Handle translated page URLs
*/
* Handle translated page URLs
*/
Page::extend(function($model) {
if (!$model->propertyExists('translatable')) {
$model->addDynamicProperty('translatable', []);
Expand All @@ -80,6 +80,12 @@ public function register()
Event::listen('cms.theme.createThemeDataModel', function($attributes) {
return new \RainLab\Translate\Models\MLThemeData($attributes);
});

Event::listen('cms.template.getTemplateToolbarSettingsButtons', function($extension, $dataHolder) {
if ($dataHolder->templateType === 'page') {
EventRegistry::instance()->extendEditorPageToolbar($dataHolder);
}
});
}

/*
Expand Down
2 changes: 0 additions & 2 deletions behaviors/TranslatablePageUrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
use App;
use RainLab\Translate\Classes\Translator;
use October\Rain\Extension\ExtensionBase;
use ApplicationException;
use Exception;

/**
* Translatable page URL model extension
Expand Down
66 changes: 63 additions & 3 deletions classes/EventRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,66 @@ class EventRegistry
{
use \October\Rain\Support\Traits\Singleton;

//
// Editor
//

public function extendEditorPageToolbar($dataHolder)
{
$locales = LocaleModel::listAvailable();
$defaultLocale = LocaleModel::getDefault()->code ?? null;

$properties = [];
foreach ($locales as $locale => $label) {
if ($locale == $defaultLocale) {
continue;
}

$properties[] = [
'property' => 'localeUrl.'.$locale,
'title' => 'cms::lang.editor.url',
'tab' => $label,
'type' => 'string',
];

$properties[] = [
'property' => 'localeTitle.'.$locale,
'title' => 'cms::lang.editor.title',
'tab' => $label,
'type' => 'string',
];

$properties[] = [
'property' => 'localeDescription.'.$locale,
'title' => 'cms::lang.editor.description',
'tab' => $label,
'type' => 'text',
];

$properties[] = [
'property' => 'localeMeta_title.'.$locale,
'title' => 'cms::lang.editor.meta_title',
'tab' => $label,
'type' => 'string',
];

$properties[] = [
'property' => 'localeMeta_description.'.$locale,
'title' => 'cms::lang.editor.meta_description',
'tab' => $label,
'type' => 'text',
];
}

$dataHolder->buttons[] = [
'button' => 'rainlab.translate::lang.plugin.name',
'icon' => 'octo-icon-globe',
'popupTitle' => 'Translate Page Properties',
'useViewBag' => true,
'properties' => $properties
];
}

//
// Utility
//
Expand Down Expand Up @@ -53,16 +113,16 @@ public function registerMenuItemTranslation($widget)
$defaultLocale = LocaleModel::getDefault();
$availableLocales = LocaleModel::listAvailable();
$fieldsToTranslate = ['title', 'url'];

// Replace specified fields with multilingual versions
foreach ($fieldsToTranslate as $fieldName) {
$widget->fields[$fieldName]['type'] = 'mltext';

foreach ($availableLocales as $code => $locale) {
if (!$defaultLocale || $defaultLocale->code === $code) {
continue;
}

// Add data locker fields for the different locales under the `viewBag[locale]` property
$widget->fields["viewBag[locale][$code][$fieldName]"] = [
'cssClass' => 'hidden',
Expand Down
2 changes: 1 addition & 1 deletion controllers/locales/_update_form.htm
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ <h4 class="modal-title"><?= e(trans('rainlab.translate::lang.locale.update_title

<button
type="button"
class="oc-icon-trash-o btn-icon danger pull-left"
class="oc-icon-trash-o btn-icon danger pull-right"
data-request="onDelete"
data-popup-load-indicator
data-request-confirm="<?= e(trans('backend::lang.form.confirm_delete')) ?>">
Expand Down

0 comments on commit 74b880b

Please sign in to comment.