/**
  * Generates html for the available Search Fields dropdown
  * @param  int $form_id
  * @param  string $current (for future use)
  * @return string
  */
 public static function render_searchable_fields($form_id = null, $current = '')
 {
     if (is_null($form_id)) {
         return '';
     }
     // start building output
     $output = '<select class="gv-search-fields">';
     $custom_fields = array('search_all' => array('text' => esc_html__('Search Everything', 'gravityview'), 'type' => 'text'), 'entry_date' => array('text' => esc_html__('Entry Date', 'gravityview'), 'type' => 'date'), 'entry_id' => array('text' => esc_html__('Entry ID', 'gravityview'), 'type' => 'text'), 'created_by' => array('text' => esc_html__('Entry Creator', 'gravityview'), 'type' => 'select'));
     foreach ($custom_fields as $custom_field_key => $custom_field) {
         $output .= sprintf('<option value="%s" %s data-inputtypes="%s" data-placeholder="%s">%s</option>', $custom_field_key, selected($custom_field_key, $current, false), $custom_field['type'], self::get_field_label(array('field' => $custom_field_key)), $custom_field['text']);
     }
     // Get fields with sub-inputs and no parent
     $fields = gravityview_get_form_fields($form_id, true, true);
     /**
      * @filter `gravityview/search/searchable_fields` Modify the fields that are displayed as searchable in the Search Bar dropdown\n
      * @since 1.17
      * @see gravityview_get_form_fields() Used to fetch the fields
      * @see GravityView_Widget_Search::get_search_input_types See this method to modify the type of input types allowed for a field
      * @param array $fields Array of searchable fields, as fetched by gravityview_get_form_fields()
      * @param  int $form_id
      */
     $fields = apply_filters('gravityview/search/searchable_fields', $fields, $form_id);
     if (!empty($fields)) {
         $blacklist_field_types = apply_filters('gravityview_blacklist_field_types', array('fileupload', 'post_image', 'post_id', 'section'), null);
         foreach ($fields as $id => $field) {
             if (in_array($field['type'], $blacklist_field_types)) {
                 continue;
             }
             $types = self::get_search_input_types($id, $field['type']);
             $output .= '<option value="' . $id . '" ' . selected($id, $current, false) . 'data-inputtypes="' . esc_attr($types) . '">' . esc_html($field['label']) . '</option>';
         }
     }
     $output .= '</select>';
     return $output;
 }
Esempio n. 2
0
 /**
  * Calculate the available fields
  * @param  string|array $form form_ID or form object
  * @param  string $zone   Either 'single', 'directory', 'header', 'footer'
  * @return array         fields
  */
 function get_available_fields($form = '', $zone = NULL)
 {
     if (empty($form)) {
         do_action('gravityview_log_error', '[get_available_fields] $form is empty');
         return array();
     }
     // get form fields
     $fields = gravityview_get_form_fields($form, true);
     // get meta fields ( only if form was already created )
     if (!is_array($form)) {
         $meta_fields = gravityview_get_entry_meta($form);
     } else {
         $meta_fields = array();
     }
     // get default fields
     $default_fields = $this->get_entry_default_fields($form, $zone);
     //merge without loosing the keys
     $fields = $fields + $meta_fields + $default_fields;
     return $fields;
 }
Esempio n. 3
0
 /**
  * Generates html for the available Search Fields dropdown
  * @param  string $form_id
  * @param  string $current (for future use)
  * @return string
  */
 public static function render_searchable_fields($form_id = null, $current = '')
 {
     if (is_null($form_id)) {
         return '';
     }
     // Get fields with sub-inputs and no parent
     $fields = gravityview_get_form_fields($form_id, true, true);
     // start building output
     $output = '<select class="gv-search-fields">';
     $output .= '<option value="search_all" ' . selected('search_all', $current, false) . ' data-inputtypes="text">' . esc_html__('Search Everything', 'gravityview') . '</option>';
     $output .= '<option value="entry_date" ' . selected('entry_date', $current, false) . ' data-inputtypes="date">' . esc_html__('Entry Date', 'gravityview') . '</option>';
     $output .= '<option value="entry_id" ' . selected('entry_id', $current, false) . ' data-inputtypes="text">' . esc_html__('Entry ID', 'gravityview') . '</option>';
     $output .= '<option value="created_by" ' . selected('created_by', $current, false) . ' data-inputtypes="select">' . esc_html__('Entry Creator', 'gravityview') . '</option>';
     if (!empty($fields)) {
         $blacklist_field_types = apply_filters('gravityview_blacklist_field_types', array('fileupload', 'post_image', 'post_id'), null);
         foreach ($fields as $id => $field) {
             if (in_array($field['type'], $blacklist_field_types)) {
                 continue;
             }
             $types = self::get_search_input_types($id, $field['type']);
             $output .= '<option value="' . $id . '" ' . selected($id, $current, false) . 'data-inputtypes="' . esc_attr($types) . '">' . esc_html($field['label']) . '</option>';
         }
     }
     $output .= '</select>';
     return $output;
 }