PHP code example of tourze / easy-admin-extra-bundle

1. Go to this page and download the library: Download tourze/easy-admin-extra-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tourze / easy-admin-extra-bundle example snippets


Tourze\EasyAdminExtraBundle\EasyAdminExtraBundle::class => ['all' => true],

use Tourze\EasyAdminExtraBundle\Controller\AbstractCrudController;

class UserCrudController extends AbstractCrudController
{
    public static function getEntityFqcn(): string
    {
        return User::class;
    }
}

use Tourze\EasyAdminAttribute\Attribute\FormField;
use Tourze\EasyAdminAttribute\Attribute\ListColumn;
use Tourze\EasyAdminAttribute\Attribute\Filterable;
use Tourze\EasyAdminAttribute\Attribute\Keyword;

class User
{
    #[ListColumn(order: 1)]
    #[FormField(order: 1)]
    #[Filterable]
    #[Keyword]
    private string $username;

    #[ListColumn(order: 2)]
    #[FormField(order: 2)]
    #[Filterable]
    private string $email;

    // Other properties...
}

use Tourze\EasyAdminExtraBundle\Service\EntityDescriber;

class MyService
{
    public function __construct(
        private readonly EntityDescriber $entityDescriber,
    ) {
    }

    public function example(\ReflectionProperty $property): string
    {
        // Get property label
        return $this->entityDescriber->getPropertyLabel($property);
    }
}

use Tourze\EasyAdminExtraBundle\Service\ChoiceService;

class MyService
{
    public function __construct(
        private readonly ChoiceService $choiceService,
    ) {
    }

    public function example(string $enumClass): array
    {
        // Create choices from enum
        return iterator_to_array($this->choiceService->createChoicesFromEnum($enumClass));
    }
}

use Tourze\EasyAdminExtraBundle\Service\RepositoryTreeDataFetcher;

class MyTreeService
{
    public function __construct(
        private readonly RepositoryTreeDataFetcher $treeFetcher,
    ) {
    }

    public function getTreeData(string $entityClass): array
    {
        $this->treeFetcher->setEntityClass($entityClass);
        return $this->treeFetcher->genTreeData();
    }
}

use Tourze\EasyAdminExtraBundle\Service\FieldService;

class CustomFieldService extends FieldService
{
    public function createCustomField(\ReflectionProperty $property): ?FieldInterface
    {
        // Custom field creation logic
        return null;
    }
}

use Tourze\EasyAdminExtraBundle\Service\RepositoryTreeDataFetcher;

class CustomTreeDataFetcher extends RepositoryTreeDataFetcher
{
    public function customTreeProcessing(array $tree): array
    {
        // Custom tree processing logic
        return $tree;
    }
}

use Tourze\EasyAdminExtraBundle\Contract\CopyableRepository;

class MyEntityRepository extends ServiceEntityRepository
{
    use CopyableRepository;
    
    // Repository implementation
}
bash
cd packages/easy-admin-extra-bundle
composer install
php vendor/bin/phpunit
bash
php vendor/bin/phpunit packages/easy-admin-extra-bundle