Validates that guide is fully completed and contains valid grade on each criterion

@param array $elementvalue value of element as came in form submit
@return boolean true if the form data is validated and contains no errors
359079
public function validate_grading_element($elementvalue) {
        $criteria = $this->get_controller()->get_definition()->guide_criteria;
        if (!isset($elementvalue['criteria']) || !is_array($elementvalue['criteria']) ||
            count($elementvalue['criteria']) < count($criteria)) {
            return false;
        }
        // Reset validation errors.
        $this->validationerrors = null;
        foreach ($criteria as $id => $criterion) {
            if (!isset($elementvalue['criteria'][$id]['score'])
                    || $criterion['maxscore'] < $elementvalue['criteria'][$id]['score']
                    || !is_numeric($elementvalue['criteria'][$id]['score'])
                    || $elementvalue['criteria'][$id]['score'] < 0) {
                $this->validationerrors[$id]['score'] = $elementvalue['criteria'][$id]['score'];
            }
        }
        if (!empty($this->validationerrors)) {
            return false;
        }
        return true;
    }
763016
private function getDefaultValue($element)
    {
        if (!$name = $element->getName()) {
            return false;
        }

        if (is_null($element->getValue())) {
            return false;
        }

        $userInput = $element->getValue();

        list($valid, $elementValue) = $this->validateValue($element, $userInput);
        $this->storeValue($name, $valid, $userInput, $elementValue);

        return true;
    }
1043474
public function matches($expectedvalue) {

        $multiple = $this->field->hasAttribute('multiple');

        // Same implementation as the parent if it is a single select.
        if (!$multiple) {
            $cleanexpectedvalue = trim($expectedvalue);
            $selectedtext = trim($this->get_selected_options());
            $selectedvalue = trim($this->get_selected_options(false));
            if ($cleanexpectedvalue != $selectedvalue && $cleanexpectedvalue != $selectedtext) {
                return false;
            }
            return true;
        }

        // We are dealing with a multi-select.

        // Unescape + trim all options and flip it to have the expected values as keys.
        $expectedoptions = $this->get_unescaped_options($expectedvalue);

        // Get currently selected option's texts.
        $texts = $this->get_selected_options(true);
        $selectedoptiontexts = $this->get_unescaped_options($texts);

        // Get currently selected option's values.
        $values = $this->get_selected_options(false);
        $selectedoptionvalues = $this->get_unescaped_options($values);

        // We check against string-ordered lists of options.
        if ($expectedoptions !== $selectedoptiontexts &&
                $expectedoptions !== $selectedoptionvalues) {
            return false;
        }

        return true;
    }
786630
protected function validateElementWithKeys(
        SignedElement $element,
        \SAML2\Utilities\ArrayCollection $pemCandidates
    ) : bool {
        $lastException = null;
        foreach ($pemCandidates as $index => $candidateKey) {
            $key = new XMLSecurityKey(XMLSecurityKey::RSA_SHA256, ['type' => 'public']);
            $key->loadKey($candidateKey->getCertificate());

            try {
                /*
                 * Make sure that we have a valid signature on either the response or the assertion.
                 */
                $result = $element->validate($key);
                if ($result) {
                    $this->logger->debug(sprintf('Validation with key "#%d" succeeded', $index));
                    return true;
                }
                $this->logger->debug(sprintf('Validation with key "#%d" failed without exception.', $index));
            } catch (\Exception $e) {
                $this->logger->debug(sprintf(
                    'Validation with key "#%d" failed with exception: %s',
                    $index,
                    $e->getMessage()
                ));

                $lastException = $e;
            }
        }

        if ($lastException !== null) {
            throw $lastException;
        } else {
            return false;
        }
    }
5477
public function valid() : bool
    {
        if ($this->privateErrors()) {
            return false;
        }
        foreach ((array)$this as $element) {
            if (is_string($element)) {
                continue;
            }
            if (!$element->getElement()->valid()) {
                return false;
            }
        }
        return true;
    }
728220
private function _validateFieldValueArray($aFieldValues)
    {
        $blValid = true;
        foreach ($aFieldValues as $sValue) {
            if (!trim($sValue)) {
                $blValid = false;
                break;
            }
        }

        return $blValid;
    }
115391
public function hasValidationErrors(FormRuntime $formRuntime, RootRenderableInterface $element): bool
    {
        return $this->getValidationResult($formRuntime, $element)->hasErrors();
    }
693240
public function validateForm(array $input, $early_exit = false)
    {
        $result = new Result($input);
        foreach ($this->rules as $name => $rules) {
            //skip a value if it is not required...
            if (!isset($this->required[$name])) {
                //and not submitted.
                //here 'submitted' means either not existing or failing submitted()
                if (!isset($input[$name]) || !$this->submitted($input[$name])) {
                    continue;
                }
            }
            $this->doValidation($result, $input, $name, $rules, $early_exit);
        }

        return $result;
    }
403434
protected function vaidateValue($value, $element)
    {
        $return = !empty($value['tmp_name']) && !empty($value['name']) && empty($value['error']);
        if ($return && $this->getExtensions()) {
            $ext = mb_strtolower(pathinfo($value['name'], PATHINFO_EXTENSION));
            $return = in_array($ext, array_map('mb_strtolower', $this->getExtensions()));
        }
        if ($return && $this->getMimes()) {
            $mime = extension_loaded('fileinfo') ? mime_content_type($value['tmp_name']) : $value['type'];
            $return = in_array($mime, $this->getMimes());
        }
        if ($return && $this->getMaxSize()) {
            $size = filesize($value['tmp_name']);
            $return = $size <= $this->getMaxSize();
        }

        return $return;
    }
841153
private function loadValidatorElement(array &$property, ElementItem $element)
    {
        /* @var $element Element */
        $type = $element->getType();

        $attrs = [];
        $arrayized = strpos($property['type'], 'array<') === 0;

        if ($arrayized) {
            if ($itemOfArray = $this->isArrayNestedElement($type)) {
                $attrs = [
                    'min' => min($element->getMin(), $itemOfArray->getMin()),
                    'max' => $itemOfArray->getMax()
                ];
            }  elseif ($itemOfArray = $this->isArrayType($type)) {
                $attrs = [
                    'min' => min($element->getMin(), $itemOfArray->getMin()),
                    'max' => $itemOfArray->getMax()
                ];
            } elseif ($this->isArrayElement($element)) {
//                $attrs = [
//                    'min' => $element->getMin(),
//                    'max' => $element->getMax()
//                ];
            }
        }

        if (isset($attrs['min']) && $attrs['min'] === 0) {
            unset($attrs['min']);
        }
        if (isset($attrs['max']) && $attrs['max'] === -1) {
            unset($attrs['max']);
        }

        $rules = $this->loadValidatorType($property, $type, $arrayized );


        if ($element->getMin() > 0) {
            $property['validation'][] = [
                'NotNull' => null
            ];
        }

        if ($arrayized && count($attrs) > 0) {
            $property['validation'][] = [
                 'Count' => $attrs
            ];
        }
        if ($arrayized && count($rules) > 0) {
//            $rules[] = ['Valid' => null];
            $property['validation'][] = [
                'All' => ['constraints' => $rules]
            ];
        } elseif ($type instanceof ComplexType) {
            $property['validation'][] = [
                'Valid' => null
            ];
        }
    }
462635
public function isValid($mixValue){
		if(is_null($mixValue)){
			return true;
		}

		if(is_object($mixValue)){
			if($mixValue instanceof \DateTime){
				return true;
			}else{
				throw new ClassException($mixValue, '\DateTime');
				return false;
			}
		}

		if(is_string($mixValue)){
			try{
				$objTest = new \DateTime($mixValue);
				return true;
			}catch (\Exception $e){
				throw new TypeException($mixValue, get_class($this));
			}
		}

		return false;
	}
968746
public static function validateEntityAutocomplete(array &$element, FormStateInterface $form_state, array &$complete_form) {
    $duplicated_values = $value = [];

    // Load the current Event enrollments so we can check duplicates.
    $storage = \Drupal::entityTypeManager()->getStorage('event_enrollment');

    if (empty($nid)) {
      $node = \Drupal::routeMatch()->getParameter('node');
      if ($node instanceof NodeInterface) {
        // You can get nid and anything else you need from the node object.
        $nid = $node->id();
      }
      elseif (!is_object($node)) {
        $nid = $node;
      }
    }

    // Grab all the input values so we can get the ID's out of them.
    $input_values = Tags::explode($element['#value']);
    foreach ($input_values as $input) {
      $match = static::extractEntityIdFromAutocompleteInput($input);
      if ($match === NULL) {
        $options = $element['#selection_settings'] + [
          'target_type' => $element['#target_type'],
          'handler' => $element['#selection_handler'],
        ];

        /* @var /Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface $handler */
        $handler = \Drupal::service('plugin.manager.entity_reference_selection')->getInstance($options);
        $autocreate = (bool) $element['#autocreate'] && $handler instanceof SelectionWithAutocreateInterface;
        // Try to get a match from the input string when the user didn't use
        // the autocomplete but filled in a value manually.
        // Got this from the parent::validateEntityAutocomplete.
        $match = static::matchEntityByTitle($handler, $input, $element, $form_state, !$autocreate);
      }

      if ($match !== NULL) {
        $value[$match] = [
          'target_id' => $match,
        ];

        $enrollments = $storage->loadByProperties(['field_event' => $nid, 'field_account' => $match]);

        // User is already a member, add it to an array for the Form element
        // to render an error after all checks are gone.
        if (!empty($enrollments)) {
          $duplicated_values[] = $input;
        }

        // Validate input for every single user. This way we make sure that
        // The element validates one, or more users added in the autocomplete.
        // This is because we don't allow adding multiple users at once,
        // so we need to validate single users, if they all pass we can add
        // them all in the _social_group_action_form_submit.
        parent::validateEntityAutocomplete($element, $form_state, $complete_form);
      }
    }

    // If we have duplicates, provide an error message.
    if (!empty($duplicated_values)) {
      $usernames = implode(', ', $duplicated_values);

      $message = \Drupal::translation()->formatPlural(count($duplicated_values),
        "@usernames is already enrolled, you can't add them again",
        "@usernames are already enrolled, you can't add them again",
        ['@usernames' => $usernames]
      );

      // We have to kick in a form set error here, or else the
      // GroupContentCardinalityValidator will kick in and show a faulty
      // error message. Alter this later when Group supports multiple members.
      $form_state->setError($element, $message);
      return;
    }

    if ($value) {
      $form_state->setValue('entity_id_new', $value);
      $form_state->setValue('node_id', $nid);
    }
  }
42497
private function validate($element)
    {
        $violationList = $this->validator->validate($element, null, ['Generator']);
        if (0 < $violationList->count()) {
            $this->output->writeln('<error>Invalid element</error>');
            /** @var \Symfony\Component\Validator\ConstraintViolationInterface $violation */
            foreach ($violationList as $violation) {
                $this->output->writeln(sprintf('<error>%s : %s</error>', $violation->getPropertyPath(), $violation->getMessage()));
            }

            return false;
        }

        return true;
    }
991711
public function contains($element)
    {
        $hashIndex = $this->hashIndex($element);

        if (array_key_exists($hashIndex, $this->_items)) {
            return true;
        }
        return false;
    }
800549
protected function isNodeChoiceAttribute($attributeValue)
    {
        return is_array($attributeValue)
        && (
            array_key_exists('contentNodeId', $attributeValue) ||
            array_key_exists('nodeName', $attributeValue) ||
            array_key_exists('nodeToLink', $attributeValue)
        );
    }
64681
public function valid(array $values, $populate = true)
    {
        foreach($this->getElements() as $index => &$element) {
            if(!array_key_exists($index, $values)) {
                if(is_a($element, 'FrenchFrogs\Form\Element\Boolean')){
                    $values[$index] = 0;
                } else {
                    $values[$index] = '';
                }
            }

            $element->valid($values[$index]);

            if (!$element->isValid()) {
                $this->getValidator()->addError($index, $element->getErrorAsString());
            }

        }

        return $this;
    }
209496
function (element) {
            // Begin with checking the validate
            var elementAsArray = [ element ],
                validationType = element.getAttribute("data-validate") || null;
                invalidElement = [];
            if (validationType !== null) {
                validationType = this.splitStringByComma(validationType);
                for (var i = 0; i < validationType.length; i++) {
                    invalidElement = this.getElementsByPattern(elementAsArray, this.patterns[validationType[i]], validationType[i]);
                    if (invalidElement.length > 0) {
                        this.currentValidationType = validationType[i];
                        return false;
                    }
                }
            }
            // As data-validate="length" has already been checked,
            // only check the elements with data-length set.
            if (element.getAttribute("data-length") === null ||
                validationType !== null && validationType.indexOf("length") !== -1)
                return true;
            validationType = "length";
            invalidElement = this.getElementsByPattern(elementAsArray, this.patterns[validationType], validationType);
            if (invalidElement.length > 0)
                return false;

            return true;
        }