add_render_attribute('input' . $item_index, 'class', 'elementor-field-textual adtf-elementor-field'); $form->add_render_attribute('input' . $item_index, 'type', 'text', true); $field_type = !empty($item['adtf_field_type']) ? $item['adtf_field_type'] : 'date'; $date_format = !empty($item['adtf_date_format']) ? $item['adtf_date_format'] : 'd-m-Y'; $time_format = !empty($item['adtf_time_format']) ? $item['adtf_time_format'] : '12'; $min_date = !empty($item['adtf_min_date']) ? $item['adtf_min_date'] : 'none'; $min_date_value = !empty($item['adtf_min_date_value']) ? $item['adtf_min_date_value'] : ''; $max_date = !empty($item['adtf_max_date']) ? $item['adtf_max_date'] : 'none'; $max_date_value = !empty($item['adtf_max_date_value']) ? $item['adtf_max_date_value'] : ''; $disable_weekday = !empty($item['adtf_disable_weekday']) ? $item['adtf_disable_weekday'] : 'none'; $start_weekday = !empty($item['adtf_start_weekday']) ? $item['adtf_start_weekday'] : 'none'; $form->add_render_attribute('input' . $item_index, 'data-field-type', $field_type); if ('both' === $field_type || 'date' === $field_type) { $form->add_render_attribute('input' . $item_index, 'data-date-format', $date_format); if ('none' !== $disable_weekday) { $form->add_render_attribute('input' . $item_index, 'data-disable-weekday', $disable_weekday); } if ('none' !== $start_weekday) { $form->add_render_attribute('input' . $item_index, 'data-start-weekday', $start_weekday); } if ('today' === $min_date) { $form->add_render_attribute('input' . $item_index, 'data-min-date', $min_date); } elseif ('specific' === $min_date && $min_date_value) { $form->add_render_attribute('input' . $item_index, 'data-min-date', $min_date); $form->add_render_attribute('input' . $item_index, 'data-min-date-value', $min_date_value); } if ('today' === $max_date) { $form->add_render_attribute('input' . $item_index, 'data-max-date', $max_date); } elseif ('specific' === $max_date && $max_date_value) { $form->add_render_attribute('input' . $item_index, 'data-max-date', $max_date); $form->add_render_attribute('input' . $item_index, 'data-max-date-value', $max_date_value); } } if ('both' === $field_type || 'time' === $field_type) { $form->add_render_attribute('input' . $item_index, 'data-time-format', $time_format); } if (!empty($item['required'])) { $form->add_render_attribute('input' . $item_index, 'aria-required', 'true'); } ?> print_render_attribute_string('input' . $item_index); ?>> controls_manager->get_control_from_stack($widget->get_unique_name(), 'form_fields'); if (is_wp_error($control_data)) { return; } $field_controls = [ 'adtf_field_type' => [ 'name' => 'adtf_field_type', 'label' => esc_html__('Field Type', 'advanced-date-time-field'), 'type' => Controls_Manager::SELECT, 'options' => [ 'date' => esc_html__('Date', 'advanced-date-time-field'), 'time' => esc_html__('Time', 'advanced-date-time-field'), 'both' => esc_html__('Date & Time', 'advanced-date-time-field'), ], 'default' => 'date', 'condition' => [ 'field_type' => $this->get_type(), ], 'tab' => 'content', 'inner_tab' => 'form_fields_content_tab', 'tabs_wrapper' => 'form_fields_tabs', ], 'adtf_date_format' => [ 'name' => 'adtf_date_format', 'label' => esc_html__('Date Format', 'advanced-date-time-field'), 'type' => Controls_Manager::SELECT, 'options' => $this->get_date_formats(), 'default' => 'd-m-Y', 'condition' => [ 'field_type' => $this->get_type(), ], 'tab' => 'content', 'inner_tab' => 'form_fields_content_tab', 'tabs_wrapper' => 'form_fields_tabs', ], 'adtf_min_date' => [ 'name' => 'adtf_min_date', 'label' => esc_html__('Min Date', 'advanced-date-time-field'), 'type' => Controls_Manager::SELECT, 'options' => [ 'none' => esc_html__('None', 'advanced-date-time-field'), 'today' => esc_html__('Today', 'advanced-date-time-field'), 'specific' => esc_html__('Specific Date', 'advanced-date-time-field'), ], 'default' => 'none', 'condition' => [ 'field_type' => $this->get_type(), ], 'tab' => 'content', 'inner_tab' => 'form_fields_content_tab', 'tabs_wrapper' => 'form_fields_tabs', ], 'adtf_min_date_value' => [ 'name' => 'adtf_min_date_value', 'label' => esc_html__('Specific Date', 'advanced-date-time-field'), 'type' => Controls_Manager::DATE_TIME, 'label_block' => false, 'picker_options' => [ 'enableTime' => false, ], 'condition' => [ 'field_type' => $this->get_type(), 'adtf_min_date' => 'specific', ], 'tab' => 'content', 'inner_tab' => 'form_fields_content_tab', 'tabs_wrapper' => 'form_fields_tabs', ], 'adtf_max_date' => [ 'name' => 'adtf_max_date', 'label' => esc_html__('Max Date', 'advanced-date-time-field'), 'type' => Controls_Manager::SELECT, 'options' => [ 'none' => esc_html__('None', 'advanced-date-time-field'), 'today' => esc_html__('Today', 'advanced-date-time-field'), 'specific' => esc_html__('Specific Date', 'advanced-date-time-field'), ], 'default' => 'none', 'condition' => [ 'field_type' => $this->get_type(), ], 'tab' => 'content', 'inner_tab' => 'form_fields_content_tab', 'tabs_wrapper' => 'form_fields_tabs', ], 'adtf_max_date_value' => [ 'name' => 'adtf_max_date_value', 'label' => esc_html__('Specific Date', 'advanced-date-time-field'), 'type' => Controls_Manager::DATE_TIME, 'label_block' => false, 'picker_options' => [ 'enableTime' => false, ], 'condition' => [ 'field_type' => $this->get_type(), 'adtf_max_date' => 'specific', ], 'tab' => 'content', 'inner_tab' => 'form_fields_content_tab', 'tabs_wrapper' => 'form_fields_tabs', ], 'adtf_disable_weekday' => [ 'name' => 'adtf_disable_weekday', 'label' => esc_html__('Disable Weekday', 'advanced-date-time-field'), 'type' => Controls_Manager::SELECT, 'options' => $this->get_days_name(), 'default' => 'none', 'condition' => [ 'field_type' => $this->get_type(), ], 'tab' => 'content', 'inner_tab' => 'form_fields_content_tab', 'tabs_wrapper' => 'form_fields_tabs', ], 'adtf_start_weekday' => [ 'name' => 'adtf_start_weekday', 'label' => esc_html__('Start Weekday', 'advanced-date-time-field'), 'type' => Controls_Manager::SELECT, 'options' => $this->get_days_name(), 'default' => 'none', 'condition' => [ 'field_type' => $this->get_type(), ], 'tab' => 'content', 'inner_tab' => 'form_fields_content_tab', 'tabs_wrapper' => 'form_fields_tabs', ], 'adtf_time_format' => [ 'name' => 'adtf_time_format', 'label' => esc_html__('Time Format', 'advanced-date-time-field'), 'type' => Controls_Manager::SELECT, 'options' => [ '12' => esc_html__('12 Hour', 'advanced-date-time-field'), '24' => esc_html__('24 Hour', 'advanced-date-time-field'), ], 'default' => '12', 'condition' => [ 'field_type' => $this->get_type(), ], 'tab' => 'content', 'inner_tab' => 'form_fields_content_tab', 'tabs_wrapper' => 'form_fields_tabs', ], ]; foreach ($control_data['fields'] as $index => $field) { if ('placeholder' !== $field['name']) { continue; } foreach ($field['conditions']['terms'] as $condition_index => $terms) { if (!isset($terms['name']) || 'field_type' !== $terms['name'] || !isset($terms['operator']) || 'in' !== $terms['operator']) { continue; } $control_data['fields'][$index]['conditions']['terms'][$condition_index]['value'][] = $this->get_type(); break; } break; } $control_data['fields'] = $this->inject_field_controls($control_data['fields'], $field_controls); $widget->update_control('form_fields', $control_data); } public function get_days_name() { return [ 'none' => esc_html__('None', 'advanced-date-time-field'), 'sun' => esc_html__('Sunday', 'advanced-date-time-field'), 'mon' => esc_html__('Monday', 'advanced-date-time-field'), 'tue' => esc_html__('Tuesday', 'advanced-date-time-field'), 'wed' => esc_html__('Wednesday', 'advanced-date-time-field'), 'thr' => esc_html__('Thursday', 'advanced-date-time-field'), 'fri' => esc_html__('Friday', 'advanced-date-time-field'), 'sat' => esc_html__('Saturday', 'advanced-date-time-field'), ]; } public function get_date_formats() { return [ 'd-m-Y' => 'd-m-Y', 'm-d-Y' => 'm-d-Y', 'Y-m-d' => 'Y-m-d', ]; } }