Skip to content
Open
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
5 changes: 3 additions & 2 deletions frontend/js/mixins/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ export default {
open: function () {
this.opened = true
},
fieldName: function (id) {
return this.name + '[' + id + ']' // output : nameOfBlock[UniqID][name]
fieldName: function (id, extra = null) {
const fieldName = this.name + '[' + id + ']' // output : nameOfBlock[UniqID][name]
return extra ? fieldName + extra : fieldName
},
repeaterName: function (id) {
return this.name.replace('[', '-').replace(']', '') + '|' + id // nameOfBlock-UniqID|name
Expand Down
9 changes: 9 additions & 0 deletions src/Services/Forms/Fields/Medias.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class Medias extends BaseFormField

protected bool $activeCrop = true;

protected bool $disableTranslate = false;

public static function make(): static
{
$instance = new self(
Expand Down Expand Up @@ -137,4 +139,11 @@ public function hideActiveCrop(bool $hideActiveCrop = true): static

return $this;
}

public function disableTranslate(): static
{
$this->disableTranslate = true;

return $this;
}
}
11 changes: 10 additions & 1 deletion src/View/Components/Fields/Medias.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public function __construct(
public int $widthMin = 0,
public int $heightMin = 0,
public bool $buttonOnTop = false,
public bool $activeCrop = true
public bool $activeCrop = true,
public bool $disableTranslate = false
) {
parent::__construct(
name: $name,
Expand Down Expand Up @@ -59,4 +60,12 @@ public function render(): View
)
);
}

public function getExtraName(): string
{
return config('twill.media_library.translated_form_fields', false)
&& $this->disableTranslate
&& !$this->translated
? '[' . config('app.locale') . ']' : '';
}
}
10 changes: 8 additions & 2 deletions src/View/Components/Fields/TwillFormComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ public function formFieldName(bool $asAttributes = false, ?string $customName =
{
$name = $customName ?? $this->name;
if ($this->renderForBlocks) {
$extra = $this->getExtraName();
if ($asAttributes) {
return "name: fieldName('$name')";
return "name: fieldName('$name', '$extra')";
}

return ":name=\"fieldName('$name')\"";
return ":name=\"fieldName('$name', '$extra')\"";
}

if ($asAttributes) {
Expand All @@ -66,4 +67,9 @@ public function formFieldName(bool $asAttributes = false, ?string $customName =
}

abstract public function render(): View;

public function getExtraName(): string
{
return '';
}
}
4 changes: 3 additions & 1 deletion views/partials/form/_medias.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@

@unless($renderForBlocks)
@push('vuexStore')
@if (isset($form_fields['medias']) && isset($form_fields['medias'][$name]))
@if(config('twill.media_library.translated_form_fields', false) && ($disableTranslate ?? false) && isset($form_fields['medias']) && isset($form_fields['medias'][config('app.locale')]) && isset($form_fields['medias'][config('app.locale')][$name]))
window['{{ config('twill.js_namespace') }}'].STORE.medias.selected["{{ $name }}"] = {!! json_encode($form_fields['medias'][config('app.locale')][$name]) !!}
@elseif(isset($form_fields['medias']) && isset($form_fields['medias'][$name]))
window['{{ config('twill.js_namespace') }}'].STORE.medias.selected["{{ $name }}"] = {!! json_encode($form_fields['medias'][$name]) !!}
@endif
@endpush
Expand Down