-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #3494511 by SV: Replace social_album_form_post_form_alter with …
…hux approach to fix issue with duplicated profile image
- Loading branch information
1 parent
260118e
commit 247c53f
Showing
2 changed files
with
76 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
modules/social_features/social_album/src/Hooks/SocialAlbumFormHooks.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
], | ||
], | ||
]; | ||
} | ||
} | ||
} | ||
|
||
} |