Skip to content

Commit

Permalink
Removed interface method in favor of annotation for BC
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyharris committed Apr 4, 2018
1 parent 6e2e6d2 commit e3af681
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
10 changes: 2 additions & 8 deletions src/View/Form/ContextInterface.php
Expand Up @@ -16,6 +16,8 @@

/**
* Interface for FormHelper context implementations.
*
* @method string getRequiredMessage($field) Gets the default "required" error message for a field
*/
interface ContextInterface
{
Expand Down Expand Up @@ -70,14 +72,6 @@ public function val($field);
*/
public function isRequired($field);

/**
* Gets the default "required" error message for a field
*
* @param string $field A dot separated path to the field
* @return string
*/
public function getRequiredMessage($field);

/**
* Get the fieldnames of the top level object in this context.
*
Expand Down
12 changes: 7 additions & 5 deletions src/View/Helper/FormHelper.php
Expand Up @@ -1435,11 +1435,13 @@ protected function _magicOptions($fieldName, $options, $allowOverride)
$options['required'] = $context->isRequired($fieldName);
}

$message = $context->getRequiredMessage($fieldName);
if ($options['required'] && $message && $this->getConfig('useValidationMessages')) {
$message = h(addslashes($message));
$options['oninvalid'] = "this.setCustomValidity('$message')";
$options['onvalid'] = "this.setCustomValidity('')";
if (method_exists($context, 'getRequiredMessage')) {
$message = $context->getRequiredMessage($fieldName);
if ($options['required'] && $message && $this->getConfig('useValidationMessages')) {
$message = h(addslashes($message));
$options['oninvalid'] = "this.setCustomValidity('$message')";
$options['onvalid'] = "this.setCustomValidity('')";
}
}

$type = $context->type($fieldName);
Expand Down

0 comments on commit e3af681

Please sign in to comment.