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
2 changes: 2 additions & 0 deletions src/Services/Forms/Fields/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace A17\Twill\Services\Forms\Fields;

use A17\Twill\Services\Forms\Fields\Traits\CanDisableTranslate;
use A17\Twill\Services\Forms\Fields\Traits\CanHaveButtonOnTop;
use A17\Twill\Services\Forms\Fields\Traits\HasFieldNote;
use A17\Twill\Services\Forms\Fields\Traits\HasMax;
Expand All @@ -14,6 +15,7 @@ class Files extends BaseFormField
use HasMax;
use HasFieldNote;
use CanHaveButtonOnTop;
use CanDisableTranslate;

protected ?string $itemLabel = null;

Expand Down
23 changes: 23 additions & 0 deletions src/Services/Forms/Fields/Traits/CanDisableTranslate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace A17\Twill\Services\Forms\Fields\Traits;

trait CanDisableTranslate
{
/**
* @var bool
*/
protected bool $disableTranslate = false;

/**
* Disables translate
*
* @return $this
*/
public function disableTranslate(): static
{
$this->disableTranslate = true;

return $this;
}
}
8 changes: 7 additions & 1 deletion src/View/Components/Fields/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function __construct(
public bool $buttonOnTop = false,
public ?string $itemLabel = null,
public ?string $fieldNote = null,
public bool $disableTranslate = false
) {
$itemLabel = $itemLabel ?? strtolower($label);
$this->itemLabel = $itemLabel;
Expand All @@ -28,12 +29,17 @@ public function __construct(
label: $label,
note: $note ?? 'Add' . ($max > 1 ? " up to $max $itemLabel" : ' one ' . Str::singular($itemLabel)),
renderForBlocks: $renderForBlocks,
renderForModal: $renderForModal
renderForModal: $renderForModal,
);
}

public function render(): View
{
return view('twill::partials.form._files', $this->data());
}

public function getExtraName(): string
{
return $this->disableTranslate ? '[' . 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 '';
}
}
66 changes: 44 additions & 22 deletions views/partials/form/_files.blade.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
<a17-locale
type="a17-filefield"
:attributes="{
label: '{{ $label }}',
itemLabel: '{{ $itemLabel }}',
note: '{{ $note }}',
fieldNote: '{{ $fieldNote }}',
max: {{ $max }},
filesizeMax: {{ $filesizeMax }},
@if ($buttonOnTop) buttonOnTop: true, @endif
{!! $formFieldName(true) !!}
}"
></a17-locale>
@if (!$disableTranslate ?? true)
<a17-locale
type="a17-filefield"
:attributes="{
label: '{{ $label }}',
itemLabel: '{{ $itemLabel }}',
note: '{{ $note }}',
fieldNote: '{{ $fieldNote }}',
max: {{ $max }},
filesizeMax: {{ $filesizeMax }},
@if ($buttonOnTop) buttonOnTop: true, @endif
{!! $formFieldName(true) !!}
}"
></a17-locale>

@unless($renderForBlocks)
@push('vuexStore')
@foreach(getLocales() as $locale)
@if (isset($form_fields['files']) && isset($form_fields['files'][$locale][$name]))
window['{{ config('twill.js_namespace') }}'].STORE.medias.selected["{{ $name }}[{{ $locale }}]"] = {!! json_encode($form_fields['files'][$locale][$name]) !!}
@endif
@endforeach
@endpush
@endunless
@else
<a17-filefield
{!! $formFieldName() !!}
:max="{{ $max }}"
label="{{ $label }}"
item-label="{{ $itemLabel }}"
note="{{ $note }}"
field-note="{{ $fieldNote }}"
:filesize-max="{{ $filesizeMax }}"
@if ($buttonOnTop) :button-on-top="true", @endif
></a17-filefield>

@unless($renderForBlocks)
@push('vuexStore')
@if (isset($form_fields['files']) && isset($form_fields['files'][config('app.locale')]) && isset($form_fields['files'][config('app.locale')][$name]))
window['{{ config('twill.js_namespace') }}'].STORE.medias.selected["{{ $name }}"] = {!! json_encode($form_fields['files'][config('app.locale')][$name]) !!}
@endif
@endpush
@endunless
@endif

@unless($renderForBlocks)
@push('vuexStore')
@foreach(getLocales() as $locale)
@if (isset($form_fields['files']) && isset($form_fields['files'][$locale][$name]))
window['{{ config('twill.js_namespace') }}'].STORE.medias.selected["{{ $name }}[{{ $locale }}]"] = {!! json_encode($form_fields['files'][$locale][$name]) !!}
@endif
@endforeach
@endpush
@endunless