Plugin.php
/**
     * Boot method, called right before the request route.
     *
     * @return array
     */
Boot method, called right before the request route.
@return array
Boot method called right before the request route . @return array
public function boot()
    {
        Client::extend(function($model) {
            $model->hasMany['notes'] = 'AlbrightLabs\Note\Models\Note';
        });
        Clients::extend(function($controller){
            if (!$controller instanceof \AlbrightLabs\Client\Controllers\Clients) {
                return;
            }
            if (!isset($controller->relationConfig)) {
                $controller->addDynamicProperty('relationConfig');
            }
            $myConfigPath = '$/albrightlabs/note/controllers/notes/config_relation.yaml';
            $controller->relationConfig = $controller->mergeConfig(
                $controller->relationConfig,
                $myConfigPath
            );
        });
        Event::listen('backend.form.extendFields', function($widget) {
            if (!$widget->getController() instanceof \AlbrightLabs\Client\Controllers\Clients) {
                return;
            }
            if (!$widget->model instanceof \AlbrightLabs\Client\Models\Client) {
                return;
            }
            $widget->addTabFields([
                'notes' => [
                    'label' => 'Notes',
                    'type'  => 'partial',
                    'path'  => '$/albrightlabs/note/controllers/notes/_field_notes.htm',
                    'tab'   => 'Notes',
                ],
            ]);
        });
        Event::listen('backend.form.extendFields', function($widget) {
            if (!$widget->getController() instanceof \AlbrightLabs\Note\Controllers\Notes) {
                return;
            }
            if (!$widget->model instanceof \AlbrightLabs\Note\Models\Note) {
                return;
            }
            $widget->removeField('title');
            $widget->addFields([
                'client' => [
                    'label'       => 'Client',
                    'type'        => 'relation',
                    'select'      => 'concat(name, " ", surname)',
                    'placeholder' => '-- Select Client --',
                ],
                'title' => [
                    'label' => 'Title',
                    'type'  => 'text',
                    'span'  => 'full',
                ],
            ]);
        });
    }
public function boot ( ) { Client :: extend ( function ( $ model ) { $ model -> hasMany [ 'notes' ] = 'AlbrightLabs\Note\Models\Note' ; } ) ; Clients :: extend ( function ( $ controller ) { if ( ! $ controller instanceof \ AlbrightLabs \ Client \ Controllers \ Clients ) { return ; } if ( ! isset ( $ controller -> relationConfig ) ) { $ controller -> addDynamicProperty ( 'relationConfig' ) ; } $ myConfigPath = '$/albrightlabs/note/controllers/notes/config_relation.yaml' ; $ controller -> relationConfig = $ controller -> mergeConfig ( $ controller -> relationConfig , $ myConfigPath ) ; } ) ; Event :: listen ( 'backend.form.extendFields' , function ( $ widget ) { if ( ! $ widget -> getController ( ) instanceof \ AlbrightLabs \ Client \ Controllers \ Clients ) { return ; } if ( ! $ widget -> model instanceof \ AlbrightLabs \ Client \ Models \ Client ) { return ; } $ widget -> addTabFields ( [ 'notes' => [ 'label' => 'Notes' , 'type' => 'partial' , 'path' => '$/albrightlabs/note/controllers/notes/_field_notes.htm' , 'tab' => 'Notes' , ] , ] ) ; } ) ; Event :: listen ( 'backend.form.extendFields' , function ( $ widget ) { if ( ! $ widget -> getController ( ) instanceof \ AlbrightLabs \ Note \ Controllers \ Notes ) { return ; } if ( ! $ widget -> model instanceof \ AlbrightLabs \ Note \ Models \ Note ) { return ; } $ widget -> removeField ( 'title' ) ; $ widget -> addFields ( [ 'client' => [ 'label' => 'Client' , 'type' => 'relation' , 'select' => 'concat(name, " ", surname)' , 'placeholder' => '-- Select Client --' , ] , 'title' => [ 'label' => 'Title' , 'type' => 'text' , 'span' => 'full' , ] , ] ) ; } ) ; }
Boot method, called right before the request route.
Boot method called right before the request route .
// Add relation to AlbrightLabs.Client Client model // Add relation config to AlbrightLabs.Client Clients controller // Only for the Clients controller // Extend all backend form usage for AlbrightLabs.Client Client model // Only for the Clients controller // Only for the Client model // Add the notes list field // Extend all backend form usage for AlbrightLabs.Note note model // Only for the Clients controller // Only for the Client model // Remove thte title field // Add the client dropdown and re-add title field