protected function validateSubdivisions($values, AddressFormat $addressFormat, $constraint)
    {
        if ($addressFormat->getSubdivisionDepth() < 1) {
            // No predefined subdivisions exist, nothing to validate against.
            return [];
        }

        $countryCode = $addressFormat->getCountryCode();
        $subdivisionFields = $addressFormat->getUsedSubdivisionFields();
        $hiddenFields = $constraint->fieldOverrides->getHiddenFields();
        $parents = [];
        $subdivisions = [];
        foreach ($subdivisionFields as $index => $field) {
            if (empty($values[$field]) || in_array($field, $hiddenFields)) {
                // The field is empty or validation is disabled.
                break;
            }
            $parents[] = $index ? $values[$subdivisionFields[$index - 1]] : $countryCode;
            $subdivision = $this->subdivisionRepository->get($values[$field], $parents);
            if (!$subdivision) {
                $this->addViolation($field, $constraint->invalidMessage, $values[$field], $addressFormat);
                break;
            }

            $subdivisions[] = $subdivision;
            if (!$subdivision->hasChildren()) {
                // No predefined subdivisions below this level, stop here.
                break;
            }
        }

        return $subdivisions;
    }
protected function validateSubdivisions($values, AddressFormat $addressFormat, $constraint)
    {
        if ($addressFormat->getSubdivisionDepth() < 1) {
            // No predefined subdivisions exist, nothing to validate against.
            return [];
        }

        $countryCode = $addressFormat->getCountryCode();
        $subdivisionFields = $addressFormat->getUsedSubdivisionFields();
        $hiddenFields = $constraint->fieldOverrides->getHiddenFields();
        $parents = [];
        $subdivisions = [];
        foreach ($subdivisionFields as $index => $field) {
            if (empty($values[$field]) || in_array($field, $hiddenFields)) {
                // The field is empty or validation is disabled.
                break;
            }
            $parents[] = $index ? $values[$subdivisionFields[$index - 1]] : $countryCode;
            $subdivision = $this->subdivisionRepository->get($values[$field], $parents);
            if (!$subdivision) {
                $this->addViolation($field, $constraint->invalidMessage, $values[$field], $addressFormat);
                break;
            }

            $subdivisions[] = $subdivision;
            if (!$subdivision->hasChildren()) {
                // No predefined subdivisions below this level, stop here.
                break;
            }
        }

        return $subdivisions;
    }
protected function validateSubdivisions ( $ values , AddressFormat $ addressFormat , $ constraint ) { if ( $ addressFormat -> getSubdivisionDepth ( ) < 1 ) { // No predefined subdivisions exist, nothing to validate against. return [ ] ; } $ countryCode = $ addressFormat -> getCountryCode ( ) ; $ subdivisionFields = $ addressFormat -> getUsedSubdivisionFields ( ) ; $ hiddenFields = $ constraint -> fieldOverrides -> getHiddenFields ( ) ; $ parents = [ ] ; $ subdivisions = [ ] ; foreach ( $ subdivisionFields as $ index => $ field ) { if ( empty ( $ values [ $ field ] ) || in_array ( $ field , $ hiddenFields ) ) { // The field is empty or validation is disabled. break ; } $ parents [ ] = $ index ? $ values [ $ subdivisionFields [ $ index - 1 ] ] : $ countryCode ; $ subdivision = $ this -> subdivisionRepository -> get ( $ values [ $ field ] , $ parents ) ; if ( ! $ subdivision ) { $ this -> addViolation ( $ field , $ constraint -> invalidMessage , $ values [ $ field ] , $ addressFormat ) ; break ; } $ subdivisions [ ] = $ subdivision ; if ( ! $ subdivision -> hasChildren ( ) ) { // No predefined subdivisions below this level, stop here. break ; } } return $ subdivisions ; }
Validates the provided subdivision values.

@param array                   $values        The field values, keyed by field constants.
@param AddressFormat           $addressFormat The address format.
@param AddressFormatConstraint $constraint    The constraint.

@return array An array of found valid subdivisions.
Validates the provided subdivision values .