diff --git a/modules/monitoring/application/forms/Config/TransportConfigForm.php b/modules/monitoring/application/forms/Config/TransportConfigForm.php index 059ea401d..ba1ec9042 100644 --- a/modules/monitoring/application/forms/Config/TransportConfigForm.php +++ b/modules/monitoring/application/forms/Config/TransportConfigForm.php @@ -270,46 +270,49 @@ class TransportConfigForm extends ConfigForm parent::addSubmitButton(); if ($this->getSubForm('transport_form') instanceof ApiTransportForm) { - $this->addElement( - 'submit', - 'transport_validation', - array( - 'ignore' => true, - 'label' => $this->translate('Validate Configuration'), - 'data-progress-label' => $this->translate('Validation In Progress'), - 'decorators' => array('ViewHelper') - ) - ); - - $this->setAttrib('data-progress-element', 'transport-progress'); - $this->addElement( - 'note', - 'transport-progress', - array( - 'decorators' => array( - 'ViewHelper', - array('Spinner', array('id' => 'transport-progress')) - ) - ) - ); - $btnSubmit = $this->getElement('btn_submit'); - $elements = array('transport_validation', 'transport-progress'); + if ($btnSubmit !== null) { // In the setup wizard $this is being used as a subform which doesn't have a submit button. + $this->addElement( + 'submit', + 'transport_validation', + array( + 'ignore' => true, + 'label' => $this->translate('Validate Configuration'), + 'data-progress-label' => $this->translate('Validation In Progress'), + 'decorators' => array('ViewHelper') + ) + ); + + $this->setAttrib('data-progress-element', 'transport-progress'); + $this->addElement( + 'note', + 'transport-progress', + array( + 'decorators' => array( + 'ViewHelper', + array('Spinner', array('id' => 'transport-progress')) + ) + ) + ); + + $elements = array('transport_validation', 'transport-progress'); + $btnSubmit->setDecorators(array('ViewHelper')); array_unshift($elements, 'btn_submit'); - } - $this->addDisplayGroup( - $elements, - 'submit_validation', - array( - 'decorators' => array( - 'FormElements', - array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls')) + + $this->addDisplayGroup( + $elements, + 'submit_validation', + array( + 'decorators' => array( + 'FormElements', + array('HtmlTag', array('tag' => 'div', 'class' => 'control-group form-controls')) + ) ) - ) - ); + ); + } } return $this; @@ -351,9 +354,12 @@ class TransportConfigForm extends ConfigForm return false; } - if (! ($this->getElement('transport_validation') === null || ( - $this->isSubmitted() && isset($formData['force_creation']) && $formData['force_creation']) - )) { + if ($this->getSubForm('transport_form') instanceof ApiTransportForm) { + if (isset($formData['force_creation']) && $formData['force_creation']) { + // ignore any validation result + return true; + } + try { CommandTransport::createTransport(new ConfigObject($this->getValues()))->probe(); } catch (CommandTransportException $e) { @@ -366,10 +372,10 @@ class TransportConfigForm extends ConfigForm 'checkbox', 'force_creation', array( - 'order' => 0, - 'ignore' => true, - 'label' => $this->translate('Force Changes'), - 'description' => $this->translate( + 'order' => 0, + 'ignore' => true, + 'label' => $this->translate('Force Changes'), + 'description' => $this->translate( 'Check this box to enforce changes without connectivity validation' ) ) diff --git a/modules/monitoring/application/forms/Setup/TransportPage.php b/modules/monitoring/application/forms/Setup/TransportPage.php index 5f3f3b640..9d0760abc 100644 --- a/modules/monitoring/application/forms/Setup/TransportPage.php +++ b/modules/monitoring/application/forms/Setup/TransportPage.php @@ -15,6 +15,7 @@ class TransportPage extends Form $this->addDescription($this->translate( 'Please define below how you want to send commands to your monitoring instance.' )); + $this->setValidatePartial(true); } public function createElements(array $formData) @@ -30,4 +31,25 @@ class TransportPage extends Form { return $this->getSubForm('transport_form')->getValues($suppressArrayNotation); } + + /** + * Run the configured backend's inspection checks and show the result, if necessary + * + * This will only run any validation if the user pushed the 'transport_validation' button. + * + * @param array $formData + * + * @return bool + */ + public function isValidPartial(array $formData) + { + if (isset($formData['transport_validation']) && parent::isValid($formData)) { + $this->info($this->translate('The configuration has been successfully validated.')); + } elseif (! isset($formData['transport_validation'])) { + // This is usually done by isValid(Partial), but as we're not calling any of these... + $this->populate($formData); + } + + return true; + } } diff --git a/modules/monitoring/library/Monitoring/MonitoringWizard.php b/modules/monitoring/library/Monitoring/MonitoringWizard.php index 2a814ba8d..59df9f819 100644 --- a/modules/monitoring/library/Monitoring/MonitoringWizard.php +++ b/modules/monitoring/library/Monitoring/MonitoringWizard.php @@ -92,6 +92,9 @@ class MonitoringWizard extends Wizard implements SetupWizard * Add buttons to the given page based on its position in the page-chain * * @param Form $page The page to add the buttons to + * + * @todo This is never called, because its a sub-wizard only + * @see WebWizard::addButtons which does some of the needed work */ protected function addButtons(Form $page) { diff --git a/modules/setup/library/Setup/WebWizard.php b/modules/setup/library/Setup/WebWizard.php index f8f10ef2f..a74a1c9ed 100644 --- a/modules/setup/library/Setup/WebWizard.php +++ b/modules/setup/library/Setup/WebWizard.php @@ -366,7 +366,7 @@ class WebWizard extends Wizard implements SetupWizard 'setup_auth_db_resource', 'setup_config_db_resource', 'setup_ldap_resource', - 'setup_monitoring_ido' + 'setup_monitoring_ido', // TODO(mf): This should be handled by MonitoringWizard ))) { $page->addElement( 'submit', @@ -380,6 +380,21 @@ class WebWizard extends Wizard implements SetupWizard ); $page->getDisplayGroup('buttons')->addElement($page->getElement('backend_validation')); } + + // TODO(mf): This should be handled by MonitoringWizard + if ($page->getName() === 'setup_command_transport') { + $page->addElement( + 'submit', + 'transport_validation', + array( + 'ignore' => true, + 'label' => t('Validate Configuration'), + 'data-progress-label' => t('Validation In Progress'), + 'decorators' => array('ViewHelper') + ) + ); + $page->getDisplayGroup('buttons')->addElement($page->getElement('transport_validation')); + } } /**