original_string: public function validationDefault(Validator $validator)
      {
          $validator
              ->add('subject', [
                  'notBlank' => [
                      'rule' => 'notBlank',
                      'message' => __d('comment', 'You need to provide a comment subject.'),
                  ],
                  'length' => [
                      'rule' => ['minLength', 5],
                      'message' => 'Comment subject need to be at least 5 characters long',
                  ]
              ])
              ->add('body', [
                  'notBlank' => [
                      'rule' => 'notBlank',
                      'message' => __d('comment', 'Your comment message cannot be empty')
                  ],
                  'length' => [
                      'rule' => ['minLength', 5],
                      'message' => 'Comment message need to be at least 5 characters long',
                  ]
              ])
              ->allowEmpty('user_id')
              ->allowEmpty('parent_id')
              ->add('parent_id', 'checkParentId', [
                  'rule' => function ($value, $context) {
                      if (!empty($value)) {
                          // make sure it's a valid parent: exists and belongs to the
                          // the same bundle (table)
                          $conditions = [
                              'id' => $value,
                              'entity_id' => $context['data']['entity_id'],
                              'table_alias' => $context['data']['table_alias'],
                          ];
  
                          return TableRegistry::get('Comment.Comments')->find()
                              ->where($conditions)
                              ->count() > 0;
                      } else {
                          $context['data']['parent_id'] = null;
                      }
  
                      return true;
                  },
                  'message' => __d('comment', 'Invalid parent comment!.'),
                  'provider' => 'table',
              ]);
  
          return $validator;
      }
code: public function validationDefault(Validator $validator)
      {
          $validator
              ->add('subject', [
                  'notBlank' => [
                      'rule' => 'notBlank',
                      'message' => __d('comment', 'You need to provide a comment subject.'),
                  ],
                  'length' => [
                      'rule' => ['minLength', 5],
                      'message' => 'Comment subject need to be at least 5 characters long',
                  ]
              ])
              ->add('body', [
                  'notBlank' => [
                      'rule' => 'notBlank',
                      'message' => __d('comment', 'Your comment message cannot be empty')
                  ],
                  'length' => [
                      'rule' => ['minLength', 5],
                      'message' => 'Comment message need to be at least 5 characters long',
                  ]
              ])
              ->allowEmpty('user_id')
              ->allowEmpty('parent_id')
              ->add('parent_id', 'checkParentId', [
                  'rule' => function ($value, $context) {
                      if (!empty($value)) {
                          // make sure it's a valid parent: exists and belongs to the
                          // the same bundle (table)
                          $conditions = [
                              'id' => $value,
                              'entity_id' => $context['data']['entity_id'],
                              'table_alias' => $context['data']['table_alias'],
                          ];
  
                          return TableRegistry::get('Comment.Comments')->find()
                              ->where($conditions)
                              ->count() > 0;
                      } else {
                          $context['data']['parent_id'] = null;
                      }
  
                      return true;
                  },
                  'message' => __d('comment', 'Invalid parent comment!.'),
                  'provider' => 'table',
              ]);
  
          return $validator;
      }
code_tokens: public function validationDefault ( Validator $ validator ) { $ validator -> add ( 'subject' , [ 'notBlank' => [ 'rule' => 'notBlank' , 'message' => __d ( 'comment' , 'You need to provide a comment subject.' ) , ] , 'length' => [ 'rule' => [ 'minLength' , 5 ] , 'message' => 'Comment subject need to be at least 5 characters long' , ] ] ) -> add ( 'body' , [ 'notBlank' => [ 'rule' => 'notBlank' , 'message' => __d ( 'comment' , 'Your comment message cannot be empty' ) ] , 'length' => [ 'rule' => [ 'minLength' , 5 ] , 'message' => 'Comment message need to be at least 5 characters long' , ] ] ) -> allowEmpty ( 'user_id' ) -> allowEmpty ( 'parent_id' ) -> add ( 'parent_id' , 'checkParentId' , [ 'rule' => function ( $ value , $ context ) { if ( ! empty ( $ value ) ) { // make sure it's a valid parent: exists and belongs to the // the same bundle (table) $ conditions = [ 'id' => $ value , 'entity_id' => $ context [ 'data' ] [ 'entity_id' ] , 'table_alias' => $ context [ 'data' ] [ 'table_alias' ] , ] ; return TableRegistry :: get ( 'Comment.Comments' ) -> find ( ) -> where ( $ conditions ) -> count ( ) > 0 ; } else { $ context [ 'data' ] [ 'parent_id' ] = null ; } return true ; } , 'message' => __d ( 'comment' , 'Invalid parent comment!.' ) , 'provider' => 'table' , ] ) ; return $ validator ; }
docstring: Basic validation set of rules.
  
  @param \Cake\Validation\Validator $validator The validator object
  @return \Cake\Validation\Validator
docstring_tokens: Basic validation set of rules .