PHP code example of umanit / easyadmin-tree-bundle
1. Go to this page and download the library: Download umanit/easyadmin-tree-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/ */
umanit / easyadmin-tree-bundle example snippets
// src/Entity/Category.php
namespace App\Entity;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Umanit\EasyAdminTreeBundle\Entity\AbstractTreeItem;
#[ORM\Entity]
#[ORM\Table(name: 'app_category')]
class Category extends AbstractTreeItem
{
...
}
// src/Controller/Admin/MyTreeCrudController.php
namespace App\Controller\Admin;
use App\Entity\Category;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\SlugField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Umanit\EasyAdminTreeBundle\Controller\TreeCrudController;
use Umanit\EasyAdminTreeBundle\Field\TreeField;
class MyTreeCrudController extends TreeCrudController
{
public static function getEntityFqcn(): string
{
// return your Category entity FQCN
return Category::class;
}
protected function getEntityLabelProperty(): string
{
// return the property of your category to use as a label in tree display
return 'name';
}
}
public function configureMenuItems(): iterable
{
return [
...
MenuItem::linkToCrud('Categories', 'fas fa-list', Category::class),
...
];
}
// src/Controller/Admin/MediaCrudController.php
namespace App\Controller\Admin;
use App\Entity\Category;
use App\Entity\Media;
use Umanit\EasyAdminTreeBundle\Controller\AbstractCategorizedCrudController;
class MediaCrudController extends AbstractCategorizedCrudController
{
public static function getEntityFqcn(): string
{
return Media::class;
}
public function configureCrud(Crud $crud): Crud
{
$crud = parent::configureCrud($crud);
// ...
}
public static function getCategoryFqcn(): string
{
// The FQCN of the entity to use as a category (should extend AbstractTreeItem)
return Category::class;
}
protected static function getCategoryPropertyName(): string
{
// the name of the category property for the entity managed by this CRUDController
return 'category';
}
protected function getDefaultCategoryId(): int
{
// The id of the category that will be used as default filter for the index page of your CRUD
return $this->getCategoryRepository()->findOneBy(['parent' => null])->getId();
}
}
// src/Controller/Admin/MediaCrudController.php
namespace App\Controller\Admin;
use Umanit\EasyAdminTreeBundle\Field\TreeField;
class MediaCrudController extends AbstractCategorizedCrudController
{
public function configureFields(string $pageName): iterable
{
return [
// ...
TreeField::new('category', 'My category'),
// ...
];
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.