From 2f70c283145e947ce4d4aeb0aefbd68cc32930a3 Mon Sep 17 00:00:00 2001 From: Bernd Oliver Suenderhauf <bos@suenderhauf.de> Date: Mon, 17 Jun 2019 18:13:59 +0200 Subject: [PATCH] Issue #3062140 by Pancho: Use item_list render arrays with #prefix/#suffix in status messages --- src/Form/FillPdfFormForm.php | 12 ++++++++---- src/Form/FillPdfSettingsForm.php | 18 +++++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/Form/FillPdfFormForm.php b/src/Form/FillPdfFormForm.php index 400be71..0c8f9c6 100644 --- a/src/Form/FillPdfFormForm.php +++ b/src/Form/FillPdfFormForm.php @@ -513,10 +513,14 @@ class FillPdfFormForm extends ContentEntityForm { $this->messenger()->addStatus($this->t('Your previous field mappings have been transferred to the new PDF template you uploaded.')); } if (count($non_matching_fields)) { - $this->messenger()->addWarning($this->t("These keys couldn't be found in the new PDF:")); - foreach (array_keys($non_matching_fields) as $pdf_key) { - $this->messenger()->addWarning($pdf_key); - } + $message = [ + '#prefix' => $this->t("These keys couldn't be found in the new PDF:"), + [ + '#theme' => 'item_list', + '#items' => array_keys($non_matching_fields), + ], + ]; + $this->messenger()->addWarning(\Drupal::service('renderer')->render($message)); } $this->messenger()->addStatus($this->t('You might also want to update the <em>Filename pattern</em> field; this has not been changed.')); diff --git a/src/Form/FillPdfSettingsForm.php b/src/Form/FillPdfSettingsForm.php index dbdb584..7e1f4c8 100644 --- a/src/Form/FillPdfSettingsForm.php +++ b/src/Form/FillPdfSettingsForm.php @@ -155,10 +155,10 @@ class FillPdfSettingsForm extends ConfigFormBase { $template_scheme = $config->get('template_scheme'); // Set an error if the previously configured scheme doesn't exist anymore. if ($template_scheme && !array_key_exists($template_scheme, $template_scheme_options)) { - $error_message = $this->t('Your previously used file storage %previous_scheme is no longer available on this Drupal site, see the %system_settings. Please reset your default to an existing file storage.', [ + $this->messenger()->addError($this->t('Your previously used file storage %previous_scheme is no longer available on this Drupal site, see the %system_settings. Please reset your default to an existing file storage.', [ '%previous_scheme' => $template_scheme . '://', '%system_settings' => Link::createFromRoute($this->t('File system settings'), 'system.file_system_settings')->toString(), - ]); + ])); // @todo: It would be helpful if we could use EntityQuery instead, see // https://www.drupal.org/project/fillpdf/issues/3043508. @@ -174,16 +174,16 @@ class FillPdfSettingsForm extends ConfigFormBase { $link = Link::fromTextAndUrl($admin_title ?: "FillPDF form {$fillpdf_form->id()}", $fillpdf_form->toUrl()); $items[$form_id] = new FormattableMarkup("@fillpdf_form: {$file_uri}", ['@fillpdf_form' => $link->toString()]); } - $list = [ - '#theme' => 'item_list', - '#items' => $items, + $error_message = [ + '#prefix' => $this->t('Nevertheless, the following FillPDF forms will not work until their respective PDF templates have been moved to an existing file scheme:'), + [ + '#theme' => 'item_list', + '#items' => $items, + ], ]; - $error_message .= '<br />' . $this->t('Nevertheless, the following FillPDF forms will not work until their respective PDF templates have been moved to an existing file scheme:<br />@list', [ - '@list' => \Drupal::service('renderer')->renderPlain($list), - ]); + $this->messenger()->addError(\Drupal::service('renderer')->renderPlain($error_message)); } - $this->messenger()->addError(new FormattableMarkup($error_message, [])); $this->logger('fillpdf')->critical('File storage %previous_scheme is no longer available.' . $count ? " $count FillPDF forms are defunct." : '', [ '%previous_scheme' => $template_scheme . '://', ]); -- GitLab