Trouble with custom validation rule and functions

Hi, why is the validationAddb not getting into function ($context) { ?

public function validationAddb(Validator $validator): Validator
    $validator->requirePresence('license_id', function ($context) {
        // Confirm the closure is executed and print the context
        debug('Inside requirePresence closure');
        if (isset($context['data']['action']) && $context['data']['action'] === 'submit') {
            return true;
        return false;
    // Add more validation rules as needed
    return $validator;

parkalbumimage = $this->Parks->Parkalbums->Parkalbumsimages->newEmptyEntity();

parkalbumimage = $this->Parks->Parksalbums->Parkalbumsimages->patchEntity($parkalbumimage, $requestData, [‘validate’ => ‘addb’]);

the data inside $requestdata is:

APP/Controller/ParksController.php (line 1218)
object(App\Model\Entity\Parkalbumsimage) id:0 {
‘action’ => ‘submit’
‘[new]’ => true
‘[accessible]’ => [
‘action’ => true,
‘license_id’ => true,
‘[dirty]’ => [
‘action’ => true,
‘[original]’ => [
‘[originalFields]’ => [
‘[virtual]’ => [
‘[hasErrors]’ => false
‘[errors]’ => [
‘[invalid]’ => [
‘[repository]’ => ‘Parkalbumsimages’

action is submit and no license_id was providede but he does not give any complaints… btw how can i say that -

add(‘license_id’, ‘validFormat’, [
‘rule’ => [‘custom’, ‘/^\d+$/’],
‘message’ => ‘License ID must be a number.’
])->minLength(‘license_id’, 1); should also be true in the case of action = submit?

any idea ?

right now i never see any result of the two debugs…

best, herzi

  1. Is })-; a typo, or do you really have a - in there?

  2. The data you’ve shown is really $parkalbumimage, not $requestData, right? $requestData (which you’ve referred to as $requestdata elsewhere; please be sure that you have all your capitalization correct in your actual code, and maybe edit your question to fix it as well) should be an array, not an entity.

  3. Is debugging even turned on for you? Any chance that the output from your debug statements is being otherwise ignored?

the problem is solved… i didnt know that he continues the entire method after patchentity… it didnt work because of other commands behind the patchentity …