Appearance
Using Filters
Filters allow you to manipulate the data being processed by AdminUI at many different points in the application lifecycle. Whether you want to add more data or remove some data, filters can be registered from anywhere in your AdminUI-powered application.
You can register filter callbacks by using our provided facade:
php
<?php
use AdminUI\AdminUI\Facades\Filters;
Adding a filter callback
You can find a full list of available filters on the Filter Reference page.
For now, here's an example of how the process works:
php
use AdminUI\AdminUI\Facades\Filters;
Filters::add(string $key, callable $callback, int $priority);
- The
$key
is the filter key you want to add a callback to $callback
is the callable function that will be executed$priority
defines the order in which registered callbacks will be run. The lower the number, the earlier your callback is executed
Example
php
use AdminUI\AdminUI\Facades\Filters;
Filters::add('admin_navigation_main', function ($value) {
$items = array_map(function ($item) {
$item['title'] = "A " . $item['title'];
return $item;
}, $value);
return $items;
}, 100);
Here, we've registered a callback on the admin_navigation_main
filter. We've passed it a function that receives the value to filter. Then finally, we've passed a priority level of 100
. This means that a registered callback for this filter with a priority of 99
would be executed before ours and a callback with 101
would be executed after ours.
Some filters may supply additional parameters to your callback function. You can optionally receive these and use them in your filtering callback. Full details of what parameters are available from each filter are detailed on the Filter Reference page.