From 18db984057b83ca4962c89b6b79bdce6a660b58f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:42:35 +0200 Subject: Adding upstream version 2.4.0. Signed-off-by: Daniel Baumann --- .../Validator/NoDuplicateChildrenValidator.php | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php (limited to 'library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php') diff --git a/library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php b/library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php new file mode 100644 index 0000000..9676de0 --- /dev/null +++ b/library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php @@ -0,0 +1,57 @@ +form = $form; + $this->bp = $bp; + $this->parent = $parent; + + $this->_messageVariables['label'] = 'label'; + $this->_messageTemplates = [ + self::CHILD_FOUND => mt('businessprocess', '%label% is already defined in this process') + ]; + } + + public function isValid($value) + { + if ($this->parent === null) { + $found = $this->bp->hasRootNode($value); + } elseif ($this->form instanceof EditNodeForm && $this->form->getNode()->getName() === $value) { + $found = false; + } else { + $found = $this->parent->hasChild($value); + } + + if (! $found) { + return true; + } + + $this->label = $this->form->getElement('children')->getMultiOptions()[$value]; + $this->_error(self::CHILD_FOUND); + return false; + } +} -- cgit v1.2.3