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

fix: Non-translated media fields display as empty #2525

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
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 @@

protected bool $activeCrop = true;

protected bool $disableTranslate = false;

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

return $this;
}

public function disableTranslate(): static

Check warning on line 143 in src/Services/Forms/Fields/Medias.php

View check run for this annotation

Codecov / codecov/patch

src/Services/Forms/Fields/Medias.php#L143

Added line #L143 was not covered by tests
{
$this->disableTranslate = true;

Check warning on line 145 in src/Services/Forms/Fields/Medias.php

View check run for this annotation

Codecov / codecov/patch

src/Services/Forms/Fields/Medias.php#L145

Added line #L145 was not covered by tests

return $this;

Check warning on line 147 in src/Services/Forms/Fields/Medias.php

View check run for this annotation

Codecov / codecov/patch

src/Services/Forms/Fields/Medias.php#L147

Added line #L147 was not covered by tests
}
}
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