Skip to content

Commit 64d4cf7

Browse files
zeezo887ifox
authored andcommitted
added 'block_' prefix to blocks crop configs
1 parent 60af476 commit 64d4cf7

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/TwillBlocks.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use A17\Twill\Services\Blocks\BlockCollection;
77
use A17\Twill\Services\Forms\InlineRepeater;
88
use A17\Twill\View\Components\Blocks\TwillBlockComponent;
9+
use Illuminate\Support\Arr;
910
use Illuminate\Support\Collection;
1011
use Illuminate\Support\Facades\File;
1112
use Illuminate\Support\Facades\Storage;
@@ -307,7 +308,7 @@ public function readBlocksFromDirectory(
307308
/**
308309
* Gets all the crop configs, also those of component blocks.
309310
*/
310-
public function getAllCropConfigs(): array
311+
public function getAllCropConfigs($prefixKey = false): array
311312
{
312313
if (! $this->cropConfigs) {
313314
$this->cropConfigs = config()->get('twill.block_editor.crops');
@@ -325,6 +326,10 @@ public function getAllCropConfigs(): array
325326
}
326327
}
327328

329+
if ($prefixKey) {
330+
return Arr::prependKeysWith($this->cropConfigs, 'block_');
331+
}
332+
328333
return $this->cropConfigs;
329334
}
330335
}

views/layouts/form.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@
205205
window['{{ config('twill.js_namespace') }}'].STORE.parents = {!! json_encode($parents ?? []) !!}
206206

207207
@if (isset($item) && classHasTrait($item, \A17\Twill\Models\Behaviors\HasMedias::class))
208-
window['{{ config('twill.js_namespace') }}'].STORE.medias.crops = {!! json_encode(($item->getMediasParams()) + \A17\Twill\Facades\TwillBlocks::getAllCropConfigs() + (config('twill.settings.crops') ?? [])) !!}
208+
window['{{ config('twill.js_namespace') }}'].STORE.medias.crops = {!! json_encode(($item->getMediasParams()) + \A17\Twill\Facades\TwillBlocks::getAllCropConfigs(true) + (config('twill.settings.crops') ?? [])) !!}
209209
@else
210-
window['{{ config('twill.js_namespace') }}'].STORE.medias.crops = {!! json_encode(\A17\Twill\Facades\TwillBlocks::getAllCropConfigs() + (config('twill.settings.crops') ?? [])) !!}
210+
window['{{ config('twill.js_namespace') }}'].STORE.medias.crops = {!! json_encode(\A17\Twill\Facades\TwillBlocks::getAllCropConfigs(true) + (config('twill.settings.crops') ?? [])) !!}
211211
@endif
212212
window['{{ config('twill.js_namespace') }}'].STORE.medias.selected = {}
213213

views/partials/form/_medias.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
type="a17-mediafield-translated"
44
:attributes="{
55
label: '{{ $label }}',
6-
cropContext: '{{ $name }}',
6+
cropContext: '{{ !$renderForBlocks ? $name : 'block_' . $name }}',
77
max: {{ $max }},
88
widthMin: {{ $widthMin }},
99
heightMin: {{ $heightMin }},
@@ -38,7 +38,7 @@
3838
<a17-inputframe @if($renderForBlocks) :fixed-error-key="$parent.blockFieldName !== undefined ? $parent.blockFieldName('{{$name}}') : ''" @endif label="{{ $label }}" name="medias.{{ $name }}" @if ($required) :required="true" @endif @if ($fieldNote) note="{{ $fieldNote }}" @endif>
3939
@if($multiple) <a17-slideshow @else <a17-mediafield @endif
4040
{!! $formFieldName() !!}
41-
crop-context="{{ $name }}"
41+
crop-context="{{ !$renderForBlocks ? $name : 'block_' . $name }}"
4242
:width-min="{{ $widthMin }}"
4343
:height-min="{{ $heightMin }}"
4444
@if($multiple) :max="{{ $max }}" @endif

0 commit comments

Comments
 (0)