You are here

public static function SocialPostAlbumManagedFile::uploadAjaxCallback in Open Social 10.2.x

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_post/modules/social_post_album/src/Element/SocialPostAlbumManagedFile.php \Drupal\social_post_album\Element\SocialPostAlbumManagedFile::uploadAjaxCallback()
  2. 10.0.x modules/social_features/social_post/modules/social_post_album/src/Element/SocialPostAlbumManagedFile.php \Drupal\social_post_album\Element\SocialPostAlbumManagedFile::uploadAjaxCallback()
  3. 10.1.x modules/social_features/social_post/modules/social_post_album/src/Element/SocialPostAlbumManagedFile.php \Drupal\social_post_album\Element\SocialPostAlbumManagedFile::uploadAjaxCallback()

#ajax callback for managed_file upload forms.

This ajax callback takes care of the following things:

  • Ensures that broken requests due to too big files are caught.
  • Adds a class to the response to be able to highlight in the UI, that a new file got uploaded.

Parameters

array $form: The build form.

\Drupal\Core\Form\FormStateInterface $form_state: The form state.

\Symfony\Component\HttpFoundation\Request $request: The current request.

Return value

\Drupal\Core\Ajax\AjaxResponse The ajax response of the ajax upload.

Overrides ManagedFile::uploadAjaxCallback

File

modules/social_features/social_post/modules/social_post_album/src/Element/SocialPostAlbumManagedFile.php, line 25

Class

SocialPostAlbumManagedFile
Provides an AJAX/progress aware widget for uploading and saving a file.

Namespace

Drupal\social_post_album\Element

Code

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,
  ]));
}