public function YamlFormManagedFileBase::form in YAML Form 8
Gets the actual configuration form array to be built.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array An associative array contain the element's configuration form without any default values..
Overrides YamlFormElementBase::form
File
- src/
Plugin/ YamlFormElement/ YamlFormManagedFileBase.php, line 536
Class
- YamlFormManagedFileBase
- Provides a base class form 'managed_file' elements.
Namespace
Drupal\yamlform\Plugin\YamlFormElementCode
public function form(array $form, FormStateInterface $form_state) {
$form = parent::form($form, $form_state);
$form['file'] = [
'#type' => 'fieldset',
'#title' => $this
->t('File settings'),
];
$scheme_options = self::getVisibleStreamWrappers();
$form['file']['uri_scheme'] = [
'#type' => 'radios',
'#title' => t('Upload destination'),
'#description' => t('Select where the final files should be stored. Private file storage has more overhead than public files, but allows restricted access to files within this element.'),
'#required' => TRUE,
'#options' => $scheme_options,
];
// Public files security warning.
if (isset($scheme_options['public'])) {
$form['file']['uri_public_warning'] = [
'#type' => 'yamlform_message',
'#message_type' => 'warning',
'#message_message' => $this
->t('Public files upload destination is dangerous for forms that are available to anonymous and/or untrusted users.') . ' ' . $this
->t('For more information see: <a href="https://www.drupal.org/psa-2016-003">DRUPAL-PSA-2016-003</a>'),
'#access' => TRUE,
'#states' => [
'visible' => [
':input[name="properties[uri_scheme]"]' => [
'value' => 'public',
],
],
],
];
}
// Private files not set warning.
if (!isset($scheme_options['private'])) {
$form['file']['uri_private_warning'] = [
'#type' => 'yamlform_message',
'#message_type' => 'warning',
'#message_message' => $this
->t('Private file system is not set. This must be changed in <a href="https://www.drupal.org/documentation/modules/file">settings.php</a>. For more information see: <a href="https://www.drupal.org/psa-2016-003">DRUPAL-PSA-2016-003</a>'),
'#access' => TRUE,
];
}
$form['file']['max_filesize'] = [
'#type' => 'number',
'#title' => $this
->t('Maximum file size'),
'#field_suffix' => $this
->t('MB'),
'#description' => $this
->t('Enter the max file size a user may upload.'),
'#min' => 1,
];
$form['file']['file_extensions'] = [
'#type' => 'textfield',
'#title' => $this
->t('File extensions'),
'#description' => $this
->t('A list of additional file extensions for this upload field, separated by spaces.'),
'#maxlength' => 255,
];
$form['file']['multiple'] = [
'#title' => $this
->t('Multiple'),
'#type' => 'checkbox',
'#return_value' => TRUE,
'#description' => $this
->t('Check this option if the user should be allowed to upload multiple files.'),
];
return $form;
}