Creating

Creating Widget

All widgets needs to be properly created in the database. The first table to insert a record for new widget is: widgets table. Inser the name and the view filename of the widget in this table.

Every widget must have its own view files and folders on the filesystem The path for the widget folder is: resources/views/themes/widget_{name}. The widget folder should contain two more folder. The first is livewire folder which will contain the component view file which we’re going to use and the other is widgets. widgets folder should contain .blade.php file with the same name that we’re going to insert into widgets table view column in database. If I want to create a widget called test1 I should have the following structure:

resources/views/themes/widget_test1/
resources/views/themes/widget_test1/livewire
resources/views/themes/widget_test1/widgets/test1.blade.php

In the main .blade.php view file we can call the desired front component and pass it any view from the livewire folder (we should create and name those view by ourselves).

Example .blade.php file contents:

@section('content')
<div class="trm-row border-bottom" style="margin: 15px;">
    <div class="trm-col-6 module-title"><span>SONDERTHEMEN</span></div>
    <div class="trm-col-6 trm-text-right">Anzeige</div>
</div>
@livewire('front.widget-articles', ['view' => 'articles'])

@endsection

And the following database record should be inserted (record insert via laravel model)

    $widget = Widget::create([
        'name' => 'test1',
        'view' => 'test1'
    ]);

After we have the files structure ready and the main database record inserted, we need to register the widget in the themes db table, in the order for the widget to be a proper theme and be able to be attached to any product/integration.

Example creation via laravel code:

    $widgetThemeName = "widget_test1";
    $widgetViewFolder = "themes.widget_test1";

    $theme = Theme::create([
        'name' => $widgetThemeName,
        'view_folder' => $widgetViewFolder,
        'description' => 'Simple description of the widget',
        'page_type' => Theme::PAGE_TYPE_NOT_SHOWN
    ]);

After the widget is registered into the themes folder we need to insert a database record into structures table using the returned id from the themes table insert:


$struct = Structure::create([
    'type' => Structure::TYPE_THEME,
    'type_id' => $theme->id [The theme id we get after the themes insert],
    'apply_type' => Structure::APPLY_TYPE_WIDGET,
    'internal_id' => [The ID of the widget from the widgets table],
    'device_type' => 0,
    'unset'       => 0,
    'priority'    => 1
]);