ListSelect.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php if ( ! defined( 'ABSPATH' ) ) exit;
  2. /**
  3. * Class NF_Fields_SelectList
  4. */
  5. class NF_Fields_ListSelect extends NF_Abstracts_List
  6. {
  7. protected $_name = 'listselect';
  8. protected $_type = 'listselect';
  9. protected $_nicename = 'Select';
  10. protected $_section = 'common';
  11. protected $_icon = 'chevron-down';
  12. protected $_templates = 'listselect';
  13. protected $_old_classname = 'list-select';
  14. public function __construct()
  15. {
  16. parent::__construct();
  17. $this->_nicename = __( 'Select', 'ninja-forms' );
  18. add_filter( 'ninja_forms_merge_tag_calc_value_' . $this->_type, array( $this, 'get_calc_value' ), 10, 2 );
  19. }
  20. public function get_calc_value( $value, $field )
  21. {
  22. if( isset( $field[ 'options' ] ) ) {
  23. foreach ($field['options'] as $option ) {
  24. if( ! isset( $option[ 'value' ] ) || $value != $option[ 'value' ] || ! isset( $option[ 'calc' ] ) ) continue;
  25. return $option[ 'calc' ];
  26. }
  27. }
  28. return $value;
  29. }
  30. }