Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Field Type: Address / Map #3634

Open
wants to merge 102 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
b7c4f9a
First commit for address/map field patched from https://github.com/po…
JoryHogeveen Jul 3, 2016
5dab8ee
First version of Address field
JoryHogeveen Aug 6, 2016
4af54f3
Improve microdata handler
JoryHogeveen Aug 6, 2016
20dc696
First commit for Maps component
JoryHogeveen Aug 6, 2016
ba9b3c8
Improve HTML and microdata formatting
JoryHogeveen Aug 6, 2016
f60e716
Improve UX and options for Maps component
JoryHogeveen Aug 6, 2016
7b8f3cf
First commit for Google Maps API class
JoryHogeveen Aug 10, 2016
cc95f1a
plugin_dir_path already has a trailing slash
JoryHogeveen Aug 10, 2016
46c973b
Prepend option names with "map_"
JoryHogeveen Aug 10, 2016
c4e7979
var api_key needs to be static + api_key disable apikey for geocode t…
JoryHogeveen Aug 10, 2016
a23c249
Add assets
JoryHogeveen Aug 10, 2016
d25be8b
Base of backend field working
JoryHogeveen Aug 10, 2016
77ffb87
Just the old file, this is where the frond-end code will go
JoryHogeveen Aug 10, 2016
12ffa74
Generate hidden lat/lng fields for geo storage on the field UI
JoryHogeveen Aug 10, 2016
af5a958
Patch the lat/lng field to the component UI directory + fix field types
JoryHogeveen Aug 10, 2016
76cebc6
JS fixes for geodata
JoryHogeveen Aug 10, 2016
b61ac52
geocoder url can be public + append json by default
JoryHogeveen Aug 10, 2016
2fd49f6
Put lat/lng data in its own array key (geo)
JoryHogeveen Aug 10, 2016
a549dab
Geo data validation (serverside) + main geocoder methods that call pr…
JoryHogeveen Aug 10, 2016
e94716f
Rebuild Maps field JS
JoryHogeveen Aug 10, 2016
1a6db8a
pods-maps.js and its JS object (PodsMaps) are probably not needed any…
JoryHogeveen Aug 10, 2016
d99b58d
Put output options formatting in dedicated function
JoryHogeveen Aug 11, 2016
fade4ec
Docs, comments
JoryHogeveen Aug 11, 2016
8051a86
dragend event instead of mouseup
JoryHogeveen Aug 11, 2016
c086c54
Maps in full with + padding for labels
JoryHogeveen Aug 11, 2016
b55443a
InfoWindow basics
JoryHogeveen Aug 11, 2016
72d0d31
@todo check pregreplace, maybe this can be done better (nl2br not wor…
JoryHogeveen Aug 11, 2016
884d8c4
InfoWindow custom content option dependencies
JoryHogeveen Aug 11, 2016
c5334f0
Update description style when it's directly after a label
JoryHogeveen Aug 11, 2016
773a0ec
InfoWindow explanation for magictags
JoryHogeveen Aug 11, 2016
68bd618
InfoWindows done
JoryHogeveen Aug 11, 2016
210d680
Comment sections
JoryHogeveen Aug 11, 2016
5dbfb05
2 custom input options for infowindows (paragraph, wysiwyg) + set opt…
JoryHogeveen Aug 11, 2016
8b6fc49
Add validate & pre_save filters
JoryHogeveen Aug 17, 2016
a344df0
Remove unused code (this is now in the Maps component)
JoryHogeveen Aug 17, 2016
837215d
Freeform input type within address field view
JoryHogeveen Aug 17, 2016
ea167da
Freeform input + JS improvements
JoryHogeveen Aug 17, 2016
5df6036
Output options for pick type (regions & countries)
JoryHogeveen Aug 11, 2016
ebeb113
Make field label translatable
JoryHogeveen Nov 5, 2016
7670735
Rename map.php to map-google.php
JoryHogeveen Dec 8, 2016
8af5fef
php linter
JoryHogeveen Dec 8, 2016
7ec0a0c
Defai;t type is address
JoryHogeveen Dec 8, 2016
bd81ae9
Prevent overwriting the $value var
JoryHogeveen Dec 8, 2016
9b64796
Implement frontend display hook basics
JoryHogeveen Dec 8, 2016
65b28b0
Add more todo's + prepare provider specific js files
JoryHogeveen Dec 8, 2016
df04817
Merge remote-tracking branch 'refs/remotes/origin/release/2.7' into f…
JoryHogeveen Mar 29, 2017
6bccbe2
Remove field type from maps options
JoryHogeveen Mar 29, 2017
8092899
Basic front-end maps are now working
JoryHogeveen Mar 29, 2017
4d55c3b
Remove dev leftovers
JoryHogeveen Mar 29, 2017
9c145db
Improve naming and structure
JoryHogeveen Mar 29, 2017
3100b94
Merge branch 'release/2.7' into feature/#657_address_map_field
sc0ttkclark Apr 21, 2017
ad20398
Merge branch 'release/2.7' into feature/#657_address_map_field
sc0ttkclark Apr 22, 2017
b63f335
Ensure add button is i18n'd
sc0ttkclark Apr 22, 2017
5b8007a
Hack around component setting saving for file field types, the post d…
sc0ttkclark Apr 22, 2017
48176e5
Fix phpdoc
sc0ttkclark Apr 22, 2017
d68e720
Fix selected handling for single-value or multi-value simple pick fields
sc0ttkclark Apr 22, 2017
d211860
Add display_list handling (just display once, not for every key in ou…
sc0ttkclark Apr 22, 2017
e6cd840
Add output escaping and get image url from marker file ID
sc0ttkclark Apr 22, 2017
e7fa680
Whitespace tweak
sc0ttkclark Apr 22, 2017
33d202a
Handle file/pick array needs for saving single/multi values
sc0ttkclark Apr 22, 2017
dbca0ad
Remove some unneeded files
sc0ttkclark Apr 22, 2017
11e0cb2
Formatting stuff
sc0ttkclark Apr 22, 2017
7bdbecb
Handle output display option
sc0ttkclark Apr 22, 2017
fb3169c
code formatting and output escaping for address
sc0ttkclark Apr 22, 2017
25b8871
Fix geo lookup location button
JoryHogeveen Apr 22, 2017
bc0e18c
Marker icon field input + improve var declaration
JoryHogeveen Apr 22, 2017
8df6988
Marker icon display
JoryHogeveen Apr 22, 2017
f11511d
Fix map type display
JoryHogeveen Apr 22, 2017
e1b5eb7
Set infowindow triggers on display field
JoryHogeveen Apr 22, 2017
c802138
Add filters to add your own custom maps provider
JoryHogeveen Apr 22, 2017
ee32887
Add todo's for maps options. These can be different for each provider.
JoryHogeveen Apr 22, 2017
e592699
Better method names for providers
JoryHogeveen Apr 22, 2017
43ac8d2
Improve code readability
JoryHogeveen Apr 22, 2017
b884c35
Merge branch 'release/2.7' into feature/#657_address_map_field
sc0ttkclark Apr 23, 2017
853a958
Merge branch 'release/2.7' into feature/#657_address_map_field
sc0ttkclark May 16, 2017
8b27af4
Merge branch 'release/2.7' into feature/#657_address_map_field
sc0ttkclark May 17, 2017
b9d46ce
Use pods_v()
JoryHogeveen May 22, 2017
0afc085
Option to disable the scrollwheel + use pods_v()
JoryHogeveen May 22, 2017
c79b0b4
Refactor google maps display to work with multiple values.
JoryHogeveen May 23, 2017
b8c0858
Typo
JoryHogeveen May 23, 2017
9357d7a
Allow values to overwrite the field marker
JoryHogeveen May 23, 2017
a24e6da
Ensure geodata is passed as float values
JoryHogeveen May 23, 2017
c018f0e
Maps provider interface
JoryHogeveen Dec 6, 2017
5e8db12
Move provider related map options into the provider class
JoryHogeveen Dec 6, 2017
1f77bb2
Get template titles helper
JoryHogeveen Dec 6, 2017
58e5ce3
Autocomplete option + filter
JoryHogeveen Dec 6, 2017
ce65b73
Enhance error handling
JoryHogeveen Dec 6, 2017
8db630a
autocorrect option setting
JoryHogeveen Dec 6, 2017
7f3496f
Fix method name
JoryHogeveen Dec 6, 2017
89b3463
Check display setting, use pods_v & phpdoc
JoryHogeveen Dec 6, 2017
ca1fc12
Only return string values for address parts
JoryHogeveen Dec 6, 2017
d949a24
Google address data handler enhancements + filter
JoryHogeveen Dec 6, 2017
18623a1
Try again if Google failes the first time
JoryHogeveen Dec 6, 2017
b3e0022
phpDoc
JoryHogeveen Dec 6, 2017
4e92cad
Option handler fixes
JoryHogeveen Dec 6, 2017
5450078
Code format
JoryHogeveen Dec 6, 2017
e71287d
Handle multiple values
JoryHogeveen Dec 6, 2017
f52d540
Option to use templates as infowindow content
JoryHogeveen Dec 6, 2017
f270c00
Option to combine equal geo locations (!! no UI for this yet !!)
JoryHogeveen Dec 6, 2017
a752bf0
map container atts
JoryHogeveen Dec 6, 2017
1267057
Autoclose open infowindows if a new window is clicked
JoryHogeveen Dec 6, 2017
8ea91bf
Autozoom when there are multiple values (!! no UI for this yet !!)
JoryHogeveen Dec 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 85 additions & 25 deletions classes/PodsComponents.php
Original file line number Diff line number Diff line change
Expand Up @@ -705,38 +705,98 @@ public function admin_ajax () {
die(); // KBAI!
}

public function admin_ajax_settings ( $component, $params ) {
if ( !isset( $this->components[ $component ] ) )
wp_die( 'Invalid Component', '', array( 'back_link' => true ) );
elseif ( !method_exists( $this->components[ $component ][ 'object' ], 'options' ) )
pods_error( 'Component options method does not exist', $this );
public function admin_ajax_settings( $component, $params ) {

$options = $this->components[ $component ][ 'object' ]->options( $this->settings[ 'components' ][ $component ] );
if ( ! isset( $this->components[ $component ] ) ) {
wp_die( 'Invalid Component', '', array( 'back_link' => true ) );
} elseif ( ! method_exists( $this->components[ $component ]['object'], 'options' ) ) {
pods_error( 'Component options method does not exist', $this );
}

if ( empty( $this->settings[ 'components' ][ $component ] ) )
$this->settings[ 'components' ][ $component ] = array();
$options = $this->components[ $component ]['object']->options( $this->settings['components'][ $component ] );

foreach ( $options as $field_name => $field_option ) {
$field_option = PodsForm::field_setup( $field_option, null, $field_option[ 'type' ] );
if ( empty( $this->settings['components'][ $component ] ) ) {
$this->settings['components'][ $component ] = array();
}

if ( !is_array( $field_option[ 'group' ] ) ) {
$field_value = pods_var_raw( 'pods_setting_' . $field_name, $params );
// @todo Use save_pod_item() functionality instead, this doesn't cover much

$this->settings[ 'components' ][ $component ][ $field_name ] = $field_value;
}
else {
foreach ( $field_option[ 'group' ] as $field_group_name => $field_group_option ) {
$field_value = pods_var_raw( 'pods_setting_' . $field_group_name, $params );
foreach ( $options as $field_name => $field_option ) {
$field_option = PodsForm::field_setup( $field_option, null, $field_option['type'] );

$this->settings[ 'components' ][ $component ][ $field_group_name ] = $field_value;
}
}
}
if ( ! is_array( $field_option['group'] ) ) {
$field_value = pods_var_raw( 'pods_setting_' . $field_name, $params );

$settings = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $this->settings, JSON_UNESCAPED_UNICODE ) : json_encode( $this->settings );
if ( in_array( $field_option['type'], array( 'pick', 'file' ), true ) ) {
$field_value = $this->handle_pick_file_value_saving( $field_value, $field_option );
}

update_option( 'pods_component_settings', $settings );
$this->settings['components'][ $component ][ $field_name ] = $field_value;
} else {
foreach ( $field_option['group'] as $field_group_name => $field_group_option ) {
$field_value = pods_var_raw( 'pods_setting_' . $field_group_name, $params );

if ( in_array( $field_group_option['type'], array( 'pick', 'file' ), true ) ) {
$field_value = $this->handle_pick_file_value_saving( $field_value, $field_group_option );
}

$this->settings['components'][ $component ][ $field_group_name ] = $field_value;
}
}
}

$settings = version_compare( PHP_VERSION, '5.4.0', '>=' ) ? json_encode( $this->settings, JSON_UNESCAPED_UNICODE ) : json_encode( $this->settings );

update_option( 'pods_component_settings', $settings );

return '1';

}

/**
* Handle saving for file/pick fields which requires some array work
*
* @param array|string $value
* @param array $field
*
* @return array|string
*/
public function handle_pick_file_value_saving( $value, $field ) {

if ( empty( $value ) ) {
$value = array();
} elseif ( ! is_array( $value ) ) {
$value = array( $value );
}

if ( 'file' === $field['type'] && ! empty( $value ) ) {
// Fix file upload saved values coming from submission
$first_value = current( $value );

if ( is_array( $first_value ) && ! empty( $first_value['id'] ) ) {
$value = wp_list_pluck( $value, 'id' );
$value = array_map( 'absint', $value );
}
}

if ( $value ) {
$single = false;

if ( 'single' === pods_v( $field['type'] . '_format_type', $field, 'single', true ) ) {
$single = true;
} elseif ( 1 === (int) pods_v( $field['type'] . '_limit', $field ) ) {
$single = true;
}

if ( $single ) {
$value = current( $value );
}
} else {
$value = '';
}

return $value;

}

return '1';
}
}
2 changes: 1 addition & 1 deletion classes/PodsField.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function value( $value = null, $name = null, $options = null, $pod = null
}

/**
* Change the way the value of the field is displayed with Pods::get
* Change the way the value of the field is displayed with Pods::field
*
* @param mixed|null $value
* @param string|null $name
Expand Down
42 changes: 33 additions & 9 deletions classes/PodsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,15 +953,38 @@ public static function display( $type, $value = null, $name = null, $options = n

$tableless_field_types = self::tableless_field_types();

if ( method_exists( self::$loaded[ $type ], 'display' ) ) {
if ( is_array( $value ) && !in_array( $type, $tableless_field_types ) ) {
foreach ( $value as $k => $display_value ) {
$value[ $k ] = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array( $display_value, $name, $options, $pod, $id, $traverse ) );
}
}
else
$value = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array( $value, $name, $options, $pod, $id, $traverse ) );
}
if ( method_exists( self::$loaded[ $type ], 'display_list' ) ) {
$value = call_user_func_array( array( self::$loaded[ $type ], 'display_list' ), array(
$value,
$name,
$options,
$pod,
$id,
$traverse
) );
} elseif ( method_exists( self::$loaded[ $type ], 'display' ) ) {
if ( is_array( $value ) && ! in_array( $type, $tableless_field_types ) ) {
foreach ( $value as $k => $display_value ) {
$value[ $k ] = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array(
$display_value,
$name,
$options,
$pod,
$id,
$traverse
) );
}
} else {
$value = call_user_func_array( array( self::$loaded[ $type ], 'display' ), array(
$value,
$name,
$options,
$pod,
$id,
$traverse
) );
}
}

$value = apply_filters( 'pods_form_display_' . $type, $value, $name, $options, $pod, $id, $traverse );

Expand Down Expand Up @@ -1398,6 +1421,7 @@ public static function field_types() {
'boolean',
'color',
'slug',
'address',
);

$field_types = array_merge( $field_types, array_keys( self::$field_types ) );
Expand Down
Loading