Unverified Commit c17136ab authored by Côme Chilliet's avatar Côme Chilliet
Browse files

:ambulance: fix(core) Improve formating for invalid value error

POC for html escaping of translated errors.

issue #6071
Showing with 28 additions and 3 deletions
+28 -3
......@@ -83,4 +83,20 @@ class SimplePluginCheckError extends FusionDirectoryError
return [_('Error'), $html, ERROR_DIALOG, $trace];
}
/*!
* \brief Format error message for invalid value
*
* \param string $error The unescaped text error
*
* \return HTML string
*/
static public function invalidValue(string $error): string
{
return sprintf(
'<b>%s</b> %s',
htmlescape(_('Invalid value:')),
htmlescape($error)
);
}
}
......@@ -81,13 +81,22 @@ class IntAttribute extends Attribute
return $error;
} elseif ($this->value !== '') {
if (!is_numeric($this->value)) {
return new SimplePluginCheckError($this, sprintf(_('"%s" is not an number'), $this->getValue()));
return new SimplePluginCheckError(
$this,
SimplePluginCheckError::invalidValue(sprintf(_('"%s" is not an number'), $this->getValue()))
);
}
if (($this->min !== FALSE) && ($this->value < $this->min)) {
return new SimplePluginCheckError($this, sprintf(_('%s is smaller than %s'), $this->getValue(), $this->min));
return new SimplePluginCheckError(
$this,
SimplePluginCheckError::invalidValue(sprintf(_('%s is smaller than %s'), $this->getValue(), $this->min))
);
}
if (($this->max !== FALSE) && ($this->value > $this->max)) {
return new SimplePluginCheckError($this, sprintf(_('%s is larger than %s'), $this->getValue(), $this->max));
return new SimplePluginCheckError(
$this,
SimplePluginCheckError::invalidValue(sprintf(_('%s is larger than %s'), $this->getValue(), $this->max))
);
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment