Overriding
Uccello was designed to make it very easy for developers to create applications that allow them to manage their data. However, it is quite possible to customize Uccello's behavior to meet specific needs.
For this purpose it is possible to override routes, controllers, views and translations.
Override a View
It is extremely easy to override a view. If you create a blade file using the kernel directory architecture, Uccello will automatically detect your file and use it first. You can do this for all modules or for a particular module.
To override a view for a particular module, use this path: resources/views/uccello/modules/
moduleName
/
viewName
/main.blade.php
To override a view for all modules, use this path:
resources/views/uccello/modules/default/
viewName
/main.blade.php
Here is the list of all default views name:
index
list
detail
edit
It is only possible to override main.blade.php
files. If you want to override other files, you can copy them from the kernel and adapt them in your application.
Example 1
If you want to replace the home page, create the file resources/views/uccello/modules/home/index/main.blade.php
with the following content:
Example 2
If you want to replace all index pages, create the file resources/views/uccello/modules/default/index/main.blade.php
with the following content:
The overriding of a view from a specific module has priority over the overriding of a default view.
Priority
To detect which view to use, Uccello uses the following priorities:
Module view overridden in app
Default view overridden in app
Module view overridden in package
Default view defined in package
Module view overridden in uccello
Default view defined in uccello
Fallback view if defined
Override an Uitype
As with views, it is very easy to override a uitype.
Each uitype can have its own HTML representation in the following views:
Search field of the list view
Cell of the table in the list view table
Detail view
Edit view
You can view the list of default uitypes views, on the Uccello Git repository or directly from your application in the following directory:vendor/uccello/uccello/resources/views/modules/default/uitypes
It is possible to override a uitype on a module level or for the entire application.
To override a uitype's view for a particular module, use this path: resources/views/uccello/modules/
moduleName
/uitypes/
viewName
/
uitypeName
.blade.php
To override a view for all modules, use this path:
resources/views/uccello/modules/default/uitypes/
viewName
/
uitypeName
.blade.php
Here is the list of all default uitypes views name:
search
list
detail
edit
If no views are defined for a specific uitype, Uccello uses by default the views defined for the text
uitype.
For example, in a detail view, Uccello uses the file resources/views/modules/default/uitypes/detail/text.blade.php to represent the integer
uitype.
Override a Controller
For override a Controller, you have to override 2 things:
The controller of your choice
The road to access this controller
Controller
First of all you have to create a new controller which will extends the original one. For example you want to override the DetailController
for the user
module.
Create a file located at app/Http/Controllers/User/DetailController.php
and add the following code:
Route
Modify the routes file located at routes/web.php
and add the following code for overriding the route that points to the Detail View of the user module.
Now the route points to your overridden Controller.
Override a Model
To override a Model you have to override 2 things:
The model of your choice
The module's
model_class
attribute in the database
Model
Simply create a new model extending the original one, and put your overriding modification inside.
Attribute
Create a migration file and modify the uccello_modules
table and change model_class
attribute for using your new model.
Override a Localization file
It is very simple to override a Localization file from another package. To do this, just create a file located at resources/lang/{lang_code}/{module_name}.php
and create a key for each translation label you want to override.
Example
To override the domain
module translation file in english, just create a file located at resources/lang/en/domain.php
and add the following code:
Now the domain
module will be named Companies and the name
field will be named Company's name.
Last updated