public function validationAnonymous(Validator $validator)
    {
        $settings = Plugin::get('Comment')->settings;
        $validator = $this->validationDefault($validator);

        if ($settings['allow_anonymous']) {
            if ($settings['anonymous_name']) {
                $validator
                    ->requirePresence('author_name')
                    ->add('author_name', 'nameLength', [
                        'rule' => ['minLength', 3],
                        'message' => __d('comment', 'Your name need to be at least 3 characters long.'),
                    ]);

                if ($settings['anonymous_name_required']) {
                    $validator->notEmpty('author_name', __d('comment', 'You must provide your name.'));
                } else {
                    $validator->allowEmpty('author_name');
                }
            }

            if ($settings['anonymous_email']) {
                $validator
                    ->requirePresence('author_email')
                    ->add('author_email', 'validEmail', [
                        'rule' => 'email',
                        'message' => __d('comment', 'e-Mail must be valid.'),
                    ]);

                if ($settings['anonymous_email_required']) {
                    $validator->notEmpty('author_email', __d('comment', 'You must provide an email.'));
                } else {
                    $validator->allowEmpty('anonymous_email');
                }
            }

            if ($settings['anonymous_web']) {
                $validator
                    ->requirePresence('author_web')
                    ->add('author_web', 'validURL', [
                        'rule' => 'url',
                        'message' => __d('comment', 'Website must be a valid URL.'),
                    ]);

                if ($settings['anonymous_web_required']) {
                    $validator->notEmpty('author_web', __d('comment', 'You must provide a website URL.'));
                } else {
                    $validator->allowEmpty('author_web');
                }
            }
        }

        return $validator;
    }
public function validationAnonymous(Validator $validator)
    {
        $settings = Plugin::get('Comment')->settings;
        $validator = $this->validationDefault($validator);

        if ($settings['allow_anonymous']) {
            if ($settings['anonymous_name']) {
                $validator
                    ->requirePresence('author_name')
                    ->add('author_name', 'nameLength', [
                        'rule' => ['minLength', 3],
                        'message' => __d('comment', 'Your name need to be at least 3 characters long.'),
                    ]);

                if ($settings['anonymous_name_required']) {
                    $validator->notEmpty('author_name', __d('comment', 'You must provide your name.'));
                } else {
                    $validator->allowEmpty('author_name');
                }
            }

            if ($settings['anonymous_email']) {
                $validator
                    ->requirePresence('author_email')
                    ->add('author_email', 'validEmail', [
                        'rule' => 'email',
                        'message' => __d('comment', 'e-Mail must be valid.'),
                    ]);

                if ($settings['anonymous_email_required']) {
                    $validator->notEmpty('author_email', __d('comment', 'You must provide an email.'));
                } else {
                    $validator->allowEmpty('anonymous_email');
                }
            }

            if ($settings['anonymous_web']) {
                $validator
                    ->requirePresence('author_web')
                    ->add('author_web', 'validURL', [
                        'rule' => 'url',
                        'message' => __d('comment', 'Website must be a valid URL.'),
                    ]);

                if ($settings['anonymous_web_required']) {
                    $validator->notEmpty('author_web', __d('comment', 'You must provide a website URL.'));
                } else {
                    $validator->allowEmpty('author_web');
                }
            }
        }

        return $validator;
    }
public function validationAnonymous ( Validator $ validator ) { $ settings = Plugin :: get ( 'Comment' ) -> settings ; $ validator = $ this -> validationDefault ( $ validator ) ; if ( $ settings [ 'allow_anonymous' ] ) { if ( $ settings [ 'anonymous_name' ] ) { $ validator -> requirePresence ( 'author_name' ) -> add ( 'author_name' , 'nameLength' , [ 'rule' => [ 'minLength' , 3 ] , 'message' => __d ( 'comment' , 'Your name need to be at least 3 characters long.' ) , ] ) ; if ( $ settings [ 'anonymous_name_required' ] ) { $ validator -> notEmpty ( 'author_name' , __d ( 'comment' , 'You must provide your name.' ) ) ; } else { $ validator -> allowEmpty ( 'author_name' ) ; } } if ( $ settings [ 'anonymous_email' ] ) { $ validator -> requirePresence ( 'author_email' ) -> add ( 'author_email' , 'validEmail' , [ 'rule' => 'email' , 'message' => __d ( 'comment' , 'e-Mail must be valid.' ) , ] ) ; if ( $ settings [ 'anonymous_email_required' ] ) { $ validator -> notEmpty ( 'author_email' , __d ( 'comment' , 'You must provide an email.' ) ) ; } else { $ validator -> allowEmpty ( 'anonymous_email' ) ; } } if ( $ settings [ 'anonymous_web' ] ) { $ validator -> requirePresence ( 'author_web' ) -> add ( 'author_web' , 'validURL' , [ 'rule' => 'url' , 'message' => __d ( 'comment' , 'Website must be a valid URL.' ) , ] ) ; if ( $ settings [ 'anonymous_web_required' ] ) { $ validator -> notEmpty ( 'author_web' , __d ( 'comment' , 'You must provide a website URL.' ) ) ; } else { $ validator -> allowEmpty ( 'author_web' ) ; } } } return $ validator ; }
Validation rules when editing a comment in backend.

@param \Cake\Validation\Validator $validator The validator object
@return \Cake\Validation\Validator
Validation rules when editing a comment in backend .