diff --git a/modules/acquia_cms_tour/src/Controller/DashboardController.php b/modules/acquia_cms_tour/src/Controller/DashboardController.php index aba60a25d..1892b3d24 100644 --- a/modules/acquia_cms_tour/src/Controller/DashboardController.php +++ b/modules/acquia_cms_tour/src/Controller/DashboardController.php @@ -3,7 +3,7 @@ namespace Drupal\acquia_cms_tour\Controller; use Drupal\acquia_cms_tour\Form\AcquiaConnectorForm; -use Drupal\acquia_cms_tour\Form\AcquiaGoogleMapsAPIForm; +use Drupal\acquia_cms_tour\Form\AcquiaGoogleMapsApiDashboardForm; use Drupal\acquia_cms_tour\Form\AcquiaSearchSolrForm; use Drupal\acquia_cms_tour\Form\AcquiaTelemetryForm; use Drupal\acquia_cms_tour\Form\GoogleAnalyticsForm; @@ -12,6 +12,7 @@ use Drupal\acquia_cms_tour\Form\SiteStudioCoreForm; use Drupal\Core\Controller\ControllerBase; use Drupal\Core\DependencyInjection\ClassResolverInterface; +use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\State\StateInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -39,6 +40,13 @@ final class DashboardController extends ControllerBase { */ protected $state; + /** + * The module handler. + * + * @var \Drupal\Core\Extension\ModuleHandlerInterface + */ + protected $moduleHandler; + /** * The sub-controllers to invoke in order to build the tour page. * @@ -49,7 +57,7 @@ final class DashboardController extends ControllerBase { 'acquia_connector_form' => AcquiaConnectorForm::class, 'acquia_solr_search_form' => AcquiaSearchSolrForm::class, 'google_analytics_form' => GoogleAnalyticsForm::class, - 'acquia_google_maps_api' => AcquiaGoogleMapsAPIForm::class, + 'acquia_google_maps_api' => AcquiaGoogleMapsApiDashboardForm::class, 'recaptcha_form' => RecaptchaForm::class, 'google_tag_manager_form' => GoogleTagManagerForm::class, 'acquia_telemetry' => AcquiaTelemetryForm::class, @@ -60,11 +68,14 @@ final class DashboardController extends ControllerBase { * * @param \Drupal\Core\State\StateInterface $state * The state service. + * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler + * The module handler service. * @param \Drupal\Core\DependencyInjection\ClassResolverInterface $class_resolver * The class resolver. */ - public function __construct(StateInterface $state, ClassResolverInterface $class_resolver) { + public function __construct(StateInterface $state, ModuleHandlerInterface $module_handler, ClassResolverInterface $class_resolver) { $this->state = $state; + $this->module_handler = $module_handler; $this->classResolver = $class_resolver; } @@ -91,6 +102,7 @@ private function getSectionOutput(string $key, string $controller_class) { public static function create(ContainerInterface $container) { return new static( $container->get('state'), + $container->get('module_handler'), $container->get('class_resolver') ); } @@ -124,10 +136,12 @@ public function content() { $count = 0; $item_count = 0; foreach (static::SECTIONS as $key => $controller) { - $count++; $build[$key] = $this->getSectionOutput($key, $controller); $state_var = $this->classResolver->getInstanceFromDefinition($controller)->getProgressState(); - if ($state_var) { + if (isset($state_var['total'])) { + $count++; + } + if (isset($state_var['count']) && $state_var['count']) { $item_count++; } } diff --git a/modules/acquia_cms_tour/src/Form/AcquiaConnectorForm.php b/modules/acquia_cms_tour/src/Form/AcquiaConnectorForm.php index 7ac12cea4..6ffea9f03 100644 --- a/modules/acquia_cms_tour/src/Form/AcquiaConnectorForm.php +++ b/modules/acquia_cms_tour/src/Form/AcquiaConnectorForm.php @@ -169,8 +169,12 @@ public function ignoreConfig(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function getProgressState() { - $acquia_connector_progress = $this->state->get('acquia_connector_progress'); - return $acquia_connector_progress; + if ($this->module_handler->moduleExists('acquia_connector')) { + return [ + 'total' => 1, + 'count' => $this->state->get('acquia_connector_progress'), + ]; + } } } diff --git a/modules/acquia_cms_tour/src/Form/AcquiaGoogleMapsAPIForm.php b/modules/acquia_cms_tour/src/Form/AcquiaGoogleMapsAPIForm.php index 526795fa3..c0f60d995 100644 --- a/modules/acquia_cms_tour/src/Form/AcquiaGoogleMapsAPIForm.php +++ b/modules/acquia_cms_tour/src/Form/AcquiaGoogleMapsAPIForm.php @@ -2,14 +2,8 @@ namespace Drupal\acquia_cms_tour\Form; -use Drupal\Core\Entity\EntityTypeManagerInterface; -use Drupal\Core\Extension\InfoParserInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\State\StateInterface; -use Drupal\Core\Url; -use Drupal\Core\Utility\LinkGeneratorInterface; use Drupal\geocoder\GeocoderProviderInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -18,43 +12,6 @@ */ final class AcquiaGoogleMapsAPIForm extends ConfigFormBase { - /** - * The entity type manager. - * - * @var \Drupal\Core\Entity\EntityTypeManagerInterface - */ - protected $entityTypeManager; - - - /** - * The state service. - * - * @var \Drupal\Core\State\StateInterface - */ - protected $state; - - /** - * The module handler. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - - /** - * The info file parser. - * - * @var \Drupal\Core\Extension\InfoParserInterface - */ - protected $infoParser; - - /** - * The link generator. - * - * @var \Drupal\Core\Utility\LinkGeneratorInterface - */ - protected $linkGenerator; - /** * The Geocoder provider entity storage handler. * @@ -62,44 +19,18 @@ final class AcquiaGoogleMapsAPIForm extends ConfigFormBase { */ private $geocoderProviderStorage; - /** - * AcquiaTelemetryForm constructor. - * - * @param \Drupal\Core\State\StateInterface $state - * The state service. - * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager - * The entity type manager. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler service. - * @param \Drupal\Core\Extension\InfoParserInterface $info_parser - * The info file parser. - * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator - * The link generator. - */ - public function __construct(StateInterface $state, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, InfoParserInterface $info_parser, LinkGeneratorInterface $link_generator) { - $this->state = $state; - $this->entityTypeManager = $entity_type_manager; - $this->module_handler = $module_handler; - $this->infoParser = $info_parser; - $this->linkGenerator = $link_generator; - if ($entity_type_manager->hasDefinition('geocoder_provider')) { - $this->geocoderProviderStorage = $entity_type_manager->getStorage('geocoder_provider'); - } - - } - /** * {@inheritdoc} */ public static function create(ContainerInterface $container) { - return new static( - $container->get('state'), - $container->get('entity_type.manager'), - $container->get('module_handler'), - $container->get('info_parser'), - $container->get('link_generator') - - ); + /** @var static $instance */ + $instance = parent::create($container); + + $entity_type_manager = $container->get('entity_type.manager'); + if ($entity_type_manager->hasDefinition('geocoder_provider')) { + $instance->geocoderProviderStorage = $entity_type_manager->getStorage('geocoder_provider'); + } + return $instance; } /** @@ -123,62 +54,34 @@ public function buildForm(array $form, FormStateInterface $form_state) { // Text input for Google Maps. ACMS can use the Gmaps API in two totally // different features (Site Studio and Place nodes). Site Studio is always // enabled in ACMS, but Place may not. - $module = 'geocoder'; - if ($this->getProgressState()) { - $form['acquia_telemetry']['check_icon'] = [ - '#prefix' => '', - '#suffix' => "", - ]; - } - if ($this->module_handler->moduleExists($module)) { - $module_path = $this->module_handler->getModule($module)->getPathname(); - $module_info = $this->infoParser->parse($module_path); - $maps_api_key = $this->config('cohesion.settings') - ->get('google_map_api_key'); - $provider = $this->loadProvider(); - if ($provider) { - $configuration = $provider->get('configuration'); - $maps_api_key = $configuration['apiKey']; - } - $form['acquia_google_maps_api_wrapper'] = [ - '#type' => 'details', - '#title' => $module_info['name'], - '#collapsible' => TRUE, - '#collapsed' => TRUE, - ]; - $form['acquia_google_maps_api_wrapper']['acquia_google_maps_api'] = [ - 'maps_api_key' => [ - '#type' => 'textfield', - '#title' => $this->t('Maps API key'), - '#placeholder' => '1234abcd', - '#description' => $this->t('Enter your Google Maps API Key to automatically generate maps for Place content in Acquia CMS.'), - '#default_value' => $maps_api_key, - '#required' => TRUE, - '#prefix' => '
' . $module_info['description'], - '#suffix' => "
", - ], - ]; - $form['acquia_google_maps_api_wrapper']['actions']['submit'] = [ - '#type' => 'submit', - '#value' => 'Save', - '#submit' => ['::saveConfig'], - '#prefix' => '
', - ]; - $form['acquia_google_maps_api_wrapper']['actions']['ignore'] = [ - '#type' => 'submit', - '#value' => 'Ignore', - '#submit' => ['::ignoreConfig'], - ]; - $form['acquia_google_maps_api_wrapper']['actions']['advanced'] = [ - '#markup' => $this->linkGenerator->generate( - 'Advanced', - Url::fromRoute('entity.geocoder_provider.collection') - ), - '#suffix' => "
", - ]; - - return $form; + $maps_api_key = $this->config('cohesion.settings') + ->get('google_map_api_key'); + + $provider = $this->loadProvider(); + if ($provider) { + $configuration = $provider->get('configuration'); + $maps_api_key = $configuration['apiKey']; } + + $form['acquia_google_maps_api'] = [ + 'maps_api_key' => [ + '#type' => 'textfield', + '#title' => $this->t('Maps API key'), + '#description' => $this->t('Enter your Google Maps API Key to automatically generate maps for Place content in Acquia CMS.'), + '#default_value' => $maps_api_key, + '#required' => TRUE, + ], + '#type' => 'fieldset', + '#open' => TRUE, + '#title' => $this->t('Google Maps'), + ]; + + $form['acquia_google_maps_api']['submit'] = [ + '#type' => 'submit', + '#value' => $this->t('Save'), + '#button_type' => 'primary', + ]; + return $form; } /** @@ -197,7 +100,7 @@ private function loadProvider() : ?GeocoderProviderInterface { /** * {@inheritdoc} */ - public function saveConfig(array &$form, FormStateInterface $form_state) { + public function submitForm(array &$form, FormStateInterface $form_state) { $maps_api_key = $form_state->getValue('maps_api_key'); // Configure Google Maps API Key for both Site Studio and @@ -205,7 +108,7 @@ public function saveConfig(array &$form, FormStateInterface $form_state) { $this->config('cohesion.settings') ->set('google_map_api_key', $maps_api_key) ->save(TRUE); - $this->state->set('acquia_google_maps_progress', TRUE); + $provider = $this->loadProvider(); if ($provider) { $configuration = $provider->get('configuration'); @@ -217,18 +120,4 @@ public function saveConfig(array &$form, FormStateInterface $form_state) { $this->messenger()->addStatus('The Google Maps API key has been set.'); } - /** - * {@inheritdoc} - */ - public function ignoreConfig(array &$form, FormStateInterface $form_state) { - $this->state->set('acquia_google_maps_progress', TRUE); - } - - /** - * {@inheritdoc} - */ - public function getProgressState() { - return($this->state->get('acquia_google_maps_progress')); - } - } diff --git a/modules/acquia_cms_tour/src/Form/AcquiaGoogleMapsApiDashboardForm.php b/modules/acquia_cms_tour/src/Form/AcquiaGoogleMapsApiDashboardForm.php new file mode 100644 index 000000000..5376f227e --- /dev/null +++ b/modules/acquia_cms_tour/src/Form/AcquiaGoogleMapsApiDashboardForm.php @@ -0,0 +1,239 @@ +state = $state; + $this->entityTypeManager = $entity_type_manager; + $this->module_handler = $module_handler; + $this->infoParser = $info_parser; + $this->linkGenerator = $link_generator; + if ($entity_type_manager->hasDefinition('geocoder_provider')) { + $this->geocoderProviderStorage = $entity_type_manager->getStorage('geocoder_provider'); + } + + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container) { + return new static( + $container->get('state'), + $container->get('entity_type.manager'), + $container->get('module_handler'), + $container->get('info_parser'), + $container->get('link_generator') + + ); + } + + /** + * {@inheritdoc} + */ + public function getFormId() { + return 'acquia_google_maps_api_form'; + } + + /** + * {@inheritdoc} + */ + protected function getEditableConfigNames() { + return ['cohesion.settings']; + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, FormStateInterface $form_state) { + // Text input for Google Maps. ACMS can use the Gmaps API in two totally + // different features (Site Studio and Place nodes). Site Studio is always + // enabled in ACMS, but Place may not. + $module = 'geocoder'; + if ($this->getProgressState()) { + $form['acquia_telemetry']['check_icon'] = [ + '#prefix' => '', + '#suffix' => "", + ]; + } + if ($this->module_handler->moduleExists($module)) { + $module_path = $this->module_handler->getModule($module)->getPathname(); + $module_info = $this->infoParser->parse($module_path); + $maps_api_key = $this->config('cohesion.settings') + ->get('google_map_api_key'); + $provider = $this->loadProvider(); + if ($provider) { + $configuration = $provider->get('configuration'); + $maps_api_key = $configuration['apiKey']; + } + $form['acquia_google_maps_api_wrapper'] = [ + '#type' => 'details', + '#title' => $module_info['name'], + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ]; + $form['acquia_google_maps_api_wrapper']['acquia_google_maps_api'] = [ + 'maps_api_key' => [ + '#type' => 'textfield', + '#title' => $this->t('Maps API key'), + '#placeholder' => '1234abcd', + '#description' => $this->t('Enter your Google Maps API Key to automatically generate maps for Place content in Acquia CMS.'), + '#default_value' => $maps_api_key, + '#required' => TRUE, + '#prefix' => '
' . $module_info['description'], + '#suffix' => "
", + ], + ]; + $form['acquia_google_maps_api_wrapper']['actions']['submit'] = [ + '#type' => 'submit', + '#value' => 'Save', + '#submit' => ['::saveConfig'], + '#prefix' => '
', + ]; + $form['acquia_google_maps_api_wrapper']['actions']['ignore'] = [ + '#type' => 'submit', + '#value' => 'Ignore', + '#submit' => ['::ignoreConfig'], + ]; + $form['acquia_google_maps_api_wrapper']['actions']['advanced'] = [ + '#markup' => $this->linkGenerator->generate( + 'Advanced', + Url::fromRoute('entity.geocoder_provider.collection') + ), + '#suffix' => "
", + ]; + + return $form; + } + } + + /** + * Loads the Geocoder provider for Google Maps, if it exists. + * + * @return \Drupal\geocoder\GeocoderProviderInterface|null + * The Geocoder provider entity, or NULL if it does not exist. + */ + private function loadProvider() : ?GeocoderProviderInterface { + if ($this->geocoderProviderStorage) { + return $this->geocoderProviderStorage->load('googlemaps'); + } + return NULL; + } + + /** + * {@inheritdoc} + */ + public function saveConfig(array &$form, FormStateInterface $form_state) { + $maps_api_key = $form_state->getValue('maps_api_key'); + + // Configure Google Maps API Key for both Site Studio and + // Geocoder module. + $this->config('cohesion.settings') + ->set('google_map_api_key', $maps_api_key) + ->save(TRUE); + $this->state->set('acquia_google_maps_progress', TRUE); + $provider = $this->loadProvider(); + if ($provider) { + $configuration = $provider->get('configuration'); + $configuration['apiKey'] = $maps_api_key; + $provider->set('configuration', $configuration); + $this->geocoderProviderStorage->save($provider); + } + + $this->messenger()->addStatus('The Google Maps API key has been set.'); + } + + /** + * {@inheritdoc} + */ + public function ignoreConfig(array &$form, FormStateInterface $form_state) { + $this->state->set('acquia_google_maps_progress', TRUE); + } + + /** + * {@inheritdoc} + */ + public function getProgressState() { + if ($this->module_handler->moduleExists('geocoder')) { + return [ + 'total' => 1, + 'count' => $this->state->get('acquia_google_maps_progress'), + ]; + } + } + +} diff --git a/modules/acquia_cms_tour/src/Form/AcquiaSearchSolrForm.php b/modules/acquia_cms_tour/src/Form/AcquiaSearchSolrForm.php index 48d6516ea..c4a0b1158 100644 --- a/modules/acquia_cms_tour/src/Form/AcquiaSearchSolrForm.php +++ b/modules/acquia_cms_tour/src/Form/AcquiaSearchSolrForm.php @@ -182,7 +182,12 @@ public function ignoreConfig(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function getProgressState() { - return($this->state->get('acquia_search_solr_progress')); + if ($this->module_handler->moduleExists('acquia_search_solr')) { + return [ + 'total' => 1, + 'count' => $this->state->get('acquia_search_solr_progress'), + ]; + } } } diff --git a/modules/acquia_cms_tour/src/Form/AcquiaTelemetryForm.php b/modules/acquia_cms_tour/src/Form/AcquiaTelemetryForm.php index 05591c04b..564d950b8 100644 --- a/modules/acquia_cms_tour/src/Form/AcquiaTelemetryForm.php +++ b/modules/acquia_cms_tour/src/Form/AcquiaTelemetryForm.php @@ -193,7 +193,12 @@ public function ignoreConfig(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function getProgressState() { - return($this->state->get('acquia_telemetry_progress')); + if ($this->module_handler->moduleExists('acquia_telemetry')) { + return [ + 'total' => 1, + 'count' => $this->state->get('acquia_telemetry_progress'), + ]; + } } } diff --git a/modules/acquia_cms_tour/src/Form/GoogleAnalyticsForm.php b/modules/acquia_cms_tour/src/Form/GoogleAnalyticsForm.php index d8d918320..23bcbfc00 100644 --- a/modules/acquia_cms_tour/src/Form/GoogleAnalyticsForm.php +++ b/modules/acquia_cms_tour/src/Form/GoogleAnalyticsForm.php @@ -166,7 +166,12 @@ public function ignoreConfig(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function getProgressState() { - return($this->state->get('google_analytics_progress')); + if ($this->module_handler->moduleExists('google_analytics')) { + return [ + 'total' => 1, + 'count' => $this->state->get('google_analytics_progress'), + ]; + } } } diff --git a/modules/acquia_cms_tour/src/Form/GoogleTagManagerForm.php b/modules/acquia_cms_tour/src/Form/GoogleTagManagerForm.php index 736f8d15e..2961b634f 100644 --- a/modules/acquia_cms_tour/src/Form/GoogleTagManagerForm.php +++ b/modules/acquia_cms_tour/src/Form/GoogleTagManagerForm.php @@ -165,7 +165,12 @@ public function ignoreConfig(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function getProgressState() { - return($this->state->get('acquia_gtm_progress')); + if ($this->module_handler->moduleExists('google_tag')) { + return [ + 'total' => 1, + 'count' => $this->state->get('acquia_gtm_progress'), + ]; + } } } diff --git a/modules/acquia_cms_tour/src/Form/RecaptchaForm.php b/modules/acquia_cms_tour/src/Form/RecaptchaForm.php index ee83fe002..4b2c79741 100644 --- a/modules/acquia_cms_tour/src/Form/RecaptchaForm.php +++ b/modules/acquia_cms_tour/src/Form/RecaptchaForm.php @@ -173,7 +173,12 @@ public function ignoreConfig(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function getProgressState() { - return($this->state->get('recaptcha_progress')); + if ($this->module_handler->moduleExists('recaptcha')) { + return [ + 'total' => 1, + 'count' => $this->state->get('recaptcha_progress'), + ]; + } } } diff --git a/modules/acquia_cms_tour/src/Form/SiteStudioCoreForm.php b/modules/acquia_cms_tour/src/Form/SiteStudioCoreForm.php index 7f223f0ae..e36618f02 100644 --- a/modules/acquia_cms_tour/src/Form/SiteStudioCoreForm.php +++ b/modules/acquia_cms_tour/src/Form/SiteStudioCoreForm.php @@ -172,7 +172,12 @@ public function ignoreConfig(array &$form, FormStateInterface $form_state) { * {@inheritdoc} */ public function getProgressState() { - return($this->state->get('site_studio_progress')); + if ($this->module_handler->moduleExists('cohesion')) { + return [ + 'total' => 1, + 'count' => $this->state->get('site_studio_progress'), + ]; + } } }