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: Blocks take crop settings from parent model if name is the same #2542

Merged
merged 2 commits into from
Oct 15, 2024
Merged
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
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
Loading