# Provider handlers

**Whatever value is passed to the grid block with the argument `provider` needs to be translated into an object that allows for building the structure and the data of the block. This translation is done via provider handlers.**

A provider handler is a class that is registered with the class `Loki\AdminComponents\ProviderHandler\ProviderHandlerListing` (via a DI type) and implements the interface `Loki\AdminComponents\ProviderHandler\ProviderHandlerInterface`.

## Default provider handlers
By default, there are three provider handlers by default:

- `repository` (`Loki\AdminComponents\ProviderHandler\RepositoryHandler`)
- `collection` (`Loki\AdminComponents\ProviderHandler\CollectionHandler`)
- `array` (`Loki\AdminComponents\ProviderHandler\ArrayHandler`)

Each provider handler needs to implement a `match($provider)` method to return `true` and `false`, depending on whether the `$provider` (a repository, collection, array provider) matches.

## Creating a new provider handler
In most cases, the existing providers will be good enough. However, it could be that your data needs to be fetched in a different way. In this case, just create a new class that implements `Loki\AdminComponents\ProviderHandler\ProviderHandlerInterface` and registers itself with a DI type for `Loki\AdminComponents\ProviderHandler\ProviderHandlerListing`:

```xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

    <type name="Loki\AdminComponents\ProviderHandler\ProviderHandlerListing">
        <arguments>
            <argument name="providerHandlers" xsi:type="array">
                <item name="foobar" xsi:type="object">Yireo\Example\ProviderHandler\FoobarHandler</item>
            </argument>
        </arguments>
    </type>
</config>
```
