<commit_before>Chapter 7. Creating Complex and Dynamic Backends
================================================

In the previous chapters you've learned how to configure your backend using YAML
configuration options and overriding Twig templates. This mechanism is enough
for simple and medium-sized backends.

However, for more complex and dynamic backends you need to use the PHP-based
customization mechanism provided by EasyAdmin. Depending on your needs you can
choose any of these three customization options (or combine them, if your
backend is very complex):

  1. **Override the default AdminController**, which is easy to set up and best
     suited for simple backends.
  2. **Define a different controller for some or all entities**, which is also
     easy to set up and scales well for medium-sized backends.
  3. **Define event listeners or subscribers** that listen to the events
     triggered by EasyAdmin. This is harder to set up but allows you to define
     the customization code anywhere in your application.

Customization Based on Overriding the Default AdminController
-------------------------------------------------------------

This technique requires you to create a new controller in your Symfony
application and make it extend from the default `AdminController` provided by
EasyAdmin. Then you just add some methods in your controller to override the
default ones.

**Step 1.** Create a new controller class anywhere in your Symfony application
and make it extend from the default `AdminController` class:

```php
// src/AppBundle/Controller/AdminController.php
namespace AppBundle\Controller;

use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController;

class AdminController extends BaseAdminController
{
    // ...
}
```

**Step 2.** Open the `app/config/routing.yml` file and change the `resource`
option of the `easy_admin_bundle` route to point to the new controller:

```yaml
# app/config/routing.yml
easy_admin_bundle:
    # resource: "@EasyAdminBundle/Controller/"           <-- REMOVE this line
    resource: "@AppBundle/Controller/AdminController.php" # <-- ADD this line
    type:     annotation
    prefix:   /admin<commit_msg>[Doc] Better explain how to configure a custom controller<commit_after>Chapter 7. Creating Complex and Dynamic Backends
================================================

In the previous chapters you've learned how to configure your backend using YAML
configuration options and overriding Twig templates. This mechanism is enough
for simple and medium-sized backends.

However, for more complex and dynamic backends you need to use the PHP-based
customization mechanism provided by EasyAdmin. Depending on your needs you can
choose any of these three customization options (or combine them, if your
backend is very complex):

  1. **Override the default AdminController**, which is easy to set up and best
     suited for simple backends.
  2. **Define a different controller for some or all entities**, which is also
     easy to set up and scales well for medium-sized backends.
  3. **Define event listeners or subscribers** that listen to the events
     triggered by EasyAdmin. This is harder to set up but allows you to define
     the customization code anywhere in your application.

Customization Based on Overriding the Default AdminController
-------------------------------------------------------------

This technique requires you to create a new controller in your Symfony
application and make it extend from the default `AdminController` provided by
EasyAdmin. Then you just add some methods in your controller to override the
default ones.

**Step 1.** Create a new controller class anywhere in your Symfony application
and make it extend from the default `AdminController` class:

```php
// src/AppBundle/Controller/AdminController.php
namespace AppBundle\Controller;

use JavierEguiluz\Bundle\EasyAdminBundle\Controller\AdminController as BaseAdminController;

class AdminController extends BaseAdminController
{
    // ...
}
```

**Step 2.** Open the `app/config/routing.yml` file and change the `resource`
option of the `easy_admin_bundle` route to point to your new controller:

```yaml
# app/config/routing.yml
easy_admin_bundle:
    # this is just an example; update the value of 'resource' accordingly
    resource: "@AppBundle/Controller/AdminController.php"
    type:     annotation
    prefix:   /admin
{'fraction_non_alphanumeric': 0.10232138832544511, 'fraction_numerical': 0.002704530087897228, 'mean_word_length': 3.871569703622393, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3741504', 'n_tokens_mistral': 1064, 'n_tokens_neox': 1011, 'n_words': 536}