Skip to content
Browse files

Crudely support field arrays in the Events for detecting invalid/miss…

…ing error type
  • Loading branch information...
1 parent b24718d commit eb0ae2a4ddc68bba1b014d4f0dbfa0bead3d3db7 Brendan Abbott committed Apr 9, 2011
Showing with 19 additions and 1 deletion.
  1. +19 −1 symphony/lib/toolkit/events/event.section.php
View
20 symphony/lib/toolkit/events/event.section.php
@@ -11,6 +11,12 @@ function buildFilterElement($name, $status, $message=NULL, array $attr=NULL){
}
}
+ if(!function_exists('__reduceType')) {
+ function __reduceType($a, $b) {
+ return (empty($b)) ? 'missing' : 'invalid';
+ }
+ }
+
if (!function_exists('__doit')) {
function __doit($source, $fields, &$result, &$event, $filters = array(), $position=NULL, $entry_id=NULL){
@@ -105,7 +111,19 @@ function __doit($source, $fields, &$result, &$event, $filters = array(), $positi
foreach($errors as $field_id => $message){
$field = $entryManager->fieldManager->fetch($field_id);
- $result->appendChild(new XMLElement($field->get('element_name'), NULL, array('label' => General::sanitize($field->get('label')), 'type' => ($fields[$field->get('element_name')] == '' ? 'missing' : 'invalid'), 'message' => General::sanitize($message))));
+
+ if(is_array($fields[$field->get('element_name')])) {
+ $type = array_reduce($fields[$field->get('element_name')], '__reduceType');
+ }
+ else {
+ $type = ($fields[$field->get('element_name')] == '') ? 'missing' : 'invalid';
+ }
+
+ $result->appendChild(new XMLElement($field->get('element_name'), NULL, array(
+ 'label' => General::sanitize($field->get('label')),
+ 'type' => $type,
+ 'message' => General::sanitize($message)
+ )));
}
if(isset($post_values) && is_object($post_values)) $result->appendChild($post_values);

0 comments on commit eb0ae2a

Please sign in to comment.
Something went wrong with that request. Please try again.