Default validation rules.

@param \Cake\Validation\Validator $validator Validator instance.
@return \Cake\Validation\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;
	}
1334453
public function validationDefault(Validator $validator)
    {
        return $validator
            ->requirePresence('enable_caching', true, __d('wasabi_core', 'Please select a cache status.'))
            ->add('enable_caching', 'inList', [
                'rule' => ['inList', ['0', '1']],
                'message' => __d('wasabi_core', 'Please select a valid cache status.')
            ])
            ->requirePresence('cache_duration', true, __d('wasabi_core', 'Please select a cache duration.'))
            ->add('cache_duration', 'custom', [
                'rule' => function ($value, $context) {
                    return in_array($value, $this->cacheDurations);
                },
                'message' => __d('wasabi_core', 'Please select a valid cache duration.')
            ]);
    }
1309498
public function setValidator(Validator $validator)
    {
        if ($validator) {
            $this->validator = $validator;
            $this->validator->setForm($this);
        }
        return $this;
    }
674170
public function validationDefault(Validator $validator)
    {
        $validator
            ->add('id', 'valid', ['rule' => 'numeric'])
            ->allowEmpty('id', 'create')
            ->add('email', 'valid', ['rule' => 'email'])
            ->requirePresence('email', 'create')
            ->notEmpty('email')
            ->add('email', 'unique', ['rule' => 'validateUnique', 'provider' => 'table'])
            ->notEmpty('password');

        $validator->add('new_password', 'custom', [
            'rule' => function ($value, $context) {
                if ($value !== $context['data']['confirm_password']) {
                    return false;
                }
                return true;
            },
            'message' => __('Passwords are not equal!'),
        ]);

        $validator->add('confirm_password', 'custom', [
            'rule' => function ($value, $context) {
                if ($value !== $context['data']['new_password']) {
                    return false;
                }
                return true;
            },
            'message' => __('Passwords are not equal.'),
        ]);


        return $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.'),
            ]);
    }
338535
public function validationDefault(Validator $validator)
    {
        $validator
            ->uuid('id')
            ->allowEmpty('id', 'create');

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

        $validator
            ->scalar('response_status')
            ->maxLength('response_status', 255)
            ->allowEmpty('response_status');

        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);
        }
    }
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);
    }
1260119
public function addValidator($validator)
    {
        if (!$validator instanceof ValidatorInterface) {
            if (!is_callable($validator)) {
                throw new \InvalidArgumentException('Validator should be callable or ValidatorInterface.');
            }

            $validator = new CallbackValidator($validator);
        }

        $this->validators[] = $validator;

        return $this;
    }
104671
public function setValidationRules(Validator $validator, array $options = []) : Validator
    {
        $options = array_merge($this->defaultOptions, $this->fixOptions($options));

        $provider = $this->config->getProvider('validationRules');
        $validator = (new $provider($this->config))->provide($validator, $options);
        if (! $validator instanceof Validator) {
            throw new RuntimeException(
                sprintf('Provider returned value must be an instance of %s.', Validator::class)
            );
        }

        return $validator;
    }
925890
public function setValidator($validator)
    {
        if (!($validator instanceof AnDomainValidatorAbstract)) {
            if (is_string($validator) && strpos($validator, '.') === false) {
                $identifier = clone $this->getIdentifier();
                $identifier->path = array('domain','validator');
                $identifier->name = $validator;
            } else {
                $identifier = $this->getIdentifier($validator);
            }

            register_default(array('identifier' => $identifier, 'prefix' => $this->_repository->getClone()));

            $validator = $identifier;
        }

        $this->_validator = $validator;

        return $this;
    }
322219
public function validate(Validator $validator = null)
    {
        if (null === $validator) {
            $validator = new Validator(new ClassMetadataFactory(new StaticMethodLoader()), new ConstraintValidatorFactory(), new DefaultTranslator());
        }

        $failureMap = new ConstraintViolationList();

        if (!$this->alreadyInValidation) {
            $this->alreadyInValidation = true;
            $retval = null;


            $retval = $validator->validate($this);
            if (count($retval) > 0) {
                $failureMap->addAll($retval);
            }

            if (null !== $this->collAttributeAttributeTypes) {
                foreach ($this->collAttributeAttributeTypes as $referrerFK) {
                    if (method_exists($referrerFK, 'validate')) {
                        if (!$referrerFK->validate($validator)) {
                            $failureMap->addAll($referrerFK->getValidationFailures());
                        }
                    }
                }
            }
            if (null !== $this->collAttributeTypeI18ns) {
                foreach ($this->collAttributeTypeI18ns as $referrerFK) {
                    if (method_exists($referrerFK, 'validate')) {
                        if (!$referrerFK->validate($validator)) {
                            $failureMap->addAll($referrerFK->getValidationFailures());
                        }
                    }
                }
            }

            $this->alreadyInValidation = false;
        }

        $this->validationFailures = $failureMap;

        return (Boolean) (!(count($this->validationFailures) > 0));

    }
774295
public function validationDefault(Validator $validator)
    {
        $validator
            ->allowEmpty('url')
            ->add('url', 'checkUrl', [
                'rule' => function ($url, $context) {
                    $plainString = (
                        strpos($url, 'javascript:') === 0 ||
                        strpos($url, 'mailto:') === 0 ||
                        strpos($url, 'tel:') === 0 ||
                        strpos($url, 'sms:') === 0 ||
                        strpos($url, '#') === 0 ||
                        strpos($url, '?') === 0 ||
                        strpos($url, '//') === 0 ||
                        strpos($url, '://') !== false
                    );

                    if ($plainString) {
                        return true;
                    } else {
                        $full = Validation::url($url);
                        $internal = str_starts_with($url, '/');

                        return $full || $internal;
                    }
                },
                'message' => __d('menu', 'Invalid URL. Internal links must start with "/", e.g. "/article-my-first-article{0}"', CONTENT_EXTENSION),
                'provider' => 'table',
            ])
            ->requirePresence('title')
            ->add('title', [
                'notBlank' => [
                    'rule' => 'notBlank',
                    'message' => __d('menu', 'You need to provide a title.'),
                ],
                'length' => [
                    'rule' => ['minLength', 3],
                    'message' => __d('menu', 'Title need to be at least 3 characters long.'),
                ],
            ])
            ->add('activation', 'validActivation', [
                'rule' => function ($value, $context) {
                    return in_array($value, ['auto', 'any', 'none', 'php']);
                },
                'message' => __d('menu', 'Please select an activation method.'),
                'provider' => 'table',
            ])
            ->allowEmpty('active')
            ->add('active', 'validPHP', [
                'rule' => function ($value, $context) {
                    if (!empty($context['data']['activation']) && $context['data']['activation'] === 'php') {
                        return strpos($value, '<?php') !== false && strpos($value, '?>') !== false;
                    }

                    return true;
                },
                'message' => __d('menu', 'Invalid PHP code, make sure that tags "&lt;?php" & "?&gt;" are present.')
            ]);

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

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

        $validator
            ->allowEmpty('url');

        $validator
            ->boolean('new_window')
            ->allowEmpty('new_window');

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

        $validator
            ->allowEmpty('icon');

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

        return $validator;
    }
792014
public function validationDefault(Validator $validator) : Validator
    {
        // configurable in config/csv_migrations.php
        if (! Configure::read('CsvMigrations.tableValidation')) {
            return $validator;
        }

        return $this->validationEnabled($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;
    }
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;
            }
        }
    }