namespace WPForms\Forms\Fields\Addons\Map;
use WPForms\Forms\Fields\Traits\ProField as ProFieldTrait;
use WPFormsGeolocation\Admin\Settings\Settings;
class Field extends WPForms_Field {
* Find Nearby Locations option key.
protected const NEARBY_LOCATIONS_KEY = 'wpforms_geolocation_find_nearby_locations';
* Search Radius option key.
protected const NEARBY_LOCATIONS_RADIUS_KEY = 'wpforms_geolocation_search_radius';
protected const DEFAULT_SEARCH_RADIUS = 25;
* Whether the addon is active.
private $is_addon_active = false;
* Determine if we should display the field options notice.
protected $display_field_options_notice = true;
* @noinspection ReturnTypeCanBeDeclaredInspection
// Define field type information.
$this->name = esc_html__( 'Map', 'wpforms-lite' );
$this->keywords = esc_html__( 'map', 'wpforms-lite' );
$this->icon = 'fa-map-location-dot';
$this->addon_slug = 'geolocation';
$this->allow_read_only = false;
$this->default_settings = [
'hide_full_screen' => '1',
'hide_location_info' => '1',
'hide_street_view' => '1',
'hide_camera_control' => '1',
'disable_mouse_zooming' => '1',
'show_thumbnail_in_entry' => '1',
'search_radius' => self::DEFAULT_SEARCH_RADIUS,
$this->is_addon_active = function_exists( 'wpforms_' . $this->addon_slug );
protected function hooks(): void {}
* Define additional field options.
* @param array $field Field data and settings.
* @noinspection ReturnTypeCanBeDeclaredInspection
public function field_options( $field ) {
$this->basic_field_options( (array) $field );
$this->advanced_field_options( (array) $field );
* @param array $field Field settings.
private function basic_field_options( array $field ): void {
'after_title' => $this->display_field_options_notice ? $this->get_field_options_notice() : '',
$this->field_option( 'label', $field );
$this->field_option( 'description', $field );
'class' => 'wpforms-field-option-row-locations',
'content' => $this->get_location_options( $field ),
$current_user_id = get_current_user_id();
$find_nearby_locations = (bool) get_user_meta( $current_user_id, self::NEARBY_LOCATIONS_KEY, true );
$nearby_locations_radius = (int) get_user_meta( $current_user_id, self::NEARBY_LOCATIONS_RADIUS_KEY, true );
$nearby_locations_radius = $nearby_locations_radius > 0 ? $nearby_locations_radius : self::DEFAULT_SEARCH_RADIUS;
'slug' => 'find_nearby_locations',
'content' => $this->field_element(
'slug' => 'find_nearby_locations',
'value' => $find_nearby_locations ? '1' : '0',
'desc' => esc_html__( 'Find Nearby Locations', 'wpforms-lite' ),
'slug' => 'search_radius',
'class' => ! $find_nearby_locations ? 'wpforms-hidden' : '',
'slug' => 'search_radius',
'value' => esc_html__( 'Search Radius', 'wpforms-lite' ),
'slug' => 'search_radius',
'value' => $nearby_locations_radius,
'options' => $this->get_search_radius_km_options(),
'miles-options' => wp_json_encode( $this->get_search_radius_miles_options() ),
'slug' => 'show_locations_list',
'content' => $this->field_element(
'slug' => 'show_locations_list',
'value' => isset( $field['show_locations_list'] ) ? '1' : '0',
'desc' => esc_html__( 'Show List of Locations', 'wpforms-lite' ),
'slug' => 'allow_location_selection',
'content' => $this->field_element(
'slug' => 'allow_location_selection',
'value' => isset( $field['allow_location_selection'] ) ? '1' : '0',
'desc' => esc_html__( 'Allow Location Selection', 'wpforms-lite' ),
'value' => esc_html__( 'Zoom Level', 'wpforms-lite' ),
'class' => 'wpforms-field-map-settings',
'value' => ! empty( $field['zoom_level'] ) && $field['zoom_level'] >= 0 && $field['zoom_level'] <= 22 ? (int) $field['zoom_level'] : 15,
'options' => range( 0, 22 ),
$this->field_option( 'basic-options', $field, [ 'markup' => 'close' ] );
* Advanced field options.
* @param array $field Field settings.
private function advanced_field_options( array $field ): void { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
$is_mapbox = $this->get_active_provider_slug() === 'mapbox-search';
$this->field_option( 'advanced-options', $field, [ 'markup' => 'open' ] );
$this->field_option( 'size', $field );
$this->field_option( 'css', $field );
printf( '<div class="wpforms-field-option-row-subtitle">%1$s</div>', esc_html__( 'Presentational Settings', 'wpforms-lite' ) );
'slug' => 'hide_full_screen',
'content' => $this->field_element(
'class' => 'wpforms-field-map-settings',
'map-control' => 'fullscreenControl',
'slug' => 'hide_full_screen',
'value' => isset( $field['hide_full_screen'] ) ? '1' : '0',
'desc' => esc_html__( 'Hide Full Screen ', 'wpforms-lite' ),
'slug' => 'hide_map_type',
'content' => $this->field_element(
'class' => 'wpforms-field-map-settings',
'map-control' => 'mapTypeControl',
'slug' => 'hide_map_type',
'value' => isset( $field['hide_map_type'] ) ? '1' : '0',
'desc' => esc_html__( 'Hide Map Type ', 'wpforms-lite' ),
'slug' => 'hide_location_info',
'content' => $this->field_element(
'slug' => 'hide_location_info',
'value' => isset( $field['hide_location_info'] ) ? '1' : '0',
'desc' => esc_html__( 'Hide Location Info ', 'wpforms-lite' ),
'slug' => 'hide_street_view',
'content' => $this->field_element(
'class' => 'wpforms-field-map-settings',
'map-control' => 'streetViewControl',
'slug' => 'hide_street_view',
'value' => isset( $field['hide_street_view'] ) ? '1' : '0',
'desc' => esc_html__( 'Hide Street View ', 'wpforms-lite' ),
printf( '<div class="wpforms-field-option-row-subtitle">%1$s</div>', esc_html__( 'Interactive Settings', 'wpforms-lite' ) );
'slug' => 'hide_camera_control',
'content' => $this->field_element(
'class' => 'wpforms-field-map-settings',
'map-control' => 'cameraControl',
'slug' => 'hide_camera_control',
'value' => isset( $field['hide_camera_control'] ) ? '1' : '0',
'desc' => esc_html__( 'Hide Camera Control ', 'wpforms-lite' ),
'content' => $this->field_element(
'class' => 'wpforms-field-map-settings',
'map-control' => 'zoomControl',
'value' => isset( $field['hide_zoom'] ) ? '1' : '0',
'desc' => esc_html__( 'Hide Zoom ', 'wpforms-lite' ),
'slug' => 'disable_dragging',
'content' => $this->field_element(
'slug' => 'disable_dragging',
'value' => isset( $field['disable_dragging'] ) ? '1' : '0',
'desc' => esc_html__( 'Disable Dragging ', 'wpforms-lite' ),
'slug' => 'disable_mouse_zooming',
'content' => $this->field_element(
'slug' => 'disable_mouse_zooming',
'value' => isset( $field['disable_mouse_zooming'] ) ? '1' : '0',
'desc' => esc_html__( 'Disable Mouse Zooming ', 'wpforms-lite' ),
printf( '<div class="wpforms-field-option-row-subtitle">%1$s</div>', esc_html__( 'Other', 'wpforms-lite' ) );
'slug' => 'show_in_entry',
'content' => $this->field_element(
'slug' => 'show_in_entry',
'value' => isset( $field['show_in_entry'] ) ? '1' : '0',
'desc' => esc_html__( 'Show in Entry ', 'wpforms-lite' ),
'slug' => 'show_thumbnail_in_entry',
'content' => $this->field_element(
'slug' => 'show_thumbnail_in_entry',
'value' => isset( $field['show_thumbnail_in_entry'] ) ? '1' : '0',
'desc' => esc_html__( 'Show Thumbnail in Entry ', 'wpforms-lite' ),