Loading src/Form/FillPdfFormForm.php +2 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading src/Form/FillPdfOverviewForm.php +2 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading src/Form/FillPdfSettingsForm.php +24 −4 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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. * Loading Loading @@ -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; Loading @@ -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') ); Loading Loading @@ -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); } } Loading tests/src/Functional/FillPdfSettingsFormTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -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'); } /** Loading Loading
src/Form/FillPdfFormForm.php +2 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading
src/Form/FillPdfOverviewForm.php +2 −2 Original line number Diff line number Diff line Loading @@ -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 { Loading
src/Form/FillPdfSettingsForm.php +24 −4 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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. * Loading Loading @@ -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; Loading @@ -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') ); Loading Loading @@ -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); } } Loading
tests/src/Functional/FillPdfSettingsFormTest.php +1 −1 Original line number Diff line number Diff line Loading @@ -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'); } /** Loading