Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ddev/example/Controller/Admin/BlogArticleCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Filter\EntityFilter;

/**
* @extends AbstractCrudController<BlogArticle>
*/
#[AdminCrud(routePath: '/blog-article')]
class BlogArticleCrudController extends AbstractCrudController
{
Expand Down
3 changes: 3 additions & 0 deletions .ddev/example/Controller/Admin/CategoryCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;

/**
* @extends AbstractCrudController<Category>
*/
#[AdminCrud(routePath: '/category')]
class CategoryCrudController extends AbstractCrudController
{
Expand Down
2 changes: 1 addition & 1 deletion doc/dashboards.rst
Original file line number Diff line number Diff line change
Expand Up @@ -982,8 +982,8 @@ user locale. You can also use ``TranslatableMessage`` objects to define any text
content in your backends (e.g. the label of some field, the help contents of
some page, etc.)::

use function Symfony\Component\Translation\t;
use Symfony\Component\Translation\TranslatableMessage;
use function Symfony\Component\Translation\t;

// creating translatable messages using objects
TextField::new('firstName', new TranslatableMessage('Name'))
Expand Down
14 changes: 14 additions & 0 deletions src/Contracts/Controller/CrudControllerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@

/**
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*
* @template TEntity of object
*/
interface CrudControllerInterface
{
/**
* @return class-string<TEntity>
*/
public static function getEntityFqcn(): string;

public function configureCrud(Crud $crud): Crud;
Expand Down Expand Up @@ -65,10 +70,19 @@ public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityD

public function createEntity(string $entityFqcn);

/**
* @param TEntity $entityInstance
*/
public function updateEntity(EntityManagerInterface $entityManager, $entityInstance): void;

/**
* @param TEntity $entityInstance
*/
public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void;

/**
* @param TEntity $entityInstance
*/
public function deleteEntity(EntityManagerInterface $entityManager, $entityInstance): void;

public function createEditFormBuilder(EntityDto $entityDto, KeyValueStore $formOptions, AdminContext $context): FormBuilderInterface;
Expand Down
5 changes: 5 additions & 0 deletions src/Contracts/Event/EntityLifecycleEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

/**
* @author: Benjamin Leibinger <mail@leibinger.io>
*
* @template TEntity of object
*/
interface EntityLifecycleEventInterface
{
/**
* @return TEntity
*/
public function getEntityInstance();
}
4 changes: 4 additions & 0 deletions src/Controller/AbstractCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@

/**
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*
* @template TEntity of object
*
* @implements CrudControllerInterface<TEntity>
*/
abstract class AbstractCrudController extends AbstractController implements CrudControllerInterface
{
Expand Down
22 changes: 22 additions & 0 deletions src/Dto/EntityDto.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,29 @@

/**
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*
* @template TEntity of object
*/
final class EntityDto
{
private bool $isAccessible = true;
/** @var class-string<TEntity> */
private string $fqcn;
/** @var ClassMetadata<TEntity> */
private ClassMetadata $metadata;
/** @var TEntity|null */
private $instance;
private $primaryKeyName;
private mixed $primaryKeyValue = null;
private string|Expression|null $permission;
private ?FieldCollection $fields = null;
private ?ActionCollection $actions = null;

/**
* @param class-string<TEntity> $entityFqcn
* @param ClassMetadata<TEntity> $entityMetadata
* @param TEntity|null $entityInstance
*/
public function __construct(string $entityFqcn, ClassMetadata $entityMetadata, string|Expression|null $entityPermission = null, /* ?object */ $entityInstance = null)
{
if (!\is_object($entityInstance)
Expand Down Expand Up @@ -61,6 +71,9 @@ public function __toString(): string
return $this->toString();
}

/**
* @return class-string<TEntity>
*/
public function getFqcn(): string
{
return $this->fqcn;
Expand All @@ -84,6 +97,9 @@ public function toString(): string
return sprintf('%s #%s', $this->getName(), substr($this->getPrimaryKeyValueAsString(), 0, 16));
}

/**
* @return TEntity|null
*/
public function getInstance()/* : ?object */
{
return $this->instance;
Expand Down Expand Up @@ -246,6 +262,9 @@ public function isEmbeddedClassProperty(string $propertyName): bool
return \array_key_exists($propertyNameParts[0], $this->metadata->embeddedClasses);
}

/**
* @param TEntity|null $newEntityInstance
*/
public function setInstance(?object $newEntityInstance): void
{
if (null !== $this->instance && null !== $newEntityInstance && !$newEntityInstance instanceof $this->fqcn) {
Expand All @@ -256,6 +275,9 @@ public function setInstance(?object $newEntityInstance): void
$this->primaryKeyValue = null;
}

/**
* @param TEntity $newEntityInstance
*/
public function newWithInstance(/* object */ $newEntityInstance): self
{
if (!\is_object($newEntityInstance)) {
Expand Down
10 changes: 10 additions & 0 deletions src/Event/AbstractLifecycleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@

/**
* @author: Benjamin Leibinger <mail@leibinger.io>
*
* @template TEntity of object
*
* @implements EntityLifecycleEventInterface<TEntity>
*/
abstract class AbstractLifecycleEvent implements EntityLifecycleEventInterface
{
/**
* @var TEntity
*/
protected $entityInstance;

/**
* @param TEntity $entityInstance
*/
public function __construct(/* ?object */ $entityInstance)
{
if (!\is_object($entityInstance)
Expand Down
2 changes: 1 addition & 1 deletion src/Security/SecurityVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;

/*
/**
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
*/
final class SecurityVoter extends Voter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\PrettyUrlsTestApplication\Entity\BlogPost;

/**
* @extends AbstractCrudController<BlogPost>
*/
class BlogPostCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Tests\PrettyUrlsTestApplication\Entity\Category;
use Symfony\Component\HttpFoundation\Response;

/**
* @extends AbstractCrudController<Category>
*/
class CategoryCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Tests\PrettyUrlsTestApplication\Entity\User;
use Symfony\Component\HttpFoundation\Response;

/**
* @extends AbstractCrudController<User>
*/
#[AdminCrud('/user-editor', 'external_user_editor')]
class UserCrudController extends AbstractCrudController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

/**
* Tests the configureActions() method and the generated actions.
*
* @extends AbstractCrudController<Category>
*/
class ActionsCrudController extends AbstractCrudController
{
Expand Down
2 changes: 2 additions & 0 deletions tests/TestApplication/src/Controller/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

/**
* Tests all the different ways of configuring asn customizing the assets.
*
* @extends AbstractCrudController<BlogPost>
*/
class AssetsController extends AbstractCrudController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost;

/**
* @extends AbstractCrudController<BlogPost>
*/
class BlogPostCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Category;
use Symfony\Component\HttpFoundation\Response;

/**
* @extends AbstractCrudController<Category>
*/
class CategoryCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost;

/**
* @extends AbstractCrudController<BlogPost>
*/
class CustomFieldAttributeCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Category;

/**
* @extends AbstractCrudController<Category>
*/
class ErrorFieldDoesNotBelongToAnyTabCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
/**
* Used to test the ->setHelp() method of fields and how that
* help message is rendered in the form.
*
* @extends AbstractCrudController<BlogPost>
*/
class FormFieldHelpController extends AbstractCrudController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

/**
* Used to test the different types of labels that fields can configure.
*
* @extends AbstractCrudController<BlogPost>
*/
class FormFieldLabelController extends AbstractCrudController
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost;

/**
* @extends AbstractCrudController<BlogPost>
*/
class FormFieldValueController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost;

/**
* @extends AbstractCrudController<BlogPost>
*/
class FormFieldsetsCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost;

/**
* @extends AbstractCrudController<BlogPost>
*/
class AnyTermsCrudSearchController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost;

/**
* @extends AbstractCrudController<BlogPost>
*/
class CustomCrudSearchController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost;

/**
* @extends AbstractCrudController<BlogPost>
*/
class DefaultCrudSearchController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\BlogPost;

/**
* @extends AbstractCrudController<BlogPost>
*/
class IdTermCrudSearchController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Bill;

/**
* @extends AbstractCrudController<Bill>
*/
class BillCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Customer;

/**
* @extends AbstractCrudController<Customer>
*/
class CustomerCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Page;

/**
* @extends AbstractCrudController<Page>
*/
class PageCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Tests\TestApplication\Entity\Website;

/**
* @extends AbstractCrudController<Website>
*/
class WebsiteCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
Expand Down