diff --git a/src/Form/FillPdfFormForm.php b/src/Form/FillPdfFormForm.php index 493191f36e1e8a31feb840f30babb1b1d17a36e2..1844464174c89484711b45ac6d85b7b789d9d04f 100644 --- a/src/Form/FillPdfFormForm.php +++ b/src/Form/FillPdfFormForm.php @@ -236,8 +236,8 @@ class FillPdfFormForm extends ContentEntityForm { $upload_location = FillPdf::buildFileUri($this->config('fillpdf.settings')->get('scheme'), 'fillpdf'); if (!file_prepare_directory($upload_location, FILE_CREATE_DIRECTORY + FILE_MODIFY_PERMISSIONS)) { - $this->messenger()->addError($this->t('The %directory subdirectory does not exist or is not writable. Please check permissions.', [ - '%directory' => 'fillpdf', + $this->messenger()->addError($this->t('The directory %directory does not exist or is not writable. Please check permissions.', [ + '%directory' => $this->fileSystem->realpath($upload_location), ])); } else { diff --git a/src/Form/FillPdfOverviewForm.php b/src/Form/FillPdfOverviewForm.php index 560d2512e02f614cff3a634db8e3dc87d20ccb0f..e59969d8a6c64ce556393c5394a78cca2e0f7576 100644 --- a/src/Form/FillPdfOverviewForm.php +++ b/src/Form/FillPdfOverviewForm.php @@ -143,8 +143,8 @@ class FillPdfOverviewForm extends FillPdfAdminFormBase { $upload_location = FillPdf::buildFileUri($this->config('fillpdf.settings')->get('scheme'), 'fillpdf'); if (!file_prepare_directory($upload_location, FILE_CREATE_DIRECTORY + FILE_MODIFY_PERMISSIONS)) { - $this->messenger()->addError($this->t('The %directory subdirectory does not exist or is not writable. Please check permissions.', [ - '%directory' => 'fillpdf', + $this->messenger()->addError($this->t('The directory %directory does not exist or is not writable. Please check permissions.', [ + '%directory' => $this->fileSystem->realpath($upload_location), ])); } else { diff --git a/src/Form/FillPdfSettingsForm.php b/src/Form/FillPdfSettingsForm.php index 79acbe332bfe80858fc611dc4871651801d93949..c12f9094fb0cb72a9f00c239a1b48bfa59162879 100644 --- a/src/Form/FillPdfSettingsForm.php +++ b/src/Form/FillPdfSettingsForm.php @@ -4,6 +4,7 @@ namespace Drupal\fillpdf\Form; use Drupal\Component\Render\FormattableMarkup; use Drupal\Core\Config\ConfigFactoryInterface; +use Drupal\Core\File\FileSystemInterface; use Drupal\Core\Form\ConfigFormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; @@ -19,6 +20,13 @@ use Drupal\fillpdf\Entity\FillPdfForm; */ class FillPdfSettingsForm extends ConfigFormBase { + /** + * The file system service. + * + * @var \Drupal\Core\File\FileSystemInterface + */ + protected $fileSystem; + /** * Definitions of all backend plugins. * @@ -47,14 +55,22 @@ class FillPdfSettingsForm extends ConfigFormBase { * * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory * The factory for configuration objects. + * @param \Drupal\Core\File\FileSystemInterface $file_system + * Helpers to operate on files and stream wrappers. * @param \Drupal\fillpdf\Service\FillPdfAdminFormHelper $admin_form_helper * The FillPDF admin form helper service. * @param \GuzzleHttp\Client $http_client * The Guzzle HTTP client service. */ - public function __construct(ConfigFactoryInterface $config_factory, FillPdfAdminFormHelper $admin_form_helper, Client $http_client) { + public function __construct( + ConfigFactoryInterface $config_factory, + FileSystemInterface $file_system, + FillPdfAdminFormHelper $admin_form_helper, + Client $http_client + ) { parent::__construct($config_factory); + $this->fileSystem = $file_system; $this->adminFormHelper = $admin_form_helper; $this->httpClient = $http_client; @@ -68,6 +84,7 @@ class FillPdfSettingsForm extends ConfigFormBase { public static function create(ContainerInterface $container) { return new static( $container->get('config.factory'), + $container->get('file_system'), $container->get('fillpdf.admin_form_helper'), $container->get('http_client') ); @@ -275,9 +292,12 @@ class FillPdfSettingsForm extends ConfigFormBase { break; } - $directory = FillPdf::buildFileUri($form_state->getValue('scheme'), 'fillpdf'); - if (!file_prepare_directory($directory, FILE_CREATE_DIRECTORY + FILE_MODIFY_PERMISSIONS)) { - $form_state->setErrorByName('scheme', $this->t('Could not automatically create the <em>fillpdf</em> subdirectory. Please create this manually before uploading your PDF form.')); + $uri = FillPdf::buildFileUri($form_state->getValue('scheme'), 'fillpdf'); + if (!file_prepare_directory($uri, FILE_CREATE_DIRECTORY + FILE_MODIFY_PERMISSIONS)) { + $error_message = $this->t('Could not automatically create the subdirectory %directory. Please check permissions before trying again.', [ + '%directory' => $this->fileSystem->realpath($uri), + ]); + $form_state->setErrorByName('scheme', $error_message); } } diff --git a/tests/src/Functional/FillPdfSettingsFormTest.php b/tests/src/Functional/FillPdfSettingsFormTest.php index 30c9500974a5ecbdef7e4fabbe7d3035e147712e..ac24735f0f39ed5f62971b8944391afd9725dd55 100644 --- a/tests/src/Functional/FillPdfSettingsFormTest.php +++ b/tests/src/Functional/FillPdfSettingsFormTest.php @@ -153,7 +153,7 @@ class FillPdfSettingsFormTest extends BrowserTestBase { file_unmanaged_copy('public://.htaccess', $directory); $this->drupalPostForm(NULL, [], 'Save configuration'); $this->assertSession()->pageTextNotContains('The configuration options have been saved.'); - $this->assertSession()->pageTextContains('Could not automatically create the fillpdf subdirectory.'); + $this->assertSession()->pageTextContains('Could not automatically create the subdirectory'); } /**