private function GeofieldMapFieldTrait::setCustomStyleMapElement in Geofield Map 8
Same name and namespace in other branches
- 8.2 src/GeofieldMapFieldTrait.php \Drupal\geofield_map\GeofieldMapFieldTrait::setCustomStyleMapElement()
Set Custom Map Style Element.
Parameters
array $settings: The Form Settings.
array $elements: The Form element to alter.
1 call to GeofieldMapFieldTrait::setCustomStyleMapElement()
- GeofieldMapFieldTrait::generateGmapSettingsForm in src/
GeofieldMapFieldTrait.php - Generate the Google Map Settings Form.
File
- src/
GeofieldMapFieldTrait.php, line 956
Class
- GeofieldMapFieldTrait
- Class GeofieldMapFieldTrait.
Namespace
Drupal\geofield_mapCode
private function setCustomStyleMapElement(array $settings, array &$elements) {
$elements['custom_style_map'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Custom Styled Map'),
];
$elements['custom_style_map']['custom_style_control'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Create a @custom_google_map_style_link.', [
'@custom_google_map_style_link' => $this->link
->generate($this
->t('Custom Google Map Style'), Url::fromUri('https://developers.google.com/maps/documentation/javascript/examples/maptype-styled-simple', [
'absolute' => TRUE,
'attributes' => [
'target' => 'blank',
],
])),
]),
'#description' => $this
->t('This option allows to create a new map type, which the user can select from the map type control. The map type includes custom styles.'),
'#default_value' => $settings['custom_style_map']['custom_style_control'],
'#return_value' => 1,
];
$elements['custom_style_map']['custom_style_name'] = [
'#type' => 'textfield',
'#title' => $this
->t('Custom Map Style Name'),
'#description' => $this
->t('Input the Name of the Custom Map Style you want to create.'),
'#default_value' => $settings['custom_style_map']['custom_style_name'],
'#placeholder' => $this
->t('My Custom Map Style'),
'#element_validate' => [
[
get_class($this),
'customMapStyleValidate',
],
],
];
$elements['custom_style_map']['custom_style_options'] = [
'#type' => 'textarea',
'#rows' => 5,
'#title' => $this
->t('Custom Map Style Options'),
'#description' => $this
->t('An object literal of map style options, that comply with the Google Maps JavaScript API.<br>The syntax should respect the javascript object notation (json) format.<br>As suggested in the field placeholder, always use double quotes (") both for the indexes and the string values.<br>(As a useful reference consider using @snappy_maps).', [
'@snappy_maps' => $this->link
->generate($this
->t('Snappy Maps'), Url::fromUri('https://snazzymaps.com', [
'absolute' => TRUE,
'attributes' => [
'target' => 'blank',
],
])),
]),
'#default_value' => $settings['custom_style_map']['custom_style_options'],
'#placeholder' => $this->customMapStylePlaceholder,
'#element_validate' => [
[
get_class($this),
'jsonValidate',
],
[
get_class($this),
'customMapStyleValidate',
],
],
];
$elements['custom_style_map']['custom_style_default'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Force the Custom Map Style as Default'),
'#description' => $this
->t('The Custom Map Style will be the Default starting one.'),
'#default_value' => $settings['custom_style_map']['custom_style_default'],
'#return_value' => 1,
];
if (isset($this->fieldDefinition)) {
$custom_style_map_control_selector = ':input[name="fields[' . $this->fieldDefinition
->getName() . '][settings_edit_form][settings][custom_style_map][custom_style_control]"]';
}
else {
$custom_style_map_control_selector = ':input[name="style_options[custom_style_map][custom_style_control]"]';
}
$elements['custom_style_map']['custom_style_name']['#states'] = [
'visible' => [
$custom_style_map_control_selector => [
'checked' => TRUE,
],
],
'required' => [
$custom_style_map_control_selector => [
'checked' => TRUE,
],
],
];
$elements['custom_style_map']['custom_style_options']['#states'] = [
'visible' => [
$custom_style_map_control_selector => [
'checked' => TRUE,
],
],
];
$elements['custom_style_map']['custom_style_default']['#states'] = [
'visible' => [
$custom_style_map_control_selector => [
'checked' => TRUE,
],
],
];
}