Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cloud-3354505
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
cloud-3354505
Commits
fcb3500f
Commit
fcb3500f
authored
1 year ago
by
xiaohua guan
Committed by
Yas Naoi
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3353595
by Xiaohua Guan, yas: Add location fields to Cloud dashboard admin settings form
parent
b16eaa5f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/cloud_dashboard/src/Form/Config/CloudDashboardAdminSettings.php
+156
-5
156 additions, 5 deletions
...dashboard/src/Form/Config/CloudDashboardAdminSettings.php
with
156 additions
and
5 deletions
modules/cloud_dashboard/src/Form/Config/CloudDashboardAdminSettings.php
+
156
−
5
View file @
fcb3500f
...
...
@@ -2,14 +2,90 @@
namespace
Drupal\cloud_dashboard\Form\Config
;
use
Drupal\cloud\Service\CloudServiceInterface
;
use
Drupal\Core\Config\ConfigFactoryInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Form\ConfigFormBase
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\Core\Locale\CountryManagerInterface
;
use
Drupal\Core\Routing\RouteProvider
;
use
Drupal\Core\Url
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
/**
* Class Cloud Admin Settings.
* Class Cloud
Dashboard
Admin Settings.
*/
class
CloudDashboardAdminSettings
extends
ConfigFormBase
{
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
$entityTypeManager
;
/**
* The country manager.
*
* @var \Drupal\Core\Locale\CountryManager
*/
protected
$countryManager
;
/**
* The cloud service.
*
* @var \Drupal\cloud\Service\CloudServiceInterface
*/
protected
$cloud
;
/**
* The route provider.
*
* @var \Drupal\Core\Routing\RouteProvider
*/
protected
$routeProvider
;
/**
* Constructs a AwsCloudAdminSettings object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Locale\CountryManagerInterface $country_manager
* Country Manager.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The Entity type manager.
* @param \Drupal\cloud\Service\CloudServiceInterface $cloud
* The cloud service.
* @param \Drupal\Core\Routing\RouteProvider $route_provider
* The route provider.
*/
public
function
__construct
(
ConfigFactoryInterface
$config_factory
,
CountryManagerInterface
$country_manager
,
EntityTypeManagerInterface
$entity_type_manager
,
CloudServiceInterface
$cloud
,
RouteProvider
$route_provider
)
{
parent
::
__construct
(
$config_factory
);
$this
->
countryManager
=
$country_manager
;
$this
->
entityTypeManager
=
$entity_type_manager
;
$this
->
cloud
=
$cloud
;
$this
->
routeProvider
=
$route_provider
;
}
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
)
{
return
new
static
(
$container
->
get
(
'config.factory'
),
$container
->
get
(
'country_manager'
),
$container
->
get
(
'entity_type.manager'
),
$container
->
get
(
'cloud'
),
$container
->
get
(
'router.route_provider'
)
);
}
/**
* {@inheritdoc}
*/
...
...
@@ -42,7 +118,7 @@ class CloudDashboardAdminSettings extends ConfigFormBase {
'#title'
=>
$this
->
t
(
'Callback URI for OAuth2'
),
'#default_value'
=>
$config
->
get
(
'oauth2_callback_uri'
),
'#description'
=>
$this
->
t
(
'If you leave this field blank, the callback URI will be the same as the consumer plugin at the server of Cloud Dashboard.'
),
'#attributes'
=>
[
'placeholder'
=>
'e.g. https://example.com/clouds/dashboard/callback'
],
'#attributes'
=>
[
'placeholder'
=>
'e.g. https://example.com/clouds/dashboard/callback'
],
];
$form
[
'custom_urls'
][
'oauth2_client_id'
]
=
[
...
...
@@ -50,7 +126,7 @@ class CloudDashboardAdminSettings extends ConfigFormBase {
'#title'
=>
$this
->
t
(
'Client ID for OAuth2'
),
'#default_value'
=>
$config
->
get
(
'oauth2_client_id'
),
'#description'
=>
$this
->
t
(
'If you leave this field blank, the client ID will be the same as the consumer plugin at the server of Cloud Dashboard.'
),
'#attributes'
=>
[
'placeholder'
=>
'e.g. e0a08590-4a13-419d-a64d-f859806c21a9'
],
'#attributes'
=>
[
'placeholder'
=>
'e.g. e0a08590-4a13-419d-a64d-f859806c21a9'
],
];
$form
[
'custom_urls'
][
'json_api_server_uri'
]
=
[
...
...
@@ -58,7 +134,7 @@ class CloudDashboardAdminSettings extends ConfigFormBase {
'#title'
=>
$this
->
t
(
'Server URL to get data by JSON:API'
),
'#default_value'
=>
$config
->
get
(
'json_api_server_uri'
),
'#description'
=>
$this
->
t
(
'If you leave this field blank, it will access the same server of Cloud Dashboard to retrieve the data.'
),
'#attributes'
=>
[
'placeholder'
=>
'e.g. https://example.com'
],
'#attributes'
=>
[
'placeholder'
=>
'e.g. https://example.com'
],
];
$form
[
'custom_urls'
][
'marker_icon_uri'
]
=
[
...
...
@@ -66,7 +142,7 @@ class CloudDashboardAdminSettings extends ConfigFormBase {
'#title'
=>
$this
->
t
(
'URL of default marker icon for Leaflet.js'
),
'#default_value'
=>
$config
->
get
(
'marker_icon_uri'
),
'#description'
=>
$this
->
t
(
'If you leave this field blank, it will access data from CDN'
),
'#attributes'
=>
[
'placeholder'
=>
'e.g. https://example.com/marker-icon.png'
],
'#attributes'
=>
[
'placeholder'
=>
'e.g. https://example.com/marker-icon.png'
],
];
$form
[
'custom_urls'
][
'map_geojson_uri'
]
=
[
...
...
@@ -77,6 +153,74 @@ class CloudDashboardAdminSettings extends ConfigFormBase {
'#attributes'
=>
[
'placeholder'
=>
'e.g. https://example.com/world_map.geojson'
],
];
$form
[
'location_map'
]
=
[
'#type'
=>
'details'
,
'#title'
=>
$this
->
t
(
'Location map'
),
'#open'
=>
TRUE
,
];
$form
[
'location_map'
][
'country'
]
=
[
'#type'
=>
'select'
,
'#title'
=>
$this
->
t
(
'Country'
),
'#options'
=>
$this
->
countryManager
->
getStandardList
(),
'#required'
=>
TRUE
,
'#default_value'
=>
$config
->
get
(
'location_map_country'
),
];
$form
[
'location_map'
][
'city'
]
=
[
'#type'
=>
'textfield'
,
'#title'
=>
$this
->
t
(
'City'
),
'#required'
=>
TRUE
,
'#default_value'
=>
$config
->
get
(
'location_map_city'
),
];
$form
[
'location_map'
][
'latitude'
]
=
[
'#type'
=>
'number'
,
'#title'
=>
$this
->
t
(
'Latitude'
),
'#max'
=>
'90'
,
'#min'
=>
'-90'
,
'#step'
=>
0.000001
,
'#required'
=>
TRUE
,
'#default_value'
=>
$config
->
get
(
'location_map_latitude'
),
];
$form
[
'location_map'
][
'longitude'
]
=
[
'#type'
=>
'number'
,
'#title'
=>
$this
->
t
(
'Longitude'
),
'#max'
=>
'180'
,
'#min'
=>
'-180'
,
'#step'
=>
0.000001
,
'#required'
=>
TRUE
,
'#default_value'
=>
$config
->
get
(
'location_map_longitude'
),
];
$form
[
'location_map'
][
'zoom_rate'
]
=
[
'#type'
=>
'select'
,
'#title'
=>
$this
->
t
(
'Zoom rate'
),
'#required'
=>
TRUE
,
'#empty_value'
=>
''
,
'#default_value'
=>
$config
->
get
(
'location_map_zoom_rate'
),
'#options'
=>
[
'1'
=>
$this
->
t
(
'1'
),
'2'
=>
$this
->
t
(
'2'
),
'3'
=>
$this
->
t
(
'3'
),
'4'
=>
$this
->
t
(
'4'
),
],
];
if
(
$this
->
cloud
->
isGeocoderAvailable
())
{
$path
=
$this
->
routeProvider
->
getRouteByName
(
'entity.cloud_config.geocoder'
)
->
getPath
();
$path
=
str_replace
(
'{country}'
,
'country'
,
$path
);
$path
=
str_replace
(
'{city}'
,
'city'
,
$path
);
$url
=
Url
::
fromUri
(
'internal:'
.
$path
);
$form
[
'#attached'
][
'library'
]
=
'cloud/cloud_geocoder'
;
$form
[
'#attached'
][
'drupalSettings'
][
'cloud'
][
'geocoder_url'
]
=
$url
->
toString
();
$form
[
'#attached'
][
'drupalSettings'
][
'cloud'
][
'country_id'
]
=
'edit-country'
;
$form
[
'#attached'
][
'drupalSettings'
][
'cloud'
][
'city_id'
]
=
'edit-city'
;
$form
[
'#attached'
][
'drupalSettings'
][
'cloud'
][
'latitude_id'
]
=
'edit-latitude'
;
$form
[
'#attached'
][
'drupalSettings'
][
'cloud'
][
'longitude_id'
]
=
'edit-longitude'
;
}
return
parent
::
buildForm
(
$form
,
$form_state
);
}
...
...
@@ -93,6 +237,13 @@ class CloudDashboardAdminSettings extends ConfigFormBase {
$config
->
set
(
'json_api_server_uri'
,
$form_state
->
getValue
(
'json_api_server_uri'
));
$config
->
set
(
'marker_icon_uri'
,
$form_state
->
getValue
(
'marker_icon_uri'
));
$config
->
set
(
'map_geojson_uri'
,
$form_state
->
getValue
(
'map_geojson_uri'
));
$config
->
set
(
'location_map_country'
,
$form_state
->
getValue
(
'country'
));
$config
->
set
(
'location_map_city'
,
$form_state
->
getValue
(
'city'
));
$config
->
set
(
'location_map_latitude'
,
$form_state
->
getValue
(
'latitude'
));
$config
->
set
(
'location_map_longitude'
,
$form_state
->
getValue
(
'longitude'
));
$config
->
set
(
'location_map_zoom_rate'
,
$form_state
->
getValue
(
'zoom_rate'
));
$config
->
save
();
parent
::
submitForm
(
$form
,
$form_state
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment