Include libraries based on block configuration
This commit is contained in:
parent
39ac5bc80e
commit
9806afe60f
|
@ -249,6 +249,12 @@ class UserController extends Controller
|
||||||
// Add $linkType->ignore_container to the $customParams array
|
// Add $linkType->ignore_container to the $customParams array
|
||||||
$customParams['ignore_container'] = $linkType->ignore_container;
|
$customParams['ignore_container'] = $linkType->ignore_container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if $linkType->include_libraries is defined and not null
|
||||||
|
if (isset($linkType->include_libraries)) {
|
||||||
|
// Add $linkType->include_libraries to the $customParams array
|
||||||
|
$customParams['include_libraries'] = $linkType->include_libraries;
|
||||||
|
}
|
||||||
|
|
||||||
$filteredLinkData['type_params'] = json_encode($customParams);
|
$filteredLinkData['type_params'] = json_encode($customParams);
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use Illuminate\Filesystem\Filesystem;
|
||||||
|
|
||||||
class LinkType extends Model
|
class LinkType extends Model
|
||||||
{
|
{
|
||||||
protected $fillable = ['id', 'typename', 'title', 'description', 'icon', 'custom_html', 'ignore_container'];
|
protected $fillable = ['id', 'typename', 'title', 'description', 'icon', 'custom_html', 'ignore_container', 'include_libraries'];
|
||||||
|
|
||||||
// Assuming no database interaction, we can disable timestamps
|
// Assuming no database interaction, we can disable timestamps
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
@ -33,6 +33,7 @@ class LinkType extends Model
|
||||||
'icon' => 'bi bi-boxes',
|
'icon' => 'bi bi-boxes',
|
||||||
'custom_html' => false,
|
'custom_html' => false,
|
||||||
'ignore_container' => false,
|
'ignore_container' => false,
|
||||||
|
'include_libraries' => [],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$linkTypes->prepend($predefinedLinkType);
|
$linkTypes->prepend($predefinedLinkType);
|
||||||
|
@ -51,6 +52,7 @@ class LinkType extends Model
|
||||||
'icon' => $configData['icon'] ?? null,
|
'icon' => $configData['icon'] ?? null,
|
||||||
'custom_html' => $configData['custom_html'] ?? false,
|
'custom_html' => $configData['custom_html'] ?? false,
|
||||||
'ignore_container' => $configData['ignore_container'] ?? false,
|
'ignore_container' => $configData['ignore_container'] ?? false,
|
||||||
|
'include_libraries' => $configData['include_libraries'] ?? [],
|
||||||
]);
|
]);
|
||||||
$linkTypes->push($linkType);
|
$linkTypes->push($linkType);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
$initial = 1;
|
$initial = 1;
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
|
@include('linkstack.modules.block-libraries', ['links' => $links])
|
||||||
|
|
||||||
@foreach($links as $link)
|
@foreach($links as $link)
|
||||||
@if(isset($link->custom_html) && $link->custom_html)
|
@if(isset($link->custom_html) && $link->custom_html)
|
||||||
@if(isset($link->ignore_container) && $link->ignore_container)
|
@if(isset($link->ignore_container) && $link->ignore_container)
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
@php
|
||||||
|
$librariesToInclude = [];
|
||||||
|
@endphp
|
||||||
|
|
||||||
|
@foreach($links as $link)
|
||||||
|
@if(isset($link->custom_html) && isset($link->include_libraries) && $link->custom_html && is_array($link->include_libraries))
|
||||||
|
@foreach($link->include_libraries as $library => $include)
|
||||||
|
@if($include)
|
||||||
|
@php
|
||||||
|
$librariesToInclude[$library] = true;
|
||||||
|
@endphp
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
@foreach($librariesToInclude as $library => $include)
|
||||||
|
@switch($library)
|
||||||
|
|
||||||
|
@case('jquery')
|
||||||
|
@once
|
||||||
|
@push('linkstack-head')
|
||||||
|
<script src="{{ asset('assets/external-dependencies/jquery-3.4.1.min.js') }}"></script>
|
||||||
|
@endpush
|
||||||
|
@endonce
|
||||||
|
@break
|
||||||
|
|
||||||
|
@case('sweetalert')
|
||||||
|
@once
|
||||||
|
@push('linkstack-head')
|
||||||
|
<script src="{{ asset('assets/external-dependencies/sweetalert2.min.js') }}"></script>
|
||||||
|
@endpush
|
||||||
|
@endonce
|
||||||
|
@break
|
||||||
|
|
||||||
|
@endswitch
|
||||||
|
@endforeach
|
||||||
|
|
||||||
|
|
||||||
|
@php /* For debugging purposes, you can add a script to the end of the body that logs the inclusion of each library: */ @endphp
|
||||||
|
{{-- @push('linkstack-body-end')
|
||||||
|
<script>
|
||||||
|
function logAssetInclusion(library) {
|
||||||
|
console.log(library + ' has been included.');
|
||||||
|
}
|
||||||
|
|
||||||
|
@foreach($librariesToInclude as $library => $include)
|
||||||
|
logAssetInclusion('{{ ucfirst($library) }}');
|
||||||
|
@endforeach
|
||||||
|
</script>
|
||||||
|
@endpush --}}
|
Loading…
Reference in New Issue