public function FileDownloadFieldFormatter::settingsForm in File Download 8
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/ FileDownloadFieldFormatter.php, line 36
Class
- FileDownloadFieldFormatter
- Plugin annotation @FieldFormatter( id = "file_download_formatter", label = @Translation("File Download"), field_types = { "file", "image" } )
Namespace
Drupal\file_download\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$form['link_title'] = [
'#type' => 'radios',
'#options' => $this
->getDisplayOptions(),
'#title' => $this
->t('Title Display'),
'#description' => $this
->t('Control what is displayed in the title of the link'),
'#default_value' => $this
->getSetting('link_title'),
];
$fieldName = $this->fieldDefinition
->getName();
$form['custom_title_text'] = [
'#type' => 'textfield',
'#title' => $this
->t('Custom text'),
'#default_value' => $this
->getSetting('custom_title_text'),
'#placeholder' => $this
->t('e.g. "Download"'),
'#description' => $this
->t('Provide a custom text to display for all download links. This field takes HTML and @link', [
'@link' => '<a href="/admin/help/token">file entity tokens for current user, file and parent entity.</a>',
]),
'#states' => [
'visible' => [
":input[name=\"fields[{$fieldName}][settings_edit_form][settings][link_title]\"]" => [
'value' => 'custom',
],
],
],
];
$form['file_size'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display file size'),
'#description' => $this
->t('Displays the size of the file next to the download link.'),
'#default_value' => $this
->getSetting('file_size'),
];
return $form;
}