SHARE
TWEET

Untitled

a guest Sep 16th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class GF_Field_Attendees extends GF_Field {
  2.  
  3.     public $type = 'attendees';
  4.  
  5.     public function get_form_editor_field_title() {
  6.         return esc_attr__( 'Attendees', 'gravityforms' );
  7.     }
  8.  
  9.     public function get_form_editor_button() {
  10.         return array(
  11.             'group' => 'advanced_fields',
  12.             'text'  => $this->get_form_editor_field_title(),
  13.         );
  14.     }
  15.  
  16.     public function get_form_editor_field_settings() {
  17.         return array(
  18.             'conditional_logic_field_setting',
  19.             'prepopulate_field_setting',
  20.             'error_message_setting',
  21.             'label_setting',
  22.             'admin_label_setting',
  23.             'rules_setting',
  24.             'duplicate_setting',
  25.             'description_setting',
  26.             'css_class_setting',
  27.         );
  28.     }
  29.  
  30.     public function is_conditional_logic_supported() {
  31.         return true;
  32.     }
  33.  
  34.     public function get_field_input( $form, $value = '', $entry = null ) {
  35.         $is_entry_detail = $this->is_entry_detail();
  36.         $is_form_editor  = $this->is_form_editor();
  37.  
  38.         $form_id  = $form['id'];
  39.         $field_id = intval( $this->id );
  40.  
  41.         $first = $last = $email = $phone = '';
  42.  
  43.         if ( is_array( $value ) ) {
  44.             $first = esc_attr( rgget( $this->id . '.1', $value ) );
  45.             $last  = esc_attr( rgget( $this->id . '.2', $value ) );
  46.             $email = esc_attr( rgget( $this->id . '.3', $value ) );
  47.             $phone = esc_attr( rgget( $this->id . '.4', $value ) );
  48.         }
  49.  
  50.         $disabled_text = $is_form_editor ? "disabled='disabled'" : '';
  51.         $class_suffix  = $is_entry_detail ? '_admin' : '';
  52.  
  53.         $first_tabindex = GFCommon::get_tabindex();
  54.         $last_tabindex  = GFCommon::get_tabindex();
  55.         $email_tabindex = GFCommon::get_tabindex();
  56.         $phone_tabindex = GFCommon::get_tabindex();
  57.  
  58.         $required_attribute = $this->isRequired ? 'aria-required="true"' : '';
  59.         $invalid_attribute  = $this->failed_validation ? 'aria-invalid="true"' : 'aria-invalid="false"';
  60.  
  61.         $first_markup = '<span id="input_' . $field_id . '_' . $form_id . '.1_container" class="attendees_first">';
  62.         $first_markup .= '<input type="text" name="input_' . $field_id . '.1" id="input_' . $field_id . '_' . $form_id . '_1" value="' . $first . '" aria-label="First Name" ' . $first_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
  63.         $first_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_1">First Name</label>';
  64.         $first_markup .= '</span>';
  65.  
  66.         $last_markup = '<span id="input_' . $field_id . '_' . $form_id . '.2_container" class="attendees_last">';
  67.         $last_markup .= '<input type="text" name="input_' . $field_id . '.2" id="input_' . $field_id . '_' . $form_id . '_2" value="' . $last . '" aria-label="Last Name" ' . $last_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
  68.         $last_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_2">Last Name</label>';
  69.         $last_markup .= '</span>';
  70.  
  71.         $email_markup = '<span id="input_' . $field_id . '_' . $form_id . '.3_container" class="attendees_email">';
  72.         $email_markup .= '<input type="text" name="input_' . $field_id . '.3" id="input_' . $field_id . '_' . $form_id . '_3" value="' . $email . '" aria-label="Email" ' . $email_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
  73.         $email_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_3">Email</label>';
  74.         $email_markup .= '</span>';
  75.  
  76.         $phone_markup = '<span id="input_' . $field_id . '_' . $form_id . '.4_container" class="attendees_phone">';
  77.         $phone_markup .= '<input type="text" name="input_' . $field_id . '.4" id="input_' . $field_id . '_' . $form_id . '_4" value="' . $phone . '" aria-label="Phone #" ' . $phone_tabindex . ' ' . $disabled_text . ' ' . $required_attribute . ' ' . $invalid_attribute . '>';
  78.         $phone_markup .= '<label for="input_' . $field_id . '_' . $form_id . '_4">Phone #</label>';
  79.         $phone_markup .= '</span>';
  80.  
  81.         $css_class = $this->get_css_class();
  82.  
  83.         return "<div class='ginput_complex{$class_suffix} ginput_container {$css_class} gfield_trigger_change' id='{$field_id}'>
  84.                    {$first_markup}
  85.                    {$last_markup}
  86.                    {$email_markup}
  87.                    {$phone_markup}
  88.                    <div class='gf_clear gf_clear_complex'></div>
  89.                </div>";
  90.     }
  91.  
  92.     public function get_css_class() {
  93.         $first_input = GFFormsModel::get_input( $this, $this->id . '.1' );
  94.         $last_input  = GFFormsModel::get_input( $this, $this->id . '.2' );
  95.         $email_input = GFFormsModel::get_input( $this, $this->id . '.3' );
  96.         $phone_input = GFFormsModel::get_input( $this, $this->id . '.4' );
  97.  
  98.         $css_class           = '';
  99.         $visible_input_count = 0;
  100.  
  101.         if ( $first_input && ! rgar( $first_input, 'isHidden' ) ) {
  102.             $visible_input_count ++;
  103.             $css_class .= 'has_first_name ';
  104.         } else {
  105.             $css_class .= 'no_first_name ';
  106.         }
  107.  
  108.         if ( $last_input && ! rgar( $last_input, 'isHidden' ) ) {
  109.             $visible_input_count ++;
  110.             $css_class .= 'has_last_name ';
  111.         } else {
  112.             $css_class .= 'no_last_name ';
  113.         }
  114.  
  115.         if ( $email_input && ! rgar( $email_input, 'isHidden' ) ) {
  116.             $visible_input_count ++;
  117.             $css_class .= 'has_email ';
  118.         } else {
  119.             $css_class .= 'no_email ';
  120.         }
  121.  
  122.         if ( $phone_input && ! rgar( $phone_input, 'isHidden' ) ) {
  123.             $visible_input_count ++;
  124.             $css_class .= 'has_phone ';
  125.         } else {
  126.             $css_class .= 'no_phone ';
  127.         }
  128.  
  129.         $css_class .= "gf_attendees_has_{$visible_input_count} ginput_container_attendees ";
  130.  
  131.         return trim( $css_class );
  132.     }
  133.  
  134.     public function get_form_editor_inline_script_on_page_render() {
  135.  
  136.         // set the default field label for the field
  137.         $script = sprintf( "function SetDefaultValues_%s(field) {
  138.        field.label = '%s';
  139.        field.inputs = [new Input(field.id + '.1', '%s'), new Input(field.id + '.2', '%s'), new Input(field.id + '.3', '%s'), new Input(field.id + '.4', '%s')];
  140.        }", $this->type, $this->get_form_editor_field_title(), 'First Name', 'Last Name', 'Email', 'Phone' ) . PHP_EOL;
  141.  
  142.         return $script;
  143.     }
  144.  
  145.     public function get_value_entry_detail( $value, $currency = '', $use_text = false, $format = 'html', $media = 'screen' ) {
  146.         if ( is_array( $value ) ) {
  147.             $first = trim( rgget( $this->id . '.1', $value ) );
  148.             $last  = trim( rgget( $this->id . '.2', $value ) );
  149.             $email = trim( rgget( $this->id . '.3', $value ) );
  150.             $phone = trim( rgget( $this->id . '.4', $value ) );
  151.  
  152.             $return = $first;
  153.             $return .= ! empty( $return ) && ! empty( $last ) ? " $last" : $last;
  154.             $return .= ! empty( $return ) && ! empty( $email ) ? " $email" : $email;
  155.             $return .= ! empty( $return ) && ! empty( $phone ) ? " $phone" : $phone;
  156.  
  157.         } else {
  158.             $return = '';
  159.         }
  160.  
  161.         if ( $format === 'html' ) {
  162.             $return = esc_html( $return );
  163.         }
  164.  
  165.         return $return;
  166.     }
  167.  
  168. }
  169.  
  170. GF_Fields::register( new GF_Field_Attendees() );
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top