NF_Abstracts_List

Class NF_Abstracts_List.

Defined (1)

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

/includes/Abstracts/List.php  
  1. abstract class NF_Abstracts_List extends NF_Abstracts_Field 
  2. protected $_name = ''; 
  3.  
  4. protected $_section = 'common'; 
  5.  
  6. protected $_type = 'list'; 
  7.  
  8. protected $_test_value = FALSE; 
  9.  
  10. protected $_settings_all_fields = array( 
  11. 'key', 'label', 'label_pos', 'required', 'options', 'classes', 'admin_label', 'help', 'description' 
  12. ); 
  13.  
  14. public static $_base_template = 'list'; 
  15.  
  16. public function __construct() 
  17. parent::__construct(); 
  18.  
  19. add_filter( 'ninja_forms_custom_columns', array( $this, 'custom_columns' ), 10, 2 ); 
  20.  
  21. add_filter( 'ninja_forms_render_options', array( $this, 'query_string_default' ), 10, 2 ); 
  22.  
  23. public function get_parent_type() 
  24. return 'list'; 
  25.  
  26. public function admin_form_element( $id, $value ) 
  27. $form_id = get_post_meta( absint( $_GET[ 'post' ] ), '_form_id', true ); 
  28.  
  29. $field = Ninja_Forms()->form( $form_id )->get_field( $id ); 
  30.  
  31. $settings = $field->get_settings(); 
  32. $settings[ 'options' ] = apply_filters( 'ninja_forms_render_options', $settings[ 'options' ], $settings ); 
  33. $settings[ 'options' ] = apply_filters( 'ninja_forms_render_options_' . $field->get_type(), $settings[ 'options' ], $settings ); 
  34.  
  35. $options = '<option>--</option>'; 
  36. if ( is_array( $settings[ 'options' ] ) ) { 
  37. foreach( $settings[ 'options' ] as $option ) { 
  38. $selected = ( $value == $option[ 'value' ] ) ? "selected" : ''; 
  39. $options .= "<option value='{$option[ 'value' ]}' $selected>{$option[ 'label' ]}</option>"; 
  40. }  
  41.  
  42. return "<select class='widefat' name='fields[$id]' id=''>$options</select>"; 
  43.  
  44. public function custom_columns( $value, $field ) 
  45. if( $this->_name != $field->get_setting( 'type' ) ) return $value; 
  46.  
  47. if( ! is_array( $value ) ) $value = array( $value ); 
  48.  
  49. $output = ''; 
  50. $options = $field->get_setting( 'options' ); 
  51. if( ! empty( $options ) ) { 
  52. foreach ($options as $option) { 
  53.  
  54. if (!in_array($option['value'], $value)) continue; 
  55.  
  56. $output .= $option['label'] . "<br />"; 
  57.  
  58. return $output; 
  59.  
  60. public function query_string_default( $options, $settings ) 
  61. if( ! isset( $settings[ 'key' ] ) ) return $options; 
  62.  
  63. $field_key = $settings[ 'key' ]; 
  64.  
  65. if( ! isset( $_GET[ $field_key ] ) ) return $options; 
  66.  
  67. foreach( $options as $key => $option ) { 
  68.  
  69. if( ! isset( $option[ 'value' ] ) ) continue; 
  70.  
  71. if( $option[ 'value' ] != $_GET[ $field_key ] ) continue; 
  72.  
  73. $options[ $key ][ 'selected' ] = 1; 
  74.  
  75. return $options;