/**
* Method to validate the form data.
*
* @param Form $form The form to validate against.
* @param array $data The data to validate.
* @param string $group The name of the field group to validate.
*
* @return array|boolean Array of filtered data if valid, false otherwise.
*
* @see FormRule
* @see InputFilter
* @since 1.6
*/
public function validate($form, $data, $group = null)
{
// Include the plugins for the delete events.
PluginHelper::importPlugin($this->events_map['validate']);
$dispatcher = Factory::getContainer()->get('dispatcher');
if (!empty($dispatcher->getListeners('onUserBeforeDataValidation'))) {
@trigger_error('The `onUserBeforeDataValidation` event is deprecated and will be removed in 5.0.' . 'Use the `onContentValidateData` event instead.', E_USER_DEPRECATED);
Factory::getApplication()->triggerEvent('onUserBeforeDataValidation', array($form, &$data));
}
Factory::getApplication()->triggerEvent('onContentBeforeValidateData', array($form, &$data));
// Filter and validate the form data.
$data = $form->filter($data);
$return = $form->validate($data, $group);
// Check for an error.
if ($return instanceof \Exception) {
$this->setError($return->getMessage());
return false;
}
// Check the validation results.
if ($return === false) {
// Get the validation messages from the form.
foreach ($form->getErrors() as $message) {
$this->setError($message);
}
return false;
}
// Tags B/C break at 3.1.2
if (!isset($data['tags']) && isset($data['metadata']['tags'])) {
$data['tags'] = $data['metadata']['tags'];
}
return $data;
}