I'll explain how to add a new design module similar to the brand design module in BeikeShop. Here's a step-by-step guide:
- First, create a View Builder class in
beike/Admin/View/DesignBuilders/ directory:
php
namespace Beike\Admin\View\DesignBuilders;
use Illuminate\Contracts\View\View;
use Illuminate\View\Component;
class YourModule extends Component
{
public function __construct()
{
}
public function render(): View
{
$data['register'] = [
'code' => 'your_module', // unique module code
'sort' => 0,
'name' => trans('admin/design_builder.module_your_module'), // translation key
'icon' => '', // module icon
];
return view('admin::pages.design.module.your_module', $data);
}
}
- Create a blade template for the module editor in
resources/beike/admin/views/pages/design/module/:
php
<template id="module-editor-your-module-template">
<div class="image-edit-wrapper">
<div class="module-editor-row">{{ __('admin/builder.text_set_up') }}</div>
<div class="module-edit-group">
<div class="module-edit-title">{{ __('admin/builder.text_module_title') }}</div>
<text-i18n v-model="form.title"></text-i18n>
</div>
<!-- Add your module specific configuration options here -->
</div>
</template>
<script type="text/javascript">
Vue.component('module-editor-your-module', {
template: '#module-editor-your-module-template',
props: ['module'],
data: function () {
return {
form: null,
}
},
watch: {
form: {
handler: function (val) {
this.$emit('on-changed', val);
},
[Redacted Person]: true
}
},
created: function () {
this.form = JSON.parse(JSON.stringify(this.module));
},
});
</script>
@push('footer-script')
<script>
register = @json($register);
register.make = {
style: {
background_color: ''
},
title: languagesFill('{{ __('admin/builder.text_module_title') }}'),
// Add other default properties
}
app.source.modules.push(register)
</script>
@endpush
- Create a blade template for the frontend display in
themes/default/design/:
php
<section class="module-item {{ $design ? 'module-item-design' : ''}}" id="module-{{ $module_id }}">
@include('design._partial._module_tool')
<div class="module-info module-your-module mb-3 mb-md-5">
<div class="module-title">{{ $content['title'] }}</div>
<div class="container">
<!-- Add your module frontend HTML here -->
</div>
</div>
</section>
- Register the module in
DesignController.php:
php
$data = [
'editors' => [
// ... other modules
'editor-your_module',
],
'design_settings' => system_setting('base.design_setting'),
];
- Add module content handling in
DesignService.php:
php
public static function handleModuleContent($moduleCode, $content)
{
// ... existing code ...
} elseif ($moduleCode == 'your_module') {
return self::handleYourModule($content);
}
// Add handler method
private static function handleYourModule($content): array
{
// Process module specific content
$content['title'] = $content['title'][locale()] ?? '';
// Add other processing logic
return $content;
}
}
Key points to remember:
- Give your module a unique code
- Create both admin editor and frontend display templates
- Handle multilingual content properly
- Register the module in the design controller
- Add content processing logic in the design service
- Follow the existing module patterns for consistency
You can look at the brand module implementation as a reference:
BrandController.php for API endpoints
brand.blade.php for frontend display
module/brand.blade.php for admin editor
Brand.php for the view builder
The brand module provides features like:
- Title configuration
- Brand selection
- Drag and drop reordering
- Multilingual support
- Responsive display
Follow this pattern while implementing your custom module functionality.