public static function Attach::settings in FileField Sources 8
Implements hook_filefield_source_settings().
File
- src/
Plugin/ FilefieldSource/ Attach.php, line 265
Class
- Attach
- A FileField source plugin to allow use of files within a server directory.
Namespace
Drupal\filefield_sources\Plugin\FilefieldSourceCode
public static function settings(WidgetInterface $plugin) {
$settings = $plugin
->getThirdPartySetting('filefield_sources', 'filefield_sources', [
'source_attach' => [
'path' => FILEFIELD_SOURCE_ATTACH_DEFAULT_PATH,
'absolute' => FILEFIELD_SOURCE_ATTACH_RELATIVE,
'attach_mode' => FILEFIELD_SOURCE_ATTACH_MODE_MOVE,
],
]);
$return['source_attach'] = [
'#title' => t('File attach settings'),
'#type' => 'details',
'#description' => t('File attach allows for selecting a file from a directory on the server, commonly used in combination with FTP.') . ' <strong>' . t('This file source will ignore file size checking when used.') . '</strong>',
'#element_validate' => [
[
get_called_class(),
'filePathValidate',
],
],
'#weight' => 3,
];
$return['source_attach']['path'] = [
'#type' => 'textfield',
'#title' => t('File attach path'),
'#default_value' => $settings['source_attach']['path'],
'#size' => 60,
'#maxlength' => 128,
'#description' => t('The directory within the <em>File attach location</em> that will contain attachable files.'),
];
if (\Drupal::moduleHandler()
->moduleExists('token')) {
$return['source_attach']['tokens'] = [
'#theme' => 'token_tree',
'#token_types' => [
'user',
],
];
}
$return['source_attach']['absolute'] = [
'#type' => 'radios',
'#title' => t('File attach location'),
'#options' => [
FILEFIELD_SOURCE_ATTACH_RELATIVE => t('Within the files directory'),
FILEFIELD_SOURCE_ATTACH_ABSOLUTE => t('Absolute server path'),
],
'#default_value' => $settings['source_attach']['absolute'],
'#description' => t('The <em>File attach path</em> may be with the files directory (%file_directory) or from the root of your server. If an absolute path is used and it does not start with a "/" your path will be relative to your site directory: %realpath.', [
'%file_directory' => \Drupal::service('file_system')
->realpath(\Drupal::config('system.file')
->get('default_scheme') . '://'),
'%realpath' => realpath('./'),
]),
];
$return['source_attach']['attach_mode'] = [
'#type' => 'radios',
'#title' => t('Attach method'),
'#options' => [
FILEFIELD_SOURCE_ATTACH_MODE_MOVE => t('Move the file directly to the final location'),
FILEFIELD_SOURCE_ATTACH_MODE_COPY => t('Leave a copy of the file in the attach directory'),
],
'#default_value' => isset($settings['source_attach']['attach_mode']) ? $settings['source_attach']['attach_mode'] : 'move',
];
return $return;
}