Skip to content

Commit

Permalink
Issue #3494511 by SV: Replace social_album_form_post_form_alter with …
Browse files Browse the repository at this point in the history
…hux approach to fix issue with duplicated profile image
  • Loading branch information
volodymyr-sydor committed Dec 17, 2024
1 parent 260118e commit 247c53f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 27 deletions.
27 changes: 0 additions & 27 deletions modules/social_features/social_album/social_album.module
Original file line number Diff line number Diff line change
Expand Up @@ -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().
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Drupal\social_album\Hooks;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\hux\Attribute\Alter;

/**
* Replace hook: social_album_form_post_form_alter.
*
* @package Drupal\social_album\Hooks
*/
final class SocialAlbumFormHooks {

/**
* The current route match.
*/
protected RouteMatchInterface $routeMatch;

/**
* The config factory service.
*/
protected ConfigFactoryInterface $configFactory;

/**
* Constructor.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory service.
*/
public function __construct(
RouteMatchInterface $route_match,
ConfigFactoryInterface $config_factory
) {
$this->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,
],
],
];
}
}
}

}

0 comments on commit 247c53f

Please sign in to comment.