public function FileDownloadLinkFormatter::settingsForm in File Entity (fieldable files) 8.2
Returns a form to configure settings for the formatter.
Invoked from \Drupal\field_ui\Form\EntityDisplayFormBase to allow administrators to configure the formatter. The field_ui module takes care of handling submitted form values.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form elements for the formatter settings.
Overrides FormatterBase::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ FileDownloadLinkFormatter.php, line 101
Class
- FileDownloadLinkFormatter
- Plugin implementation of the 'file_download_link' formatter.
Namespace
Drupal\file_entity\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$element['access_message'] = [
'#type' => 'textfield',
'#title' => t('No access message'),
'#description' => t("This text is shown instead of the download link if the user doesn't have permission to download the file."),
'#default_value' => $this
->getSetting('access_message'),
];
$element['text'] = array(
'#type' => 'textfield',
'#title' => t('Link text'),
'#description' => t('This field supports tokens.'),
'#default_value' => $this
->getSetting('text'),
);
// If we have the token module available, add the token tree link.
if ($this->module_handler
->moduleExists('token')) {
$token_types = array(
'file',
);
if (!empty($form['#entity_type'])) {
$token_types[] = $form['#entity_type'];
}
$element['token_tree_link'] = array(
'#theme' => 'token_tree_link',
'#token_types' => $token_types,
);
}
return $element;
}