Default validation rules.

@param \Cake\Validation\Validator $validator The validator object
@return \Cake\Validation\Validator
490209
public function validationDefault(Validator $validator)
    {
        return $validator
            ->add('theme', 'validTheme', [
                'rule' => function ($value, $context) {
                    $exists = plugin()
                        ->filter(function ($plugin) use ($value) {
                            return $plugin->isTheme && $plugin->name === $value;
                        })
                        ->first();

                    return !empty($exists);
                },
                'message' => __d('block', 'Invalid theme for region.'),
            ]);
    }
1368747
protected function _addValidatorProps($validator = [])
    {
        foreach ($validator as $key => $value) {
            if (!isset($value) || empty($value)) {
                continue;
            }
            if ($key === 'rule' && is_array($value) && !is_callable($value)) {
                $this->_pass = array_slice($value, 1);
                $value = array_shift($value);
            }
            if (in_array($key, ['rule', 'on', 'message', 'last', 'provider', 'pass'])) {
                $this->{"_$key"} = $value;
            }
        }
    }
316143
protected function validationOldPassword($validator) {
		$validator->setProvider('userBehavior', $this);
		$validator->setProvider('userTable', $this->_table);

		$validator->add('old_password', 'notBlank', [
			'rule' => 'notBlank',
			'message' => __d('user_tools', 'Enter your old password.')
		]);
		$validator->add('old_password', 'oldPassword', [
			'rule' => ['validateOldPassword', 'password'],
			'provider' => 'userBehavior',
			'message' => __d('user_tools', 'Wrong password, please try again.')
		]);

		return $validator;
	}
337711
public function validationDefault(Validator $validator)
    {
        $validator
            ->notEmpty('handler', __d('field', 'Invalid field type.'))
            ->add('label', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('field', 'You need to provide a label.'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('field', 'Label need to be at least 3 characters long'),
                ],
            ]);

        return $validator;
    }
58819
public function validationDoNotRequirePresence(UserValidator $validator)
    {
        //No field is required
        foreach ($validator->getIterator() as $field => $rules) {
            $validator->requirePresence($field, false);
        }

        return $validator;
    }
129545
private static function applyValidatorRules($validator, array &$rules)
    {
        $validatorRule = ValidatorRule::getInstance();
        foreach ($rules as $rule) {
            list($functionName, $arguments) = $validatorRule->parseRule($validator, $rule);
            $validator = \call_user_func_array([$validator, $functionName], $arguments);
        }

        return $validator;
    }
499960
protected function useValidator(Validator $validator)
    {
        if ($validator !== $this->validator9) {
            return true;

        }
        $set1 = substr($this->account, 0, 2);
        $set2 = substr($this->account, 0, 3);
        return ($set1 >= 51  && $set1 <= 59)
            || ($set2 >= 901 && $set2 <= 910);
    }
176218
protected function getValidatorInstance(): Validator
    {
        $factory = $this->container->make(ValidationFactory::class);

        if (method_exists($this, 'validator')) {
            $validator = $this->container->call([$this, 'validator'], compact('factory'));
        } else {
            $validator = $this->createDefaultValidator($factory);
        }

        if (method_exists($this, 'withValidator')) {
            $this->withValidator($validator);
        }

        return $validator;
    }
721552
public function validationEnabled(Validator $validator) : Validator
    {
        $className = App::shortName(get_class($this), 'Model/Table', 'Table');
        $config = (new ModuleConfig(ConfigType::MIGRATION(), $className))->parse();
        $config = json_encode($config);
        if (false === $config) {
            return $validator;
        }
        $config = json_decode($config, true);
        $factory = new FieldHandlerFactory();

        foreach ($config as $column) {
            $validator = $factory->setValidationRules($this, $column['name'], $validator);
        }

        return $validator;
    }
21154
public function validate($validator)
    {
        // Validate currency
        $currencies = $this->getAllowedCurrencies();
        $currency = $this->fieldCurrency->dataValue();
        if ($currency && $currencies && !in_array($currency, $currencies)) {
            $validator->validationError(
                $this->getName(),
                _t(
                    __CLASS__ . '.INVALID_CURRENCY',
                    'Currency {currency} is not in the list of allowed currencies',
                    ['currency' => $currency]
                )
            );
            return false;
        }

        // Field-specific validation
        return $this->fieldAmount->validate($validator) && $this->fieldCurrency->validate($validator);
    }
433689
public function validationDefault(Validator $validator): \Cake\Validation\Validator
    {
        $validator->add('data', 'custom', [
            'rule' => function ($value, $context) {
                if ($context['data']['action'] != ModelHistory::ACTION_COMMENT) {
                    return true;
                }

                return !empty($value['comment']);
            },
            'message' => __d('model_history', 'comment_empty')
        ]);

        return $validator;
    }
423609
public function validationDefault(Validator $validator) {
		$validator
			->integer('id')
			->allowEmpty('id', 'create');

		$validator
			->requirePresence('ip', 'create')
			->notEmpty('ip');

		$validator
			->requirePresence('session_id', 'create')
			->notEmpty('session_id');

		$validator
			->allowEmpty('result');

		$validator
			->dateTime('used')
			->allowEmpty('used');

		return $validator;
	}
596813
public function validationDefault(Validator $validator) {
		$validator
			->integer('id')
			->allowEmpty('id', 'create');

		$validator
			->requirePresence('address', 'create')
			->notEmpty('address')
			->add('address', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']);

		$validator
			->allowEmpty('formatted_address');

		$validator
			->allowEmpty('country');

		$validator
			->decimal('lat')
			->allowEmpty('lat');

		$validator
			->decimal('lng')
			->allowEmpty('lng');

		$validator
			->allowEmpty('data');

		return $validator;
	}
1202754
public function validate(Validator $validator)
    {
        $handler = $this->get('metadata')->get('handler');
        if (class_exists($handler)) {
            $handler = new $handler();

            return $handler->validate($this, $validator);
        }
    }
365749
protected function _setValidator($validator)
    {
        if (!is_null($validator) && !($validator instanceof ValidatorInterface)) {
            throw $this->_createInvalidArgumentException($this->__('Invalid validator'), null, null, $validator);
        }

        $this->validator = $validator;
    }
91560
public static function validator($validator = null)
    {
        if (func_num_args()) {
            static::$_validators[static::class] = $validator;
            return;
        }
        $self = static::class;
        if (isset(static::$_validators[$self])) {
            return static::$_validators[$self];
        }
        $class = static::$_classes['validator'];
        $validator = static::$_validators[$self] = new $class();
        static::_rules($validator);
        return $validator;
    }
73286
protected function registerValidationRules($validator)
    {
        /**
         * elfinder validator
         */
        $validator->resolver(function($translator, $data, $rules, $messages)
        {
            return new BaseValidator($translator, $data, $rules, $messages);
        });
        $validator->replacer('elfinder_max', function($message, $attribute, $rule, $parameters) {
            return str_replace(':size',$parameters[0],$message);
        });
        $validator->replacer('elfinder', function($message, $attribute, $rule, $parameters) {
            return str_replace(':values',implode(', ', $parameters),$message);
        });

    }