Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve forms #18

Merged
merged 3 commits into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add assertions to ensure validation
  • Loading branch information
jmsche committed Aug 24, 2021
commit 0abe6280aacb7febe32e1aa5ede477897e680db0
1 change: 1 addition & 0 deletions src/Controller/Admin/DatabaseCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ public function configureCrud(Crud $crud): Crud
->setPageTitle(Crud::PAGE_NEW, 'database.new.title')
->setEntityLabelInPlural('database.admin_label.plural')
->setEntityLabelInSingular('database.admin_label.singular')
->setFormOptions(['validation_groups' => ['Default', 'Create']], ['validation_groups' => ['Default']])
;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Controller/Admin/UserCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public function configureCrud(Crud $crud): Crud
->setPageTitle(Crud::PAGE_NEW, 'user.new.title')
->setEntityLabelInPlural('user.admin_label.plural')
->setEntityLabelInSingular('user.admin_label.singular')
;
->setFormOptions(['validation_groups' => ['Default', 'Create']], ['validation_groups' => ['Default']])
;
}

public function configureActions(Actions $actions): Actions
Expand Down
12 changes: 12 additions & 0 deletions src/Entity/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Entity(repositoryClass: DatabaseRepository::class)]
#[ORM\Table(name: '`database`')]
Expand All @@ -18,23 +19,34 @@ class Database implements \Stringable
use PrimaryKeyTrait;

#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank]
#[Assert\Length(max: 255)]
private string $host;

#[ORM\Column(type: 'integer', nullable: true)]
#[Assert\NotBlank]
#[Assert\Length(max: 255)]
private ?int $port = null;

#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank]
#[Assert\Length(max: 255)]
private string $user;

#[Assert\NotBlank(groups: ['Create'])]
private ?string $plainPassword = null;

#[ORM\Column(type: 'string', length: 255)]
private string $password;

#[ORM\Column(type: 'string', length: 255)]
#[Assert\NotBlank]
#[Assert\Length(max: 255)]
private string $name;

#[ORM\Column(type: 'integer')]
#[Assert\NotBlank]
#[Assert\Positive]
private int $maxBackups;

#[ORM\OneToMany(mappedBy: 'database', targetEntity: Backup::class, orphanRemoval: true)]
Expand Down
9 changes: 9 additions & 0 deletions src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;

#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity('email')]
class User implements UserInterface, PasswordAuthenticatedUserInterface, \Stringable
{
use PrimaryKeyTrait;
Expand All @@ -22,9 +25,14 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \String
public const ROLE_ADMIN = 'ROLE_ADMIN';

#[ORM\Column(type: Types::STRING, length: 180, unique: true)]
#[Assert\NotBlank]
#[Assert\Email]
#[Assert\Length(max: 180)]
private string $email;

#[ORM\Column(type: Types::STRING)]
#[Assert\NotBlank]
#[Assert\Choice(callback: 'getAvailableRoles')]
private string $role;

/**
Expand All @@ -33,6 +41,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, \String
#[ORM\Column(type: 'string')]
private string $password;

#[Assert\NotBlank(groups: ['Create'])]
private ?string $plainPassword = null;

#[ORM\OneToMany(mappedBy: 'owner', targetEntity: Database::class, orphanRemoval: true)]
Expand Down