Same name and namespace in other branches
  1. 8.9.x core/modules/file/src/Plugin/Field/FieldType/FileItem.php \Drupal\file\Plugin\Field\FieldType\FileItem::fieldSettingsForm()
  2. 9 core/modules/file/src/Plugin/Field/FieldType/FileItem.php \Drupal\file\Plugin\Field\FieldType\FileItem::fieldSettingsForm()
1 call to FileItem::fieldSettingsForm()
ImageItem::fieldSettingsForm in core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
1 method overrides FileItem::fieldSettingsForm()
ImageItem::fieldSettingsForm in core/modules/image/src/Plugin/Field/FieldType/ImageItem.php

File

core/modules/file/src/Plugin/Field/FieldType/FileItem.php, line 166

Class

FileItem
Plugin implementation of the 'file' field type.

Namespace

Drupal\file\Plugin\Field\FieldType

Code

public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
  $element = [];
  $settings = $this
    ->getSettings();
  $element['file_directory'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('File directory'),
    '#default_value' => $settings['file_directory'],
    '#description' => $this
      ->t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'),
    '#element_validate' => [
      [
        static::class,
        'validateDirectory',
      ],
    ],
    '#weight' => 3,
  ];

  // Make the extension list a little more human-friendly by comma-separation.
  $extensions = str_replace(' ', ', ', $settings['file_extensions']);
  $element['file_extensions'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Allowed file extensions'),
    '#default_value' => $extensions,
    '#description' => $this
      ->t("Separate extensions with a comma or space. Each extension can contain alphanumeric characters, '.', and '_', and should start and end with an alphanumeric character."),
    '#element_validate' => [
      [
        static::class,
        'validateExtensions',
      ],
    ],
    '#weight' => 1,
    '#maxlength' => 256,
    // By making this field required, we prevent a potential security issue
    // that would allow files of any type to be uploaded.
    '#required' => TRUE,
  ];
  $element['max_filesize'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Maximum upload size'),
    '#default_value' => $settings['max_filesize'],
    '#description' => $this
      ->t('Enter a value like "512" (bytes), "80 KB" (kilobytes) or "50 MB" (megabytes) in order to restrict the allowed file size. If left empty the file sizes could be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', [
      '%limit' => ByteSizeMarkup::create(Environment::getUploadMaxSize()),
    ]),
    '#size' => 10,
    '#element_validate' => [
      [
        static::class,
        'validateMaxFilesize',
      ],
    ],
    '#weight' => 5,
  ];
  $element['description_field'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable <em>Description</em> field'),
    '#default_value' => $settings['description_field'] ?? '',
    '#description' => $this
      ->t('The description field allows users to enter a description about the uploaded file.'),
    '#weight' => 11,
  ];
  return $element;
}