Skip to content

Commit

Permalink
permission checker - added support for callable before change value
Browse files Browse the repository at this point in the history
  • Loading branch information
janatjak committed Jul 25, 2017
1 parent 3bce3e2 commit 6c95ef1
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Model/Entity/EntityPersister.php
Expand Up @@ -44,8 +44,9 @@ public function __construct(EntityManager $entityManager, ValidatorInterface $va

/**
* @param Element $element
* @param callable|null $onBeforeValidation
*/
public function update(Element $element)
public function update(Element $element, callable $onBeforeValidation = null)
{
$key = $element->getEntityHash();
$container = $this->entityElementContainers[$key] ?? null;
Expand All @@ -60,6 +61,14 @@ public function update(Element $element)
$container->addElement($element);

$entity = $container->getEntity();

if (is_callable($onBeforeValidation)) {
$message = $onBeforeValidation($entity);
if ($message) {
$element->setError(3, $message);
}
}

$property = $element->getProperty();
$value = $element->getValue();

Expand Down

0 comments on commit 6c95ef1

Please sign in to comment.