SocialPostAlbumManagedFile.php in Open Social 10.2.x
File
modules/social_features/social_post/modules/social_post_album/src/Element/SocialPostAlbumManagedFile.php
View source
<?php
namespace Drupal\social_post_album\Element;
use Drupal\Core\Ajax\InvokeCommand;
use Drupal\Core\Form\FormStateInterface;
use Drupal\file\Element\ManagedFile;
use Symfony\Component\HttpFoundation\Request;
class SocialPostAlbumManagedFile extends ManagedFile {
const CLASS_NAME = 'post-images-loaded';
public static function uploadAjaxCallback(&$form, FormStateInterface &$form_state, Request $request) {
$response = parent::uploadAjaxCallback($form, $form_state, $request);
$parents = explode('/', $request->query
->get('element_parents'));
return $response
->addCommand(new InvokeCommand('#edit-' . str_replace('_', '-', $parents[0]) . '-wrapper', 'addClass', [
self::CLASS_NAME,
]));
}
public static function processManagedFile(&$element, FormStateInterface $form_state, &$complete_form) {
if (!empty($element['#value']['fids'])) {
$complete_form[$element['#field_name']]['#attributes']['class'][] = self::CLASS_NAME;
}
return parent::processManagedFile($element, $form_state, $complete_form);
}
}