Skip to content

Commit 3103725

Browse files
committed
added new form field property and method to disable twill.media_library.translated_form_fields
1 parent ce0fbf1 commit 3103725

File tree

5 files changed

+33
-6
lines changed

5 files changed

+33
-6
lines changed

Diff for: frontend/js/mixins/block.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ export default {
1818
open: function () {
1919
this.opened = true
2020
},
21-
fieldName: function (id) {
22-
return this.name + '[' + id + ']' // output : nameOfBlock[UniqID][name]
21+
fieldName: function (id, extra = null) {
22+
const fieldName = this.name + '[' + id + ']' // output : nameOfBlock[UniqID][name]
23+
return extra ? fieldName + extra : fieldName
2324
},
2425
repeaterName: function (id) {
2526
return this.name.replace('[', '-').replace(']', '') + '|' + id // nameOfBlock-UniqID|name

Diff for: src/Services/Forms/Fields/Medias.php

+9
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Medias extends BaseFormField
3232

3333
protected bool $activeCrop = true;
3434

35+
protected bool $disableTranslate = false;
36+
3537
public static function make(): static
3638
{
3739
$instance = new self(
@@ -137,4 +139,11 @@ public function hideActiveCrop(bool $hideActiveCrop = true): static
137139

138140
return $this;
139141
}
142+
143+
public function disableTranslate(): static
144+
{
145+
$this->disableTranslate = true;
146+
147+
return $this;
148+
}
140149
}

Diff for: src/View/Components/Fields/Medias.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ public function __construct(
3030
public int $widthMin = 0,
3131
public int $heightMin = 0,
3232
public bool $buttonOnTop = false,
33-
public bool $activeCrop = true
33+
public bool $activeCrop = true,
34+
public bool $disableTranslate = false
3435
) {
3536
parent::__construct(
3637
name: $name,
@@ -59,4 +60,12 @@ public function render(): View
5960
)
6061
);
6162
}
63+
64+
public function getExtraName(): string
65+
{
66+
return config('twill.media_library.translated_form_fields', false)
67+
&& $this->disableTranslate
68+
&& !$this->translated
69+
? '[' . config('app.locale') . ']' : '';
70+
}
6271
}

Diff for: src/View/Components/Fields/TwillFormComponent.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ public function formFieldName(bool $asAttributes = false, ?string $customName =
5151
{
5252
$name = $customName ?? $this->name;
5353
if ($this->renderForBlocks) {
54+
$extra = $this->getExtraName();
5455
if ($asAttributes) {
55-
return "name: fieldName('$name')";
56+
return "name: fieldName('$name', '$extra')";
5657
}
5758

58-
return ":name=\"fieldName('$name')\"";
59+
return ":name=\"fieldName('$name', '$extra')\"";
5960
}
6061

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

6869
abstract public function render(): View;
70+
71+
public function getExtraName(): string
72+
{
73+
return '';
74+
}
6975
}

Diff for: views/partials/form/_medias.blade.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757

5858
@unless($renderForBlocks)
5959
@push('vuexStore')
60-
@if (isset($form_fields['medias']) && isset($form_fields['medias'][$name]))
60+
@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]))
61+
window['{{ config('twill.js_namespace') }}'].STORE.medias.selected["{{ $name }}"] = {!! json_encode($form_fields['medias'][config('app.locale')][$name]) !!}
62+
@elseif(isset($form_fields['medias']) && isset($form_fields['medias'][$name]))
6163
window['{{ config('twill.js_namespace') }}'].STORE.medias.selected["{{ $name }}"] = {!! json_encode($form_fields['medias'][$name]) !!}
6264
@endif
6365
@endpush

0 commit comments

Comments
 (0)