Caldera_Forms_Field_Localizer

Handles sending form field config to DOM.

Defined (1)

The class is defined in the following location(s).

/classes/field/localizer.php  
  1. class Caldera_Forms_Field_Localizer { 
  2.  
  3. /** 
  4. * The configs to be printed 
  5. * @since 1.5.0 
  6. * @var 
  7. */ 
  8. protected static $localized; 
  9.  
  10. /** 
  11. * Add form 
  12. * Functions as factory for Caldera_Forms_Render_FieldsJS 
  13. * @since 1.5.0 
  14. * @param array $form 
  15. * @param $current_form_count 
  16. */ 
  17. public static function add_form( array $form, $current_form_count ) { 
  18. $fieldjs = new Caldera_Forms_Field_JS( $form, $current_form_count ); 
  19.  
  20. self::$localized[ $current_form_count ] = $fieldjs->to_array(); 
  21. add_action( 'wp_footer', array( __CLASS__, 'localize_cb' ), 100 ); 
  22.  
  23.  
  24. /** 
  25. * Output the configs as CDATA 
  26. * @since 1.5.0 
  27. * @uses "wp_footer" 
  28. */ 
  29. public static function localize_cb() { 
  30. if ( ! empty( self::$localized ) ) { 
  31.  
  32. $slug = Caldera_Forms_Render_Assets::field_script_to_localize_slug(); 
  33. $data = array(); 
  34. foreach ( self::$localized as $form_instance => $form_data ) { 
  35. $data[ $form_instance ] = $form_data; 
  36.  
  37. $wp_scripts = wp_scripts(); 
  38. wp_localize_script( $slug, 'CFFIELD_CONFIG', $data ); 
  39.  
  40. $wp_scripts->print_extra_script( $slug, true ); 
  41.