Skip to content

Commit

Permalink
EV-318: Disabled edit on read-only entities
Browse files Browse the repository at this point in the history
  • Loading branch information
cableman committed Nov 27, 2023
1 parent 39e1d6a commit 37d5787
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Controller/Admin/AddressCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Entity\Address;
use Doctrine\Common\Collections\Criteria;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
Expand All @@ -26,6 +28,17 @@ public function configureCrud(Crud $crud): Crud
->setDefaultSort(['id' => Criteria::DESC]);
}

public function configureActions(Actions $actions): Actions
{
return parent::configureActions($actions)
->update(Crud::PAGE_INDEX, Action::EDIT, static function(Action $action) {
return $action->displayIf(static function (Address $address) {
return $address->isEditable();
});
})
->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureFields(string $pageName): iterable
{
return [
Expand Down
14 changes: 14 additions & 0 deletions src/Controller/Admin/EventCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Controller\Admin;

use App\Entity\Address;
use App\Entity\Event;
use Doctrine\Common\Collections\Criteria;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
Expand All @@ -28,6 +31,17 @@ public function configureCrud(Crud $crud): Crud
->setDefaultSort(['id' => Criteria::DESC]);
}

public function configureActions(Actions $actions): Actions
{
return parent::configureActions($actions)
->update(Crud::PAGE_INDEX, Action::EDIT, static function(Action $action) {
return $action->displayIf(static function (Event $event) {
return $event->isEditable();
});
})
->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureFields(string $pageName): iterable
{
return [
Expand Down
8 changes: 8 additions & 0 deletions src/Controller/Admin/FeedCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace App\Controller\Admin;

use App\Entity\Feed;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\CodeEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
Expand All @@ -18,6 +21,11 @@ public static function getEntityFqcn(): string
return Feed::class;
}

public function configureActions(Actions $actions): Actions
{
return $actions->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureFields(string $pageName): iterable
{
return [
Expand Down
15 changes: 15 additions & 0 deletions src/Controller/Admin/ImageCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace App\Controller\Admin;

use App\Entity\Event;
use App\Entity\Image;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
Expand All @@ -18,6 +22,17 @@ public static function getEntityFqcn(): string
return Image::class;
}

public function configureActions(Actions $actions): Actions
{
return parent::configureActions($actions)
->update(Crud::PAGE_INDEX, Action::EDIT, static function(Action $action) {
return $action->displayIf(static function (Image $image) {
return $image->isEditable();
});
})
->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureFields(string $pageName): iterable
{
return [
Expand Down
14 changes: 14 additions & 0 deletions src/Controller/Admin/LocationCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Controller\Admin;

use App\Entity\Image;
use App\Entity\Location;
use Doctrine\Common\Collections\Criteria;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
Expand All @@ -30,6 +33,17 @@ public function configureCrud(Crud $crud): Crud
->setDefaultSort(['id' => Criteria::DESC]);
}

public function configureActions(Actions $actions): Actions
{
return parent::configureActions($actions)
->update(Crud::PAGE_INDEX, Action::EDIT, static function(Action $action) {
return $action->displayIf(static function (Location $location) {
return $location->isEditable();
});
})
->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureFields(string $pageName): iterable
{
return [
Expand Down
14 changes: 14 additions & 0 deletions src/Controller/Admin/OccurrenceCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

namespace App\Controller\Admin;

use App\Entity\Location;
use App\Entity\Occurrence;
use Doctrine\Common\Collections\Criteria;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
Expand All @@ -26,6 +29,17 @@ public function configureCrud(Crud $crud): Crud
->setDefaultSort(['start' => Criteria::ASC]);
}

public function configureActions(Actions $actions): Actions
{
return parent::configureActions($actions)
->update(Crud::PAGE_INDEX, Action::EDIT, static function(Action $action) {
return $action->displayIf(static function (Occurrence $occurrence) {
return $occurrence->isEditable();
});
})
->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureFields(string $pageName): iterable
{
return [
Expand Down
8 changes: 8 additions & 0 deletions src/Controller/Admin/OrganizationCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace App\Controller\Admin;

use App\Entity\Organization;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
use EasyCorp\Bundle\EasyAdminBundle\Field\EmailField;
Expand All @@ -19,6 +22,11 @@ public static function getEntityFqcn(): string
return Organization::class;
}

public function configureActions(Actions $actions): Actions
{
return $actions->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureFields(string $pageName): iterable
{
return [
Expand Down
15 changes: 15 additions & 0 deletions src/Controller/Admin/TagCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

namespace App\Controller\Admin;

use App\Entity\Occurrence;
use App\Entity\Tag;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
Expand All @@ -18,6 +22,17 @@ public static function getEntityFqcn(): string
return Tag::class;
}

public function configureActions(Actions $actions): Actions
{
return parent::configureActions($actions)
->update(Crud::PAGE_INDEX, Action::EDIT, static function(Action $action) {
return $action->displayIf(static function (Tag $tag) {
return $tag->isEditable();
});
})
->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureFields(string $pageName): iterable
{
return [
Expand Down
7 changes: 7 additions & 0 deletions src/Controller/Admin/UserCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Controller\Admin;

use App\Entity\User;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
Expand Down Expand Up @@ -33,6 +35,11 @@ public static function getEntityFqcn(): string
return User::class;
}

public function configureActions(Actions $actions): Actions
{
return $actions->add(Crud::PAGE_INDEX, Action::DETAIL);
}

public function configureFields(string $pageName): iterable
{
return [
Expand Down

0 comments on commit 37d5787

Please sign in to comment.