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. $field = Ninja_Forms()->form()->get_field( $id ); 
  28.  
  29. $options = '<option>--</option>'; 
  30. foreach( $field->get_setting( 'options' ) as $option ) { 
  31. $selected = ( $value == $option[ 'value' ] ) ? "selected" : ''; 
  32. $options .= "<option value='{$option[ 'value' ]}' $selected>{$option[ 'label' ]}</option>"; 
  33.  
  34. return "<select class='widefat' name='fields[$id]' id=''>$options</select>"; 
  35.  
  36. public function custom_columns( $value, $field ) 
  37. if( $this->_name != $field->get_setting( 'type' ) ) return $value; 
  38.  
  39. if( ! is_array( $value ) ) $value = array( $value ); 
  40.  
  41. $output = ''; 
  42. $options = $field->get_setting( 'options' ); 
  43. if( ! empty( $options ) ) { 
  44. foreach ($options as $option) { 
  45.  
  46. if (!in_array($option['value'], $value)) continue; 
  47.  
  48. $output .= $option['label'] . "<br />"; 
  49.  
  50. return $output; 
  51.  
  52. public function query_string_default( $options, $settings ) 
  53. if( ! isset( $settings[ 'key' ] ) ) return $options; 
  54.  
  55. $field_key = $settings[ 'key' ]; 
  56.  
  57. if( ! isset( $_GET[ $field_key ] ) ) return $options; 
  58.  
  59. foreach( $options as $key => $option ) { 
  60.  
  61. if( ! isset( $option[ 'value' ] ) ) continue; 
  62.  
  63. if( $option[ 'value' ] != $_GET[ $field_key ] ) continue; 
  64.  
  65. $options[ $key ][ 'selected' ] = 1; 
  66.  
  67. return $options;