mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 09:35:49 +02:00
Validate that a parts name fullfills the regular expression set in a category
This commit is contained in:
parent
58105575d3
commit
22950f2476
5 changed files with 40 additions and 1 deletions
|
@ -41,6 +41,7 @@ use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
||||||
use Symfony\Component\Validator\Constraints as Assert;
|
use Symfony\Component\Validator\Constraints as Assert;
|
||||||
|
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Part class.
|
* Part class.
|
||||||
|
@ -147,4 +148,23 @@ class Part extends AttachmentContainingDBElement
|
||||||
}
|
}
|
||||||
parent::__clone();
|
parent::__clone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Assert\Callback
|
||||||
|
*/
|
||||||
|
public function validate(ExecutionContextInterface $context, $payload)
|
||||||
|
{
|
||||||
|
//Ensure that the part name fullfills the regex of the category
|
||||||
|
if ($this->category) {
|
||||||
|
$regex = $this->category->getPartnameRegex();
|
||||||
|
if (!empty($regex)) {
|
||||||
|
if (!preg_match($regex, $this->name)) {
|
||||||
|
$context->buildViolation('part.name.must_match_category_regex')
|
||||||
|
->atPath('name')
|
||||||
|
->setParameter('%regex%', $regex)
|
||||||
|
->addViolation();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ class CategoryAdminForm extends BaseEntityAdminForm
|
||||||
'required' => false,
|
'required' => false,
|
||||||
'empty_data' => '',
|
'empty_data' => '',
|
||||||
'label' => 'category.edit.partname_regex',
|
'label' => 'category.edit.partname_regex',
|
||||||
|
'help' => 'category.edit.partname_regex.help',
|
||||||
'attr' => [
|
'attr' => [
|
||||||
'placeholder' => 'category.edit.partname_regex.placeholder',
|
'placeholder' => 'category.edit.partname_regex.placeholder',
|
||||||
],
|
],
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
{% if part.category is not null and part.category.partnameHint is not empty %}
|
{% if part.category is not null and part.category.partnameHint is not empty %}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-9 offset-sm-3">
|
<div class="col-sm-9 offset-sm-3">
|
||||||
<p class="text-muted"><b>{% trans %}part.edit.name.category_hint{% endtrans %}:</b> {{ part.category.partnameHint }}</p>
|
<p class="form-text help-text"><b>{% trans %}part.edit.name.category_hint{% endtrans %}:</b> {{ part.category.partnameHint }}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
|
@ -10401,5 +10401,17 @@ Element 3</target>
|
||||||
<target>Hint from category</target>
|
<target>Hint from category</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="_vbPEFP" name="category.edit.partname_regex.placeholder">
|
||||||
|
<segment>
|
||||||
|
<source>category.edit.partname_regex.placeholder</source>
|
||||||
|
<target>e.g "/Capacitor \d+ nF/i"</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="QFgP__5" name="category.edit.partname_regex.help">
|
||||||
|
<segment>
|
||||||
|
<source>category.edit.partname_regex.help</source>
|
||||||
|
<target>A PCRE-compatible regular expression, which a part name have to match.</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
|
@ -293,5 +293,11 @@
|
||||||
<target>You have selected less quantity to withdraw than needed for the build! Add additional quantity.</target>
|
<target>You have selected less quantity to withdraw than needed for the build! Add additional quantity.</target>
|
||||||
</segment>
|
</segment>
|
||||||
</unit>
|
</unit>
|
||||||
|
<unit id="G9ZKt.4" name="part.name.must_match_category_regex">
|
||||||
|
<segment>
|
||||||
|
<source>part.name.must_match_category_regex</source>
|
||||||
|
<target>The part name does not match the regular expression stated by the category: %regex%</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
</file>
|
</file>
|
||||||
</xliff>
|
</xliff>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue