From 21bb5d571d9d294edeae33c9c61618b99bbca153 Mon Sep 17 00:00:00 2001 From: Tofandel <adrien.foulon@tukan.hu> Date: Tue, 5 Mar 2024 18:11:27 +0100 Subject: [PATCH] Only output list of used blocks --- src/TwillBlocks.php | 9 +++++---- views/layouts/form.blade.php | 6 ++---- views/layouts/main.blade.php | 1 + 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/TwillBlocks.php b/src/TwillBlocks.php index eaa06b4aff..7e70d8fe27 100644 --- a/src/TwillBlocks.php +++ b/src/TwillBlocks.php @@ -355,7 +355,7 @@ public function getAllCropConfigs(): array public function getListOfUsedBlocks(): Collection { - return $this->usedBlocks->values(); + return $this->usedBlocks; } public function generateListOfAllBlocks(bool $settingsOnly = false): Collection @@ -391,7 +391,7 @@ function ($appBlock) use ($block) { return false; } } - return isset($disabledBlocks[$block->name]) || isset($disabledBlocks[ltrim($block->componentClass, '\\')]); + return !(isset($disabledBlocks[$block->name]) || isset($disabledBlocks[ltrim($block->componentClass, '\\')])); })->sortBy(function (Block $b) use ($customOrder) { // Sort blocks by custom order then by group and then by name return ($customOrder[$b->name] ?? $customOrder[ltrim($b->componentClass, '\\')] ?? PHP_INT_MAX) . '-' . $b->group . '-' . $b->name; @@ -406,7 +406,7 @@ public function generateListOfAvailableBlocks( array|callable $excludeBlocks = [], bool $defaultOrder = false ): Collection { - $globalExcludeBlocks = TwillBlocks::getGloballyExcludedBlocks(); + $globalExcludeBlocks = $this->getGloballyExcludedBlocks(); $matchBlock = function ($matcher, $block, $someFn = null) { if (is_callable($matcher)) { @@ -454,7 +454,8 @@ function (Block $block) use ($blocks, $groups, $excludeBlocks, $globalExcludeBlo $finalList = $finalList->sortBy(fn(Block $block) => $groups[$block->group] ?? PHP_INT_MAX, SORT_NUMERIC); } } - $this->usedBlocks->merge($finalList->keyBy(fn(Block $block) => $block->name)); + + $this->usedBlocks = $this->usedBlocks->merge($finalList->keyBy(fn(Block $block) => $block->name)); return $finalList; } } diff --git a/views/layouts/form.blade.php b/views/layouts/form.blade.php index 258478552c..0257df1485 100644 --- a/views/layouts/form.blade.php +++ b/views/layouts/form.blade.php @@ -223,11 +223,9 @@ {{-- Permissions --}} window['{{ config('twill.js_namespace') }}'].STORE.groups = {!! isset($groups) ? json_encode($groups) : '[]' !!}; window['{{ config('twill.js_namespace') }}'].STORE.groupUserMapping = {!! isset($groupUserMapping) ? json_encode($groupUserMapping) : '[]' !!}; -@stop -@push('vuexStore') - window['{{config('twill.js_namespace')}}.STORE.form.allAvailableBlocks'] = {!! json_encode(TwillBlocks::getListOfUsedBlocks()) !!}; -@endpush + window['{{config('twill.js_namespace')}}'].STORE.form.allAvailableBlocks = {!! TwillBlocks::getListOfUsedBlocks() !!} +@stop @prepend('extra_js') @includeWhen(config('twill.block_editor.inline_blocks_templates', true), 'twill::partials.form.utils._blocks_templates') diff --git a/views/layouts/main.blade.php b/views/layouts/main.blade.php index 7fa5e602e5..3af2e0d41d 100644 --- a/views/layouts/main.blade.php +++ b/views/layouts/main.blade.php @@ -145,6 +145,7 @@ window.STORE.browsers.selected = {} @stack('vuexStore') + </script> <script src="{{ twillAsset('chunk-vendors.js') }}"></script> <script src="{{ twillAsset('chunk-common.js') }}"></script>