Skip to content

Commit

Permalink
Merge branch 'develop' into WS-447-confirm-leave
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkin authored Aug 31, 2024
2 parents afb488e + cdd8e13 commit 7a91117
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 2 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,9 @@
"FOIA-32: Dynamically provide action plugins for every moderation state change": "https://www.drupal.org/files/issues/2019-11-20/2797583_provide_moderation_states_as_actions_128.patch",
"FOIA-32: Exclude Agency/Component from validation for bulk publishing": "./patches/FOIA-32-validator.patch",
"2869592 - Disabled update module shouldn't produce a status report warning": "https://www.drupal.org/files/issues/2024-07-16/2869592-disabled-update-module-71.patch",
"2230909 - Simple decimals fail to pass validation": "https://www.drupal.org/files/issues/2024-06-04/2230909-321.patch"
"2230909 - Simple decimals fail to pass validation": "https://www.drupal.org/files/issues/2024-06-04/2230909-321.patch",
"Hacks related to file_entity to get XML upload to work": "./patches/managed-file-hacks-for-xml-upload.patch",
"More hacks related to action module to get XML upload to work": "./patches/migrate-action-hack-for-xml-upload.patch"
},
"drupal/password_policy": {
"Config install issues": "https://www.drupal.org/files/issues/2022-10-04/password_policy_field_last_password_reset_unknown_error_2771129-134.patch"
Expand Down
1 change: 0 additions & 1 deletion config/default/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ module:
serialization: 0
shortcut: 0
simplesamlphp_auth: 0
swiftmailer: 0
symfony_mailer: 0
syslog: 0
system: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'file_validate_extensions' => ['xml'],
],
'#required' => TRUE,
'#file_type' => 'document',
];

$form['next_step'] = [
Expand Down
65 changes: 65 additions & 0 deletions patches/managed-file-hacks-for-xml-upload.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
diff --git a/core/modules/file/file.module b/core/modules/file/file.module
index 6fcfa8c789..e80041cd22 100644
--- a/core/modules/file/file.module
+++ b/core/modules/file/file.module
@@ -532,8 +532,9 @@ function _file_save_upload_from_form(array $element, FormStateInterface $form_st
$upload_location = $element['#upload_location'] ?? FALSE;
$upload_name = implode('_', $element['#parents']);
$upload_validators = $element['#upload_validators'] ?? [];
+ $file_type = $element['#file_type'] ?? FALSE;

- $result = file_save_upload($upload_name, $upload_validators, $upload_location, $delta, $fileExists);
+ $result = file_save_upload($upload_name, $upload_validators, $upload_location, $delta, $fileExists, $file_type);

// Get new errors that are generated while trying to save the upload. This
// will also clear them from the messenger service.
@@ -614,7 +615,7 @@ function _file_save_upload_from_form(array $element, FormStateInterface $form_st
*
* @see _file_save_upload_from_form()
*/
-function file_save_upload($form_field_name, $validators = [], $destination = FALSE, $delta = NULL, FileExists|int $fileExists = FileExists::Rename) {
+function file_save_upload($form_field_name, $validators = [], $destination = FALSE, $delta = NULL, FileExists|int $fileExists = FileExists::Rename, $file_type = FALSE) {
if (!$fileExists instanceof FileExists) {
// @phpstan-ignore-next-line
$fileExists = FileExists::fromLegacyInt($fileExists, __METHOD__);
@@ -657,7 +658,7 @@ function file_save_upload($form_field_name, $validators = [], $destination = FAL
foreach ($uploaded_files as $i => $uploaded_file) {
try {
$form_uploaded_file = new FormUploadedFile($uploaded_file);
- $result = $file_upload_handler->handleFileUpload($form_uploaded_file, $validators, $destination, $fileExists, FALSE);
+ $result = $file_upload_handler->handleFileUpload($form_uploaded_file, $validators, $destination, $fileExists, FALSE, $file_type);
if ($result->hasViolations()) {
$errors = [];
foreach ($result->getViolations() as $violation) {
diff --git a/core/modules/file/src/Upload/FileUploadHandler.php b/core/modules/file/src/Upload/FileUploadHandler.php
index 9f3661871f..cc011f399a 100644
--- a/core/modules/file/src/Upload/FileUploadHandler.php
+++ b/core/modules/file/src/Upload/FileUploadHandler.php
@@ -174,7 +174,7 @@ public function __construct(
* @throws \ValueError
* Thrown if $fileExists is a legacy int and not a valid value.
*/
- public function handleFileUpload(UploadedFileInterface $uploadedFile, array $validators = [], string $destination = 'temporary://', /*FileExists*/$fileExists = FileExists::Replace, bool $throw = TRUE): FileUploadResult {
+ public function handleFileUpload(UploadedFileInterface $uploadedFile, array $validators = [], string $destination = 'temporary://', /*FileExists*/$fileExists = FileExists::Replace, bool $throw = TRUE, $file_type = FALSE): FileUploadResult {
if (!$fileExists instanceof FileExists) {
// @phpstan-ignore-next-line
$fileExists = FileExists::fromLegacyInt($fileExists, __METHOD__);
@@ -267,11 +267,16 @@ public function handleFileUpload(UploadedFileInterface $uploadedFile, array $val
);
}

- $file = File::create([
+ $file_values = [
'uid' => $this->currentUser->id(),
'status' => 0,
'uri' => $uploadedFile->getRealPath(),
- ]);
+ ];
+ if ($file_type) {
+ $file_values['type'] = $file_type;
+ }
+
+ $file = File::create($file_values);

// This will be replaced later with a filename based on the destination.
$file->setFilename($filename);
27 changes: 27 additions & 0 deletions patches/migrate-action-hack-for-xml-upload.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
diff --git a/core/modules/action/action.module b/core/modules/action/action.module
index 0e4229debc..f3ac61db22 100644
--- a/core/modules/action/action.module
+++ b/core/modules/action/action.module
@@ -61,12 +61,16 @@ function action_migration_plugins_alter(array &$migrations) {
foreach ($migrations as $migration_id => $migration) {
// Add Actions plugins in actions module.
/** @var \Drupal\migrate\Plugin\migrate\source\SqlBase $source_plugin */
- $source_plugin = \Drupal::service('plugin.manager.migration')
- ->createStubMigration($migration)
- ->getSourcePlugin();
- if (is_a($source_plugin, Action::class) && isset($migration['process']['plugin'])) {
- $migrations[$migration_id]['process']['plugin'][0]['map']['comment_unpublish_by_keyword_action'] = 'comment_unpublish_by_keyword_action';
- $migrations[$migration_id]['process']['plugin'][0]['map']['node_unpublish_by_keyword_action'] = 'node_unpublish_by_keyword_action';
+ try {
+ $source_plugin = \Drupal::service('plugin.manager.migration')
+ ->createStubMigration($migration)
+ ->getSourcePlugin();
+ if (is_a($source_plugin, Action::class) && isset($migration['process']['plugin'])) {
+ $migrations[$migration_id]['process']['plugin'][0]['map']['comment_unpublish_by_keyword_action'] = 'comment_unpublish_by_keyword_action';
+ $migrations[$migration_id]['process']['plugin'][0]['map']['node_unpublish_by_keyword_action'] = 'node_unpublish_by_keyword_action';
+ }
+ } catch (Exception $e) {
+ // Do nothing. This hack added to allow the XML upload to work.
}
}
}

0 comments on commit 7a91117

Please sign in to comment.