Show error, if null category is assigned to part.

Fixes issue #42.
This commit is contained in:
Jan Böhmer 2020-05-17 21:13:46 +02:00
parent 4f70e9fe5a
commit be47680b60
4 changed files with 18 additions and 1 deletions

View file

@ -46,6 +46,7 @@ use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint; use App\Entity\Parts\Footprint;
use App\Security\Annotations\ColumnSecurity; use App\Security\Annotations\ColumnSecurity;
use App\Validator\Constraints\Selectable; use App\Validator\Constraints\Selectable;
use Symfony\Component\Validator\Constraints as Assert;
trait BasicPropertyTrait trait BasicPropertyTrait
{ {
@ -83,6 +84,7 @@ trait BasicPropertyTrait
* @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false) * @ORM\JoinColumn(name="id_category", referencedColumnName="id", nullable=false)
* @ColumnSecurity(prefix="category", type="App\Entity\Parts\Category") * @ColumnSecurity(prefix="category", type="App\Entity\Parts\Category")
* @Selectable() * @Selectable()
* @Assert\NotNull(message="validator.select_valid_category")
*/ */
protected $category; protected $category;
@ -196,7 +198,7 @@ trait BasicPropertyTrait
* *
* @return $this * @return $this
*/ */
public function setCategory(Category $category): self public function setCategory(?Category $category): self
{ {
$this->category = $category; $this->category = $category;

View file

@ -131,6 +131,9 @@ class PartBaseType extends AbstractType
'label' => 'part.edit.category', 'label' => 'part.edit.category',
'disable_not_selectable' => true, 'disable_not_selectable' => true,
'disabled' => ! $this->security->isGranted('category.edit', $part), 'disabled' => ! $this->security->isGranted('category.edit', $part),
'constraints' => [
]
]) ])
->add('footprint', StructuralEntityType::class, [ ->add('footprint', StructuralEntityType::class, [
'class' => Footprint::class, 'class' => Footprint::class,

View file

@ -167,5 +167,11 @@
<target>Der Benutzername darf nur Buchstaben, Zahlen, Unterstriche, Punkte, Plus- oder Minuszeichen enthalten.</target> <target>Der Benutzername darf nur Buchstaben, Zahlen, Unterstriche, Punkte, Plus- oder Minuszeichen enthalten.</target>
</segment> </segment>
</unit> </unit>
<unit id="ayNr6QK" name="validator.select_valid_category">
<segment>
<source>validator.select_valid_category</source>
<target>Bitte wählen Sie eine gültige Kategorie.</target>
</segment>
</unit>
</file> </file>
</xliff> </xliff>

View file

@ -185,5 +185,11 @@
<target>You can not assign children element as parent (This would cause loops).</target> <target>You can not assign children element as parent (This would cause loops).</target>
</segment> </segment>
</unit> </unit>
<unit id="ayNr6QK" name="validator.select_valid_category">
<segment>
<source>validator.select_valid_category</source>
<target>Please select a valid category!</target>
</segment>
</unit>
</file> </file>
</xliff> </xliff>