From 2b6981905e3fcd0a00ad722fa08ad465174de0e8 Mon Sep 17 00:00:00 2001 From: Francis Whittle Date: Fri, 8 Nov 2024 10:20:15 +1100 Subject: [PATCH] WPCIVIUX-176 Clarify logging and documentation for API Field name validator --- .../utils/class-civicrm-ux-validators.php | 28 +++++++++++++------ rest/json-all-events.php | 4 +-- shortcodes/event/event-fullcalendar.php | 4 +-- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/includes/utils/class-civicrm-ux-validators.php b/includes/utils/class-civicrm-ux-validators.php index 47589a7..26ebfa6 100644 --- a/includes/utils/class-civicrm-ux-validators.php +++ b/includes/utils/class-civicrm-ux-validators.php @@ -44,15 +44,25 @@ public static function validateCssColor($color): ?string return $valid ? $matches[1] : null; } - public static function validateAPIFieldName($field, $key = null): ?string - { - $valid = preg_match('{ ^ (?! [.-] ) [[:alnum:]._:-]+ (? Civicrm_Ux_Validators::validateAPIFieldName( $field, 'extra_fields' ), $extra_fields ); if(!empty($_REQUEST['colors']) && !is_array($_REQUEST['colors'])) { $_REQUEST['colors'] = explode(',', $_REQUEST['colors']); @@ -91,7 +91,7 @@ protected function get_events_all() { } if(!empty($_REQUEST['image_src_field'])) { - $image_src_field = Civicrm_Ux_Validators::validateAPIFieldName($_REQUEST['image_src_field']); + $image_src_field = Civicrm_Ux_Validators::validateAPIFieldName($_REQUEST['image_src_field'], 'image_src_field'); $eventQuery->addSelect($image_src_field); } else { $image_src_field = null; diff --git a/shortcodes/event/event-fullcalendar.php b/shortcodes/event/event-fullcalendar.php index c95ab14..1c40c64 100644 --- a/shortcodes/event/event-fullcalendar.php +++ b/shortcodes/event/event-fullcalendar.php @@ -39,10 +39,10 @@ public function shortcode_callback( $atts = [], $content = null, $tag = '' ) { } } if (isset($atts['extra_fields'])) { - $extra_fields_arr = array_map([ 'Civicrm_Ux_Validators', 'validateAPIFieldName' ], explode(",", $atts['extra_fields'])); + $extra_fields_arr = array_map( fn( $field ) => Civicrm_Ux_Validators::validateAPIFieldName( $field, 'extra_fields' ), explode( ",", $atts['extra_fields'] ) ); } if (isset($atts['image_src_field'])) { - $atts['image_src_field'] = Civicrm_Ux_Validators::validateAPIFieldName($atts['image_src_field']); + $atts['image_src_field'] = Civicrm_Ux_Validators::validateAPIFieldName( $atts['image_src_field'], 'image_src_field' ); } if (isset($atts['force_login'])) { $atts['force_login'] = filter_var($atts['force_login'], FILTER_VALIDATE_BOOLEAN);