Skip to content
Snippets Groups Projects
Commit 2bbc0f2d authored by Bernd Oliver Suenderhauf's avatar Bernd Oliver Suenderhauf
Browse files

Issue #3048627 by Pancho: SettingsForm always validates stored LocalServer endpoint

parent 4192e75a
No related branches found
No related tags found
No related merge requests found
......@@ -14,6 +14,7 @@ use GuzzleHttp\Client;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Link;
use Drupal\fillpdf\Entity\FillPdfForm;
use Drupal\Core\Config\Config;
/**
* Configure FillPDF settings form.
......@@ -281,26 +282,30 @@ class FillPdfSettingsForm extends ConfigFormBase {
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$config = $this->config('fillpdf.settings');
$values = $form_state->getValues();
switch ($form_state->getValue('backend')) {
switch ($values['backend']) {
case 'fillpdf_service':
// @todo: Add validation for FillPDF Service.
// See https://www.drupal.org/project/fillpdf/issues/3040899.
break;
case 'local_service':
// Set the form_state value to the Config object without saving.
$config = $this->config('fillpdf.settings')->set('local_service_endpoint', $values['local_service_endpoint']);
// Check for FillPDF LocalServer.
$status = FillPdf::checkLocalServiceEndpoint($this->httpClient, $config);
if ($status === FALSE) {
$error_message = $this->t('FillPDF LocalService is not properly installed. Was unable to contact %local_server', ['%local_server' => $config->get('local_service_endpoint')]);
$error_message = $this->t('FillPDF LocalService is not properly installed. Was unable to contact %endpoint', [
'%endpoint' => $values['local_service_endpoint'],
]);
$form_state->setErrorByName('local_service_endpoint', $error_message);
}
break;
case 'pdftk':
// Check for pdftk.
$status = FillPdf::checkPdftkPath($form_state->getValue('pdftk_path'));
$status = FillPdf::checkPdftkPath($values['pdftk_path']);
if ($status === FALSE) {
$error_message = $this->t('The path you have entered for <em>pdftk</em> is invalid. Please enter a valid path.');
$form_state->setErrorByName('pdftk_path', $error_message);
......@@ -317,8 +322,8 @@ class FillPdfSettingsForm extends ConfigFormBase {
break;
}
$template_scheme = $form_state->getValue('template_scheme');
$schemes_to_prepare = array_filter($form_state->getValue('allowed_schemes')) + [$template_scheme => $template_scheme];
$template_scheme = $values['template_scheme'];
$schemes_to_prepare = array_filter($values['allowed_schemes']) + [$template_scheme => $template_scheme];
foreach ($schemes_to_prepare as $scheme) {
$uri = FillPdf::buildFileUri($scheme, 'fillpdf');
if (!file_prepare_directory($uri, FILE_CREATE_DIRECTORY + FILE_MODIFY_PERMISSIONS)) {
......
......@@ -190,15 +190,12 @@ class PdfPopulationTest extends FillPdfTestBase {
*/
public function testLocalServicePdfPopulation() {
// For local container testing, we require the Docker container to be
// running on port 18085. If http://127.0.0.1:18085/ping does not return a
// running on port 8085. If http://127.0.0.1:8085/ping does not return a
// 200, we assume that we're not in an environment where we can run this
// test.
$this->configureLocalServiceBackend();
$fillpdf_config = $this->container->get('config.factory')
->get('fillpdf.settings');
if (!FillPdf::checkLocalServiceEndpoint(
$this->container->get('http_client'),
$fillpdf_config)) {
$config = $this->container->get('config.factory')->get('fillpdf.settings');
if (!FillPdf::checkLocalServiceEndpoint($this->container->get('http_client'), $config)) {
throw new \PHPUnit_Framework_SkippedTestError('FillPDF LocalServer unavailable, so skipping test.');
}
$this->backendTest();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment