public function php($data)
 {
     $valid = parent::php($data);
     $identifierField = Member::config()->unique_identifier_field;
     $member = Member::get()->filter($identifierField, $data[$identifierField])->first();
     if (is_object($member) && $member->isInDB()) {
         $uniqueField = $this->form->Fields()->dataFieldByName($identifierField);
         $this->validationError($uniqueField->id(), sprintf(_t('Member.VALIDATIONMEMBEREXISTS', 'A member already exists with the same %s'), strtolower($identifierField)), 'required');
         $valid = false;
     }
     // Execute the validators on the extensions
     if ($this->extension_instances) {
         foreach ($this->extension_instances as $extension) {
             if (method_exists($extension, 'hasMethod') && $extension->hasMethod('updatePHP')) {
                 $valid &= $extension->updatePHP($data, $this->form);
             }
         }
     }
     return $valid;
 }
 public function testCustomMemberValidator()
 {
     $member = $this->objFromFixture('Member', 'admin');
     $form = new MemberTest_ValidatorForm();
     $form->loadDataFrom($member);
     $validator = new Member_Validator();
     $validator->setForm($form);
     $pass = $validator->php(array('FirstName' => 'Borris', 'Email' => '*****@*****.**'));
     $fail = $validator->php(array('Email' => '*****@*****.**', 'Surname' => ''));
     $this->assertTrue($pass, 'Validator requires on FirstName and Email');
     $this->assertFalse($fail, 'Missing FirstName');
     $ext = new MemberTest_ValidatorExtension();
     $ext->updateValidator($validator);
     $pass = $validator->php(array('FirstName' => 'Borris', 'Email' => '*****@*****.**'));
     $fail = $validator->php(array('Email' => '*****@*****.**'));
     $this->assertFalse($pass, 'Missing surname');
     $this->assertFalse($fail, 'Missing surname value');
     $fail = $validator->php(array('Email' => '*****@*****.**', 'Surname' => 'Silverman'));
     $this->assertTrue($fail, 'Passes with email and surname now (no firstname)');
 }