Skip to content

Commit

Permalink
Merge pull request #2082 from antonioribeiro/capsules-blocks
Browse files Browse the repository at this point in the history
Allow creating blocks and repeaters inside Capsules
  • Loading branch information
haringsrob authored Feb 3, 2023
2 parents c089ee2 + 0b2e2e8 commit ff6c7ef
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/Helpers/Capsule.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ public function autoloadConfigFiles(): void
public function registerViews(): void
{
View::addLocation(Str::replaceLast(DIRECTORY_SEPARATOR . $this->name, '', $this->path));

$this->registerBlocksAndRepeatersViewPaths();
}

public function loadMigrations(): void
Expand Down Expand Up @@ -376,4 +378,22 @@ public function getType(): string
{
return '';
}

public function registerBlocksAndRepeatersViewPaths(): void
{
$resourcePath = $this->getConfig()['views_path'] ?? 'resources/views/admin';

foreach(['blocks', 'repeaters'] as $type) {
if (file_exists($path = "{$this->path}/$resourcePath/$type")) {
$paths = config("twill.block_editor.directories.source.$type");

$paths[] = [
'path' => $path,
'source' => 'capsule::'.$this->name
];

config(["twill.block_editor.directories.source.$type" => $paths]);
}
}
}
}
2 changes: 1 addition & 1 deletion views/partials/form/utils/_block_editor_store.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
window['{{ config('twill.js_namespace') }}'].STORE.form.blocks = {!! json_encode($form_fields['blocks']) !!}
window['{{ config('twill.js_namespace') }}'].STORE.form.blocks = {!! json_encode($form_fields['blocks'] ?? []) !!}

@foreach($form_fields['blocksFields'] ?? [] as $field)
window['{{ config('twill.js_namespace') }}'].STORE.form.fields.push({!! json_encode($field) !!})
Expand Down

0 comments on commit ff6c7ef

Please sign in to comment.