diff --git a/src/TwillBlocks.php b/src/TwillBlocks.php index 0273bf21b..dbe33eb52 100644 --- a/src/TwillBlocks.php +++ b/src/TwillBlocks.php @@ -6,6 +6,7 @@ use A17\Twill\Services\Blocks\BlockCollection; use A17\Twill\Services\Forms\InlineRepeater; use A17\Twill\View\Components\Blocks\TwillBlockComponent; +use Illuminate\Support\Arr; use Illuminate\Support\Collection; use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; @@ -307,7 +308,7 @@ public function readBlocksFromDirectory( /** * Gets all the crop configs, also those of component blocks. */ - public function getAllCropConfigs(): array + public function getAllCropConfigs($prefixKey = false): array { if (! $this->cropConfigs) { $this->cropConfigs = config()->get('twill.block_editor.crops'); @@ -325,6 +326,10 @@ public function getAllCropConfigs(): array } } + if ($prefixKey) { + return Arr::prependKeysWith($this->cropConfigs, 'block_'); + } + return $this->cropConfigs; } } diff --git a/views/layouts/form.blade.php b/views/layouts/form.blade.php index 2707dfa69..34c7a7408 100644 --- a/views/layouts/form.blade.php +++ b/views/layouts/form.blade.php @@ -205,9 +205,9 @@ window['{{ config('twill.js_namespace') }}'].STORE.parents = {!! json_encode($parents ?? []) !!} @if (isset($item) && classHasTrait($item, \A17\Twill\Models\Behaviors\HasMedias::class)) - window['{{ config('twill.js_namespace') }}'].STORE.medias.crops = {!! json_encode(($item->getMediasParams()) + \A17\Twill\Facades\TwillBlocks::getAllCropConfigs() + (config('twill.settings.crops') ?? [])) !!} + window['{{ config('twill.js_namespace') }}'].STORE.medias.crops = {!! json_encode(($item->getMediasParams()) + \A17\Twill\Facades\TwillBlocks::getAllCropConfigs(true) + (config('twill.settings.crops') ?? [])) !!} @else - window['{{ config('twill.js_namespace') }}'].STORE.medias.crops = {!! json_encode(\A17\Twill\Facades\TwillBlocks::getAllCropConfigs() + (config('twill.settings.crops') ?? [])) !!} + window['{{ config('twill.js_namespace') }}'].STORE.medias.crops = {!! json_encode(\A17\Twill\Facades\TwillBlocks::getAllCropConfigs(true) + (config('twill.settings.crops') ?? [])) !!} @endif window['{{ config('twill.js_namespace') }}'].STORE.medias.selected = {} diff --git a/views/partials/form/_medias.blade.php b/views/partials/form/_medias.blade.php index 9545875d5..3b2091bd1 100644 --- a/views/partials/form/_medias.blade.php +++ b/views/partials/form/_medias.blade.php @@ -3,7 +3,7 @@ type="a17-mediafield-translated" :attributes="{ label: '{{ $label }}', - cropContext: '{{ $name }}', + cropContext: '{{ !$renderForBlocks ? $name : 'block_' . $name }}', max: {{ $max }}, widthMin: {{ $widthMin }}, heightMin: {{ $heightMin }}, @@ -38,7 +38,7 @@ @if($multiple)