You are here

public function FileItem::fieldSettingsForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/file/src/Plugin/Field/FieldType/FileItem.php \Drupal\file\Plugin\Field\FieldType\FileItem::fieldSettingsForm()

Returns a form for the field-level settings.

Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.

Parameters

array $form: The form where the settings form is being included in.

\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.

Return value

array The form definition for the field settings.

Overrides EntityReferenceItem::fieldSettingsForm

1 call to FileItem::fieldSettingsForm()
ImageItem::fieldSettingsForm in core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
Returns a form for the field-level settings.
1 method overrides FileItem::fieldSettingsForm()
ImageItem::fieldSettingsForm in core/modules/image/src/Plugin/Field/FieldType/ImageItem.php
Returns a form for the field-level settings.

File

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

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' => t('File directory'),
    '#default_value' => $settings['file_directory'],
    '#description' => t('Optional subdirectory within the upload destination where files will be stored. Do not include preceding or trailing slashes.'),
    '#element_validate' => [
      [
        get_class($this),
        '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' => t('Allowed file extensions'),
    '#default_value' => $extensions,
    '#description' => t('Separate extensions with a space or comma and do not include the leading dot.'),
    '#element_validate' => [
      [
        get_class($this),
        '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' => t('Maximum upload size'),
    '#default_value' => $settings['max_filesize'],
    '#description' => 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 will be limited only by PHP\'s maximum post and file upload sizes (current limit <strong>%limit</strong>).', [
      '%limit' => format_size(Environment::getUploadMaxSize()),
    ]),
    '#size' => 10,
    '#element_validate' => [
      [
        get_class($this),
        'validateMaxFilesize',
      ],
    ],
    '#weight' => 5,
  ];
  $element['description_field'] = [
    '#type' => 'checkbox',
    '#title' => t('Enable <em>Description</em> field'),
    '#default_value' => isset($settings['description_field']) ? $settings['description_field'] : '',
    '#description' => t('The description field allows users to enter a description about the uploaded file.'),
    '#weight' => 11,
  ];
  return $element;
}