Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic implementation that changes the Blocks formwidget to extend MLR… #34

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blocks/button.block
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fields:
label:
label: winter.blocks::lang.fields.label
span: full
type: text
type: mltext
tabs:
icons:
winter.blocks::lang.fields.actions: 'icon-arrow-pointer'
Expand Down
4 changes: 2 additions & 2 deletions blocks/image.block
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ icon: icon-picture-o
tags: ["pages"]
fields:
image:
type: mediafinder
type: mlmediafinder
span: full
mode: image
alt_text:
label: winter.blocks::lang.blocks.image.alt_text
span: full
type: text
type: mltext
config:
size:
label: winter.blocks::lang.fields.size
Expand Down
2 changes: 1 addition & 1 deletion blocks/plaintext.block
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fields:
content:
placeholder: winter.blocks::lang.fields.content
span: full
type: textarea
type: mltextarea
size: small
==
<p>
Expand Down
2 changes: 1 addition & 1 deletion blocks/richtext.block
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fields:
content:
placeholder: winter.blocks::lang.fields.content
span: full
type: richeditor
type: mlricheditor
==
<div class="prose lg:prose-xl">
{{ content | raw }}
Expand Down
2 changes: 1 addition & 1 deletion blocks/title.block
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fields:
content:
placeholder: winter.blocks::lang.blocks.title.name
span: full
type: text
type: mltext
config:
size:
label: winter.blocks::lang.fields.size
Expand Down
2 changes: 1 addition & 1 deletion blocks/video.block
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fields:
video:
label: winter.blocks::lang.blocks.video.name
span: full
type: mediafinder
type: mlmediafinder
mode: video
==
{% if video %}
Expand Down
2 changes: 1 addition & 1 deletion blocks/vimeo.block
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tags: ["pages"]
fields:
vimeo_id:
label: winter.blocks::lang.blocks.vimeo.vimeo_id
type: text
type: mltext
==
{% if vimeo_id %}
<iframe
Expand Down
2 changes: 1 addition & 1 deletion blocks/youtube.block
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tags: ["pages"]
fields:
youtube_id:
label: winter.blocks::lang.blocks.youtube.youtube_id
type: text
type: mltext
==
{% if youtube_id %}
<iframe
Expand Down
47 changes: 45 additions & 2 deletions formwidgets/Blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace Winter\Blocks\FormWidgets;

use Backend\FormWidgets\Repeater;
use Lang;
use Winter\Blocks\Classes\BlockManager;
use Winter\Storm\Exception\ApplicationException;
use Winter\Translate\FormWidgets\MLRepeater;
use Winter\Translate\Models\Locale;

/**
* "Blocks" FormWidget for defining and managing multiple blocks
*/
class Blocks extends Repeater
class Blocks extends MLRepeater
{
/**
* List of blocks to ignore for this specific instance
Expand Down Expand Up @@ -370,4 +371,46 @@ protected function getBestInspectorField(string $type): string

return $type;
}

/**
* Returns an array of translated values for this field
* @return array
*/
public function getLocaleSaveData()
{
$values = [];
$data = post('RLTranslate');

if (!is_array($data)) {
if ($this->translationMode === 'fields') {
foreach (Locale::listEnabled() as $code => $name) {
// force translations removal from db
$values[$code] = [];
}
}
return $values;
}

$fieldName = $this->getLongFieldName();
$isJson = $this->isLocaleFieldJsonable();

foreach ($data as $locale => $_data) {
$i = 0;
$content = array_get($_data, $fieldName);
if (is_array($content)) {
foreach ($content as $index => $value) {
// we reindex to fix item reordering index issues
// This will add the _group & _config data with the localized content
$values[$locale][$i++] = array_replace_recursive(
json_decode(json_encode($this->formWidgets[$index]->data), true),
$value
);
}
} else {
$values[$locale] = $isJson && is_string($content) ? json_decode($content, true) : $content;
}
}

return $values;
}
}