Skip to content

Commit

Permalink
Only output list of used blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Mar 5, 2024
1 parent b256607 commit 21bb5d5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/TwillBlocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -391,7 +391,7 @@ function ($appBlock) use ($block) {
return false;

Check warning on line 391 in src/TwillBlocks.php

View check run for this annotation

Codecov / codecov/patch

src/TwillBlocks.php#L391

Added line #L391 was not covered by tests
}
}
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;
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
}
}
6 changes: 2 additions & 4 deletions views/layouts/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
1 change: 1 addition & 0 deletions views/layouts/main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 21bb5d5

Please sign in to comment.