public function AddtocalView::settingsForm in Add to Cal 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldFormatter/AddtocalView.php \Drupal\addtocal\Plugin\Field\FieldFormatter\AddtocalView::settingsForm()
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 DateTimeCustomFormatter::settingsForm
File
- src/
Plugin/ Field/ FieldFormatter/ AddtocalView.php, line 69
Class
- AddtocalView
- Plugin annotation @FieldFormatter( id = "addtocal_view", label = @Translation("Add to Cal"), field_types = { "date", "datestamp", "datetime", "daterange", } )
Namespace
Drupal\addtocal\Plugin\Field\FieldFormatterCode
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$settings = $this
->getSettings();
$field = $this->fieldDefinition;
$location_field_types = [
'string',
'text_with_summary',
'address',
];
$description_field_types = [
'string',
'text_long',
'text_with_summary',
];
$description_options = $location_options = [
FALSE => 'None',
];
$entity_field_list = \Drupal::service('entity_field.manager')
->getFieldDefinitions($field
->getTargetEntityTypeId(), $field
->getTargetBundle());
foreach ($entity_field_list as $entity_field) {
// Filter out base fields like nid, uuid, revisions, etc.
if ($entity_field
->getFieldStorageDefinition()
->isBaseField() == FALSE) {
if (in_array($entity_field
->get('field_type'), $location_field_types)) {
$location_options[$entity_field
->get('field_name')] = $entity_field
->getLabel();
}
if (in_array($entity_field
->get('field_type'), $description_field_types)) {
$description_options[$entity_field
->get('field_name')] = $entity_field
->getLabel();
}
}
}
// Date Range field type settings
if ($field
->getType() == 'daterange') {
$form['separator'] = [
'#type' => 'textfield',
'#title' => $this
->t('Date separator'),
'#description' => $this
->t('The string to separate the start and end dates'),
'#default_value' => $this
->getSetting('separator'),
];
}
$form['location'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Location'),
'#open' => TRUE,
];
$form['location']['value'] = [
'#title' => $this
->t('Location Field:'),
'#type' => 'select',
'#options' => $location_options,
'#default_value' => isset($settings['location']['value']) ? $settings['location']['value'] : '',
'#description' => $this
->t('A field to use as the location for calendar events.'),
];
$form['location']['tokenized'] = [
'#title' => $this
->t('Tokenized Location Contents:'),
'#type' => 'textarea',
'#default_value' => isset($settings['location']['tokenized']) ? $settings['location']['tokenized'] : '',
'#description' => $this
->t('You can insert static text or use tokens (see the token chart below).'),
];
$form['description'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Description'),
'#open' => TRUE,
];
$form['description']['value'] = [
'#title' => $this
->t('Description Field:'),
'#type' => 'select',
'#options' => $description_options,
'#default_value' => $this
->getSetting('description'),
'#description' => $this
->t('A field to use as the description for calendar events. <em>The contents used from this field will be truncated to 1024 characters</em>.'),
];
$form['description']['tokenized'] = [
'#title' => $this
->t('Tokenized Description Contents:'),
'#type' => 'textarea',
'#default_value' => isset($settings['description']['tokenized']) ? $settings['description']['tokenized'] : '',
'#description' => $this
->t('You can insert static text or use tokens (see the token chart below).'),
];
$form['past_events'] = [
'#title' => $this
->t('Show Add to Cal widget for Past Events'),
'#type' => 'checkbox',
'#default_value' => $settings['past_events'],
'#description' => $this
->t('Show the widget for past events.'),
];
return $form;
}