title: How can I turn off CakePHP 3 validation only when a field is dirty?
body: <p>I'm working with saving edits to an entity - the only trouble is that this password validation function below is part of the UsersTable, and it wants to be called even when I'm not making a change to the password field:</p>
  
  <pre><code>-&gt;add('password',[
      'custom'=&gt;[
          'rule'=&gt; function($value, $context){
              $pattern = '$\S*(?=\S{8,})(?=\S*[a-z])(?=\S*[A-Z])(?=\S*[\d])(?=\S*[\W])\S*$';
                  return (bool)preg_match($pattern, $context['providers']['entity']-&gt;beforeHash);
              },
          'message'=&gt;'Your password must have 1 uppercase letter, 1 lowercase letter, 1 number, and 1 special character ie. !@#$%'
      ],
  ])
  </code></pre>
  
  <p>I tried adding a statement to it - the 'on' parameter as described in the documentation:</p>
  
  <pre><code>'on' =&gt; function ($context) {
      return empty($context['providers']['password]);
   },
  </code></pre>
  
  <p>This allowed me to make the changes, as it only runs the validation when the field is empty (i.e., when we first create a user).</p>
  
  <p>Unfortunately, it also broke my other functions - change and reset password. In those cases, a password is set in the field, so the validation won't apply when I'm trying to change or reset my password.</p>
  
  <p>So I talked to the Github CakePHP3 guys on it and they suggested I check the dirty field to see whether or not a password was trying to be changed.</p>
  
  <p>It's a great idea, but how do I access the field? Once I get deep into the array, I can't go any further:</p>
  
  <pre><code>$context['providers']['entity'] // this returns my object, but doesn't go deep enough
  $context['providers']['entity']['dirty'] // this doesn't work - returns null, even though there is data inside on the debug
  </code></pre>
  
  <p>So how can I access the dirty array from the context I'm in? If I can see that the password field is being updated, I can make an exception and fix the problem.</p>