Skip to content
Snippets Groups Projects
Commit 9975c7f2 authored by Robert Phillips's avatar Robert Phillips
Browse files

Issue #3366312: Add field widget alter.

parent de463766
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @file
* File uploader settings.
*
* @see https://git.drupalcode.org/project/file_uploader/-/blob/main/example.file_uploader.settings.php
*/
$settings['file_uploader'] = [
'instance' => [
'autoProceed' => TRUE,
],
'plugin' => [
'showProgressDetails' => TRUE,
],
];
<?php
/**
* @file
* Hooks provided by the module.
*/
/**
* @addtogroup hooks
* @{
*/
use Drupal\Core\Form\FormStateInterface;
/**
* Alter the file uploader options.
*
* @param array $options
* An array of uploader options.
* @param array $element
* The form element.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
function hook_file_uploader_options_alter(array &$options, array $element, FormStateInterface $form_state): void {
$options['instance']['autoProceed'] = TRUE;
}
/**
* @} End of "addtogroup hooks".
*/
......@@ -4,9 +4,7 @@ namespace Drupal\file_uploader\Element;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\Url;
use Drupal\file\Element\ManagedFile;
use Drupal\file\Entity\File;
......@@ -92,11 +90,12 @@ class FileUploader extends ManagedFile {
'#value' => implode(' ', $fids),
];
// Attach options to JavaScript settings.
// Invoke hook_file_uploader_options(). Allows modules and themes
// to easily alter the file uploader options.
$options = $element['#upload_options'];
if ($settings = Settings::get('file_uploader')) {
$options = NestedArray::mergeDeep($options, $settings);
}
\Drupal::moduleHandler()->alter('file_uploader_options', $options, $element, $form_state);
\Drupal::theme()->alter('file_uploader_options', $options, $element, $form_state);
$element['#attached']['drupalSettings']['file_uploader'][$element['#id']] = [
'provider' => $provider,
'name' => implode('_', $element['#parents']),
......
......@@ -8,7 +8,6 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Language\LanguageManagerInterface;
use Drupal\Core\Link;
use Drupal\Core\Security\TrustedCallbackInterface;
use Drupal\Core\Site\Settings;
use Drupal\Core\Url;
use Drupal\file\Plugin\Field\FieldWidget\FileWidget;
use Drupal\file_uploader\Element\FileUploader;
......@@ -160,9 +159,6 @@ class FileUploaderWidgetBase extends FileWidget implements TrustedCallbackInterf
* {@inheritdoc}
*/
public static function process($element, FormStateInterface $form_state, $form) {
if ($options = Settings::get('file_uploader_uppy')) {
$element['#upload_options'] = NestedArray::mergeDeep($element['#upload_options'], $options);
}
return $element;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment