From 2c8f86b5786e190600a1f9afcb20d6ec11603ab7 Mon Sep 17 00:00:00 2001 From: Volodymyr Sydor Date: Tue, 17 Dec 2024 17:08:33 +0200 Subject: [PATCH 1/3] Issue #3494511 by SV: Replace social_album_form_post_form_alter with hux approach to fix issue with duplicated profile image --- .../social_album/social_album.module | 27 ------- .../src/Hooks/SocialAlbumFormHooks.php | 76 +++++++++++++++++++ phpstan-baseline.neon | 15 ---- 3 files changed, 76 insertions(+), 42 deletions(-) create mode 100644 modules/social_features/social_album/src/Hooks/SocialAlbumFormHooks.php diff --git a/modules/social_features/social_album/social_album.module b/modules/social_features/social_album/social_album.module index a104da0a960..954c8961ed2 100644 --- a/modules/social_features/social_album/social_album.module +++ b/modules/social_features/social_album/social_album.module @@ -353,33 +353,6 @@ function social_album_form_comment_form_alter(&$form, FormStateInterface $form_s } } -/** - * Implements hook_form_FORM_ID_alter(). - */ -function social_album_form_post_form_alter(&$form, FormStateInterface $form_state, $form_id) { - if (\Drupal::routeMatch()->getRouteName() === 'social_album.post') { - if (isset($form['current_user_image'])) { - unset($form['current_user_image']); - } - } - elseif (isset($form['field_album'])) { - // Hide album select field when feature is disabled on the image post form. - $status = \Drupal::config('social_album.settings')->get('status'); - if (!$status) { - unset($form['field_album']); - } - else { - $form['field_album']['#states'] = [ - 'visible' => [ - ':input[name="field_post_image[0][fids]"]' => [ - 'filled' => TRUE, - ], - ], - ]; - } - } -} - /** * Implements hook_form_FORM_ID_alter(). */ diff --git a/modules/social_features/social_album/src/Hooks/SocialAlbumFormHooks.php b/modules/social_features/social_album/src/Hooks/SocialAlbumFormHooks.php new file mode 100644 index 00000000000..1ae21df2674 --- /dev/null +++ b/modules/social_features/social_album/src/Hooks/SocialAlbumFormHooks.php @@ -0,0 +1,76 @@ +routeMatch = $route_match; + $this->configFactory = $config_factory; + } + + /** + * Form alter hook: replacement of social_album_form_post_form_alter. + * + * @param array $form + * The drupal form. + * @param \Drupal\Core\Form\FormStateInterface $form_state + * The form state. + */ + #[Alter('form_post_form')] + public function formPostFormAlter(array &$form, FormStateInterface $form_state): void { + if ($this->routeMatch->getRouteName() === 'social_album.post') { + if (isset($form['current_user_image'])) { + unset($form['current_user_image']); + } + } + elseif (isset($form['field_album'])) { + // Hide album select field when feature is disabled on image post form. + $status = $this->configFactory->get('social_album.settings')->get('status'); + if (!$status) { + unset($form['field_album']); + } + else { + $form['field_album']['#states'] = [ + 'visible' => [ + ':input[name="field_post_image[0][fids]"]' => [ + 'filled' => TRUE, + ], + ], + ]; + } + } + } + +} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b73a6256dbf..48e750e7300 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -3118,21 +3118,6 @@ parameters: count: 1 path: modules/social_features/social_album/social_album.module - - - message: "#^Function social_album_form_post_form_alter\\(\\) has no return type specified\\.$#" - count: 1 - path: modules/social_features/social_album/social_album.module - - - - message: "#^Function social_album_form_post_form_alter\\(\\) has parameter \\$form with no type specified\\.$#" - count: 1 - path: modules/social_features/social_album/social_album.module - - - - message: "#^Function social_album_form_post_form_alter\\(\\) has parameter \\$form_id with no type specified\\.$#" - count: 1 - path: modules/social_features/social_album/social_album.module - - message: "#^Function social_album_form_social_post_entity_form_alter\\(\\) has no return type specified\\.$#" count: 1 From fccf7d3b404dc339a5c7733de9fcee76466a02a8 Mon Sep 17 00:00:00 2001 From: Volodymyr Sydor Date: Thu, 19 Dec 2024 14:36:10 +0200 Subject: [PATCH 2/3] Issue #3494511 by SV: Fix of adding class to wrapper when at least one image was loaded --- .../src/Element/SocialPostAlbumManagedFile.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/social_features/social_post/modules/social_post_album/src/Element/SocialPostAlbumManagedFile.php b/modules/social_features/social_post/modules/social_post_album/src/Element/SocialPostAlbumManagedFile.php index f672d187b12..8e93d1e036b 100644 --- a/modules/social_features/social_post/modules/social_post_album/src/Element/SocialPostAlbumManagedFile.php +++ b/modules/social_features/social_post/modules/social_post_album/src/Element/SocialPostAlbumManagedFile.php @@ -24,7 +24,7 @@ class SocialPostAlbumManagedFile extends ManagedFile { */ public static function uploadAjaxCallback(&$form, FormStateInterface &$form_state, Request $request) { $response = parent::uploadAjaxCallback($form, $form_state, $request); - $element_parents = \Drupal::request()->request->get('element_parents'); + $element_parents = \Drupal::request()->query->get('element_parents'); // Either has a parent, or null if no parent, both are fine but can be // bool|float|int|string. if (!is_string($element_parents)) { From 18471ef3551f56539fe06804b20def8eb0677e11 Mon Sep 17 00:00:00 2001 From: Serhii Myronets Date: Thu, 19 Dec 2024 16:32:20 +0200 Subject: [PATCH 3/3] Issue #3494511: Improve position of the throbber button --- .../assets/css/social-post-album--form.css | 9 +++++++-- .../assets/css/social-post-album--form.css.map | 2 +- .../assets/css/social-post-album--form.scss | 10 ++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.css b/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.css index 32fbef086e5..172f06dca89 100644 --- a/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.css +++ b/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.css @@ -7,6 +7,11 @@ .card--stream.social-post-album--form form > .field--name-field-post-image.post-images-loaded { width: 100%; } +.card--stream.social-post-album--form form .field--widget-social-post-album-image .form-managed-file .form-submit { + top: -11px; + right: 11px; + left: auto; +} .card--stream.social-post-album--form form .table-responsive + .image-widget:not(.hidden) { position: absolute; display: block; @@ -245,8 +250,8 @@ } @media (max-width: 599px) { .card--stream.social-post-album--form form #edit-field-album-wrapper .select-wrapper, -.card--stream.social-post-album--form form #edit-field-album-wrapper select, -.card--stream.social-post-album--form form #edit-field-album-wrapper .form-control { + .card--stream.social-post-album--form form #edit-field-album-wrapper select, + .card--stream.social-post-album--form form #edit-field-album-wrapper .form-control { max-width: 100%; } } diff --git a/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.css.map b/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.css.map index d0f167c066f..e96a5858b73 100644 --- a/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.css.map +++ b/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.css.map @@ -1 +1 @@ -{"version":3,"sourceRoot":"","sources":["social-post-album--form.scss"],"names":[],"mappings":"AAEI;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;;AAGF;EAhBF;IAiBI;;;AAGF;EApBF;IAqBI;;;AAGF;EACE;;AAEA;EACE;EACA;;AAIJ;EACE;;AAGF;AAAA;EAEE;EACA;EACA;EACA;EACA;;AAGF;EACE;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EACA;;AAEA;EALF;IAMI;IACA;IACA;;;AAIJ;EACE;;AAEA;EAHF;IAII;;;AAKN;EACE;EACA;;AAGF;EACE;EACA;;AAGF;EACE;;AAKJ;EACE;EACA;EACA;EACA;EACA;;AAEA;EAPF;IAQI;;;AAIJ;EACE;;AAGF;EACE;EACA;EACA;EACA;;AAEA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EATF;IAUI;IACA;;;AAGF;EAdF;IAeI;IACA;;;AAGF;EACE;EACA;;AAGF;EACE;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EAEE;;AAGF;EAEE;EACA;EACA;EACA;EACA;EACA;EACA;;AAGF;EACE;;AAGF;EACE;;AAIJ;EACE;EACA;;AAGF;EACE;EACA;;AAGF;EACE;;AAGF;AAAA;AAAA;EAGE;;AAGF;EACE;;AAEA;EACE;EACA;;AAGF;EARF;IASI;;EAEA;IACE;IACA;;;AAIJ;EAjBF;IAkBI;;EAEA;IACE;IACA;;;AAOV;EACE;EACA;EACA;EACA;EACA;EACA;;AAEA;EARF;IASI;;;AAGF;EACE;EACA;;AAEA;EAJF;IAKI;IACA;IACA;;EAEA;IACE;;EAGF;IACE;;EAEA;IACE;IACA;IACA;;;AASN;EAHF;AAAA;AAAA;IAII;;;AAMJ;EACE;;AAIJ;EACE;;AAEA;EACE;;AAIA;EACE;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EACA;EACA;EACA;;AAIJ;EACE;IACE;;EAEF;IACE;;EAEF;IACE;IACA","file":"social-post-album--form.css"} \ No newline at end of file +{"version":3,"sourceRoot":"","sources":["social-post-album--form.scss"],"names":[],"mappings":"AAEI;EACE;;AAGF;EACE;;AAGF;EACE;;AAKE;EACE;EACA;EACA;;AAKN;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;;AAGF;EAhBF;IAiBI;;;AAGF;EApBF;IAqBI;;;AAGF;EACE;;AAEA;EACE;EACA;;AAIJ;EACE;;AAGF;AAAA;EAEE;EACA;EACA;EACA;EACA;;AAGF;EACE;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EACA;;AAEA;EALF;IAMI;IACA;IACA;;;AAIJ;EACE;;AAEA;EAHF;IAII;;;AAKN;EACE;EACA;;AAGF;EACE;EACA;;AAGF;EACE;;AAKJ;EACE;EACA;EACA;EACA;EACA;;AAEA;EAPF;IAQI;;;AAIJ;EACE;;AAGF;EACE;EACA;EACA;EACA;;AAEA;EACE;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EATF;IAUI;IACA;;;AAGF;EAdF;IAeI;IACA;;;AAGF;EACE;EACA;;AAGF;EACE;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EAEE;;AAGF;EAEE;EACA;EACA;EACA;EACA;EACA;EACA;;AAGF;EACE;;AAGF;EACE;;AAIJ;EACE;EACA;;AAGF;EACE;EACA;;AAGF;EACE;;AAGF;AAAA;AAAA;EAGE;;AAGF;EACE;;AAEA;EACE;EACA;;AAGF;EARF;IASI;;EAEA;IACE;IACA;;;AAIJ;EAjBF;IAkBI;;EAEA;IACE;IACA;;;AAOV;EACE;EACA;EACA;EACA;EACA;EACA;;AAEA;EARF;IASI;;;AAGF;EACE;EACA;;AAEA;EAJF;IAKI;IACA;IACA;;EAEA;IACE;;EAGF;IACE;;EAEA;IACE;IACA;IACA;;;AASN;EAHF;AAAA;AAAA;IAII;;;AAMJ;EACE;;AAIJ;EACE;;AAEA;EACE;;AAIA;EACE;;AAGF;EACE;EACA;EACA;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EACA;EACA;EACA;EACA;;AAEA;EACE;EACA;EACA;EACA;EACA;;AAIJ;EACE;IACE;;EAEF;IACE;;EAEF;IACE;IACA","file":"social-post-album--form.css"} \ No newline at end of file diff --git a/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.scss b/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.scss index 4e70abed702..9c459a63000 100644 --- a/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.scss +++ b/modules/social_features/social_post/modules/social_post_album/assets/css/social-post-album--form.scss @@ -12,6 +12,16 @@ width: 100%; } + .field--widget-social-post-album-image { + .form-managed-file { + .form-submit { + top: -11px; + right: 11px; + left: auto; + } + } + } + .table-responsive + .image-widget:not(.hidden) { position: absolute; display: block;