true, 'invalid' => true, ); } /** * Declare the custom options so Formidable saves their posted values * (`field_options[adtf_{option}_{field_id}]`) and exposes their defaults. * * @return array */ protected function extra_field_opts() { return array( 'adtf_field_type' => 'date', 'adtf_date_format' => 'd-m-Y', 'adtf_min_date' => 'none', 'adtf_min_date_value' => '', 'adtf_max_date' => 'none', 'adtf_max_date_value' => '', 'adtf_disable_weekday' => 'none', 'adtf_start_weekday' => 'none', 'adtf_time_format' => '12', ); } /** * Render the input on the front end with the picker configuration * passed through data attributes. * * @param array $args * @param array $shortcode_atts * @return string */ public function front_field_input( $args, $shortcode_atts ) { $input_html = $this->get_field_input_html_hook( $this->field ); return 'adtf_data_attributes() . ' />'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- pieces are escaped above. } /** * Extra class on the front-end input so our script can find it. * * @return string */ protected function get_input_class() { return 'adtf-formidable-field'; } /** * Build the flatpickr configuration attributes. * * @return string */ protected function adtf_data_attributes() { $atts = array( 'data-field-type' => FrmField::get_option( $this->field, 'adtf_field_type' ), ); $field_type = $atts['data-field-type']; if ( 'both' === $field_type || 'date' === $field_type ) { $atts['data-date-format'] = FrmField::get_option( $this->field, 'adtf_date_format' ); $disable_weekday = FrmField::get_option( $this->field, 'adtf_disable_weekday' ); if ( $disable_weekday && 'none' !== $disable_weekday ) { $atts['data-disable-weekday'] = $disable_weekday; } $start_weekday = FrmField::get_option( $this->field, 'adtf_start_weekday' ); if ( $start_weekday && 'none' !== $start_weekday ) { $atts['data-start-weekday'] = $start_weekday; } $min_date = FrmField::get_option( $this->field, 'adtf_min_date' ); if ( 'today' === $min_date ) { $atts['data-min-date'] = 'today'; } elseif ( 'specific' === $min_date ) { $min_date_value = FrmField::get_option( $this->field, 'adtf_min_date_value' ); if ( $min_date_value ) { $atts['data-min-date'] = 'specific'; $atts['data-min-date-value'] = $min_date_value; } } $max_date = FrmField::get_option( $this->field, 'adtf_max_date' ); if ( 'today' === $max_date ) { $atts['data-max-date'] = 'today'; } elseif ( 'specific' === $max_date ) { $max_date_value = FrmField::get_option( $this->field, 'adtf_max_date_value' ); if ( $max_date_value ) { $atts['data-max-date'] = 'specific'; $atts['data-max-date-value'] = $max_date_value; } } } if ( 'both' === $field_type || 'time' === $field_type ) { $atts['data-time-format'] = FrmField::get_option( $this->field, 'adtf_time_format' ); } return FrmAppHelper::array_to_html_params( $atts ); } } /** * Builder options panel for the field. Fired through Formidable's * `frm_{type}_primary_field_options` action from FrmFieldType::show_primary_options(). * * @param array $args Includes 'field', 'display', and 'values'. */ function adtf_formidable_primary_field_options( $args ) { $field = $args['field']; $id = $field['id']; $field_type = $field['adtf_field_type'] ?? 'date'; $date_format = $field['adtf_date_format'] ?? 'd-m-Y'; $min_date = $field['adtf_min_date'] ?? 'none'; $min_date_value = $field['adtf_min_date_value'] ?? ''; $max_date = $field['adtf_max_date'] ?? 'none'; $max_date_value = $field['adtf_max_date_value'] ?? ''; $disable_weekday = $field['adtf_disable_weekday'] ?? 'none'; $start_weekday = $field['adtf_start_weekday'] ?? 'none'; $time_format = $field['adtf_time_format'] ?? '12'; $option_name = function ( $key ) use ( $id ) { return 'field_options[' . esc_attr( $key . '_' . $id ) . ']'; }; $days = array( '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' ), ); ?>