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..75c80a125f4 --- /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 the 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, + ], + ], + ]; + } + } + } + +}