Skip to content

Commit

Permalink
[#433] Fix default_max_filesize error where the value needs to be an int
Browse files Browse the repository at this point in the history
Since the field is being disabled, the validator isn't needed
  • Loading branch information
ericras committed Jun 7, 2023
1 parent 21b9505 commit 84d258e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions web/modules/custom/unl_webform/unl_webform.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Modifies Webform UI to pare down options and enforce defaults.
*/

use Drupal\Component\Utility\Bytes;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\WebformInterface;
Expand Down Expand Up @@ -257,8 +258,9 @@ function unl_webform_form_webform_ui_element_form_alter(&$form, FormStateInterfa
$form['properties']['file']['sanitize']['#default_value'] = TRUE;
$form['properties']['file']['sanitize']['#disabled'] = TRUE;

// Set max file size to 10M.
$form['properties']['file']['max_filesize']['#default_value'] = $config->get('file.default_max_filesize');
// Set 'Maximum file size'.
$max_filesize = Bytes::toNumber($config->get('file.default_max_filesize')) / 1024 / 1024;
$form['properties']['file']['max_filesize']['#default_value'] = $max_filesize;
$form['properties']['file']['max_filesize']['#disabled'] = TRUE;

// Remove upload button option.
Expand Down Expand Up @@ -290,9 +292,6 @@ function unl_webform_webform_ui_element_form_validate($form, FormStateInterface
|| $element_type == 'webform_document_file'
|| $element_type == 'webform_image_file'
) {
// Enforce defaults.
$form_state->setValue(['properties', 'sanitize'], TRUE);
$form_state->setValue(['properties', 'max_filesize'], $config->get('file.default_max_filesize'));

// Validate file extensions.
$extensions = explode(' ', $form_state->getValue(['properties', 'file_extensions']));
Expand Down

0 comments on commit 84d258e

Please sign in to comment.