diff --git a/classes/components/forms/context/OrcidSettingsForm.php b/classes/components/forms/context/OrcidSettingsForm.php index 50146ba531f..efe83f75e35 100644 --- a/classes/components/forms/context/OrcidSettingsForm.php +++ b/classes/components/forms/context/OrcidSettingsForm.php @@ -28,8 +28,8 @@ class OrcidSettingsForm extends FormComponent { - public const ORCID_DEFAULT_GROUP = 'orcidDefaultGroup'; - public const ORCID_SETTINGS_GROUP = 'orcidSettingsGroup'; + public const DEFAULT_GROUP = 'orcidDefaultGroup'; + public const SETTINGS_GROUP = 'orcidSettingsGroup'; public $id = 'orcidSettings'; public $method = 'PUT'; public Context $context; @@ -40,42 +40,60 @@ public function __construct(string $action, array $locales, \PKP\context\Context $this->locales = $locales; $this->context = $context; - $this->addGroup(['id' => self::ORCID_DEFAULT_GROUP]) + $this->addGroup(['id' => self::DEFAULT_GROUP]) ->addGroup([ - 'id' => self::ORCID_SETTINGS_GROUP, + 'id' => self::SETTINGS_GROUP, 'showWhen' => OrcidManager::ENABLED - ]) - // TODO: Handle disabling form requirement when ORCID functionality is disabled. - ->addField(new FieldOptions(OrcidManager::ENABLED, [ - 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath'), - 'groupId' => self::ORCID_DEFAULT_GROUP, - 'options' => [ - // TODO: Remove temporary hard-coded string - ['value' => true, 'label' => 'Enable ORCID Profile functionality'] - ], - 'value' => (bool) $context->getData(OrcidManager::ENABLED) ?? false - ])) - ->addField(new FieldHTML('settingsDescription', [ - 'groupId' => self::ORCID_DEFAULT_GROUP, - 'description' => __('orcidProfile.manager.settings.description'), - ])); + ]); + + // TODO: Handle disabling form requirement when ORCID functionality is disabled. + + $isEnabledValue = (bool) $context->getData(OrcidManager::ENABLED) ?? false; + if (OrcidManager::isGloballyConfigured()) { + $isEnabledValue = true; + } + $this->addField(new FieldOptions(OrcidManager::ENABLED, [ + 'label' => __('orcidProfile.fieldset'), + 'groupId' => self::DEFAULT_GROUP, + 'options' => [ + // TODO: Remove temporary hard-coded string + [ + 'value' => true, + 'label' => 'Enable ORCID Profile functionality', + 'disabled' => OrcidManager::isGloballyConfigured(), + ] + ], + 'value' => $isEnabledValue, + ])); + + $settingsDescriptionText = __('orcidProfile.manager.settings.description'); + if (OrcidManager::isGloballyConfigured()) { + // TODO: Add text about globally configured restrictions + $settingsDescriptionText .= '

' . 'TODO: Add text about globally configured restrictions.'; + } + + $this->addField(new FieldHTML('settingsDescription', [ + 'groupId' => self::DEFAULT_GROUP, + 'description' => $settingsDescriptionText, + ])); + // ORCID API settings can be configured globally via the site settings form or from this settings form if (OrcidManager::isGloballyConfigured()) { $site = Application::get()->getRequest()->getSite(); $this->addField(new FieldHTML(OrcidManager::API_TYPE, [ - 'groupId' => self::ORCID_SETTINGS_GROUP, + 'groupId' => self::SETTINGS_GROUP, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath'), 'description' => $this->getLocalizedApiTypeString($site->getData(OrcidManager::API_TYPE)) ])) ->addField(new FieldHTML(OrcidManager::CLIENT_ID, [ - 'groupId' => self::ORCID_SETTINGS_GROUP, + 'groupId' => self::SETTINGS_GROUP, 'label' => __('orcidProfile.manager.settings.orcidClientId'), 'description' => $site->getData(OrcidManager::CLIENT_ID), ])) ->addField(new FieldHTML(OrcidManager::CLIENT_SECRET, [ - 'groupId' => self::ORCID_SETTINGS_GROUP, + 'groupId' => self::SETTINGS_GROUP, 'label' => __('orcidProfile.manager.settings.orcidClientSecret'), 'description' => $site->getData(OrcidManager::CLIENT_SECRET), ])); @@ -83,7 +101,7 @@ public function __construct(string $action, array $locales, \PKP\context\Context } else { $this->addField(new FieldSelect(OrcidManager::API_TYPE, [ 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath'), - 'groupId' => self::ORCID_SETTINGS_GROUP, + 'groupId' => self::SETTINGS_GROUP, 'isRequired' => true, 'options' => [ ['value' => OrcidManager::API_PUBLIC_PRODUCTION, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.public')], @@ -95,13 +113,13 @@ public function __construct(string $action, array $locales, \PKP\context\Context ])) ->addField(new FieldText(OrcidManager::CLIENT_ID, [ 'label' => __('orcidProfile.manager.settings.orcidClientId'), - 'groupId' => self::ORCID_SETTINGS_GROUP, + 'groupId' => self::SETTINGS_GROUP, 'isRequired' => true, 'value' => $context->getData(OrcidManager::CLIENT_ID) ?? '', ])) ->addField(new FieldText(OrcidManager::CLIENT_SECRET, [ 'label' => __('orcidProfile.manager.settings.orcidClientSecret'), - 'groupId' => self::ORCID_SETTINGS_GROUP, + 'groupId' => self::SETTINGS_GROUP, 'isRequired' => true, 'value' => $context->getData(OrcidManager::CLIENT_SECRET) ?? '', ])); @@ -119,19 +137,19 @@ public function __construct(string $action, array $locales, \PKP\context\Context return strcmp($a['label'], $b['label']); }); $this->addField(new FieldSelect(OrcidManager::COUNTRY, [ - 'groupId' => self::ORCID_SETTINGS_GROUP, + 'groupId' => self::SETTINGS_GROUP, 'label' => __('orcidProfile.manager.settings.country'), 'description' => __('orcidProfile.manager.settings.review.help'), 'options' => $countries, 'value' => $context->getData(OrcidManager::COUNTRY) ?? '', ])) ->addField(new FieldText(OrcidManager::CITY, [ - 'groupId' => self::ORCID_SETTINGS_GROUP, + 'groupId' => self::SETTINGS_GROUP, 'label' => 'orcidProfile.manager.settings.city', 'value' => $context->getData(OrcidManager::CITY) ?? '', ])) ->addField(new FieldOptions(OrcidManager::SEND_MAIL_TO_AUTHORS_ON_PUBLICATION, [ - 'groupId' => self::ORCID_SETTINGS_GROUP, + 'groupId' => self::SETTINGS_GROUP, 'label' => __('orcidProfile.manager.settings.mailSectionTitle'), 'options' => [ ['value' => true, 'label' => __('orcidProfile.manager.settings.sendMailToAuthorsOnPublication')] @@ -139,7 +157,7 @@ public function __construct(string $action, array $locales, \PKP\context\Context 'value' => (bool) $context->getData(OrcidManager::SEND_MAIL_TO_AUTHORS_ON_PUBLICATION) ?? false, ])) ->addField(new FieldSelect(OrcidManager::LOG_LEVEL, [ - 'groupId' => self::ORCID_SETTINGS_GROUP, + 'groupId' => self::SETTINGS_GROUP, 'label' => __('orcidProfile.manager.settings.logSectionTitle'), 'description' => __('orcidProfile.manager.settings.logLevel.help'), 'options' => [ diff --git a/classes/components/forms/site/OrcidSiteSettingsForm.php b/classes/components/forms/site/OrcidSiteSettingsForm.php index 66605c38da7..3191929946b 100644 --- a/classes/components/forms/site/OrcidSiteSettingsForm.php +++ b/classes/components/forms/site/OrcidSiteSettingsForm.php @@ -3,6 +3,8 @@ namespace APP\components\forms\site; use APP\orcid\OrcidManager; +use PKP\components\forms\FieldHTML; +use PKP\components\forms\FieldOptions; use PKP\components\forms\FieldSelect; use PKP\components\forms\FieldText; use PKP\components\forms\FormComponent; @@ -10,6 +12,8 @@ class OrcidSiteSettingsForm extends FormComponent { + public const DEFAULT_GROUP = 'orcidDefaultGroup'; + public const SETTINGS_GROUP = 'orcidSettingsGroup'; public $id = 'orcidSiteSettings'; public $method = 'PUT'; @@ -17,23 +21,49 @@ public function __construct(string $action, array $locales, Site $site) { parent::__construct($this->id, $this->method, $action, $locales); + $this->addGroup(['id' => self::DEFAULT_GROUP]) + ->addGroup([ + 'id' => self::SETTINGS_GROUP, + 'showWhen' => OrcidManager::ENABLED, + ]); + // TODO: How to handle all should be blank or completed (all or nothing) - $this->addField(new FieldSelect(OrcidManager::API_TYPE, [ - 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath'), + $this->addField(new FieldOptions(OrcidManager::ENABLED, [ + 'label' => __('orcidProfile.fieldset'), + 'groupId' => self::DEFAULT_GROUP, 'options' => [ - ['value' => OrcidManager::API_PUBLIC_PRODUCTION, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.public')], - ['value' => OrcidManager::API_PUBLIC_SANDBOX, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.publicSandbox')], - ['value' => OrcidManager::API_MEMBER_PRODUCTION, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.member')], - ['value' => OrcidManager::API_MEMBER_SANDBOX, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.memberSandbox')], + // TODO: Remove temporary hard-coded string + ['value' => true, 'label' => 'Enable ORCID Profile functionality'] ], - 'value' => $site->getData(OrcidManager::API_TYPE) ?? OrcidManager::API_PUBLIC_PRODUCTION, + 'value' => (bool) $site->getData(OrcidManager::ENABLED) ?? false, ])) + ->addField(new FieldHTML('settingsDescription', [ + 'groupId' => self::DEFAULT_GROUP, + // TODO: Add site settings description text + 'description' => 'TODO: Add site settings description text.', + ])) + ->addField(new FieldSelect(OrcidManager::API_TYPE, [ + 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath'), + 'groupId' => self::SETTINGS_GROUP, + 'isRequired' => true, + 'options' => [ + ['value' => OrcidManager::API_PUBLIC_PRODUCTION, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.public')], + ['value' => OrcidManager::API_PUBLIC_SANDBOX, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.publicSandbox')], + ['value' => OrcidManager::API_MEMBER_PRODUCTION, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.member')], + ['value' => OrcidManager::API_MEMBER_SANDBOX, 'label' => __('orcidProfile.manager.settings.orcidProfileAPIPath.memberSandbox')], + ], + 'value' => $site->getData(OrcidManager::API_TYPE) ?? OrcidManager::API_PUBLIC_PRODUCTION, + ])) ->addField(new FieldText(OrcidManager::CLIENT_ID, [ 'label' => __('orcidProfile.manager.settings.orcidClientId'), + 'groupId' => self::SETTINGS_GROUP, + 'isRequired' => true, 'value' => $site->getData(OrcidManager::CLIENT_ID) ?? '', ])) ->addField(new FieldText(OrcidManager::CLIENT_SECRET, [ 'label' => __('orcidProfile.manager.settings.orcidClientSecret'), + 'groupId' => self::SETTINGS_GROUP, + 'isRequired' => true, 'value' => $site->getData(OrcidManager::CLIENT_SECRET) ?? '', ])); } diff --git a/classes/orcid/OrcidManager.php b/classes/orcid/OrcidManager.php index 7ba597eebe6..6d35d4f9c76 100644 --- a/classes/orcid/OrcidManager.php +++ b/classes/orcid/OrcidManager.php @@ -62,11 +62,7 @@ class OrcidManager public static function isGloballyConfigured(): bool { $site = Application::get()->getRequest()->getSite(); - $apiType = $site->getData(self::API_TYPE); - $clientId = $site->getData(self::CLIENT_ID); - $clientSecret = $site->getData(self::CLIENT_SECRET); - return isset($apiType) && trim($apiType) && isset($clientId) && trim($clientId) && - isset($clientSecret) && trim($clientSecret); + return $site->getData(self::ENABLED); } /** @@ -84,6 +80,9 @@ public static function getIcon(): string */ public static function isEnabled(?Context $context = null): bool { + if (self::isGloballyConfigured()) { + return true; + } if ($context === null) { $context = Application::get()->getRequest()->getContext(); }