Skip to content

Commit

Permalink
added 'block_' prefix to blocks crop configs
Browse files Browse the repository at this point in the history
  • Loading branch information
zeezo887 committed Mar 14, 2024
1 parent ce0fbf1 commit a174e83
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/TwillBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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');
Expand All @@ -325,6 +326,10 @@ public function getAllCropConfigs(): array
}
}

if ($prefixKey) {
return Arr::prependKeysWith($this->cropConfigs, 'block_');
}

return $this->cropConfigs;
}
}
4 changes: 2 additions & 2 deletions views/layouts/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}

Expand Down
4 changes: 2 additions & 2 deletions views/partials/form/_medias.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
type="a17-mediafield-translated"
:attributes="{
label: '{{ $label }}',
cropContext: '{{ $name }}',
cropContext: '{{ !$renderForBlocks ? $name : 'block_' . $name }}',
max: {{ $max }},
widthMin: {{ $widthMin }},
heightMin: {{ $heightMin }},
Expand Down Expand Up @@ -38,7 +38,7 @@
<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>
@if($multiple) <a17-slideshow @else <a17-mediafield @endif
{!! $formFieldName() !!}
crop-context="{{ $name }}"
crop-context="{{ !$renderForBlocks ? $name : 'block_' . $name }}"
:width-min="{{ $widthMin }}"
:height-min="{{ $heightMin }}"
@if($multiple) :max="{{ $max }}" @endif
Expand Down

0 comments on commit a174e83

Please sign in to comment.