public function YearOnlyItem::fieldSettingsForm in Year Only 8
Same name and namespace in other branches
- 9.0.x src/Plugin/Field/FieldType/YearOnlyItem.php \Drupal\yearonly\Plugin\Field\FieldType\YearOnlyItem::fieldSettingsForm()
Returns a form for the field-level settings.
Invoked from \Drupal\field_ui\Form\FieldConfigEditForm to allow administrators to configure field-level settings.
Parameters
array $form: The form where the settings form is being included in.
\Drupal\Core\Form\FormStateInterface $form_state: The form state of the (entire) configuration form.
Return value
array The form definition for the field settings.
Overrides FieldItemBase::fieldSettingsForm
File
- src/
Plugin/ Field/ FieldType/ YearOnlyItem.php, line 73
Class
- YearOnlyItem
- Plugin implementation of the 'yearonly' field type.
Namespace
Drupal\yearonly\Plugin\Field\FieldTypeCode
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = [];
$element['#markup'] = '<strong>' . $this
->t('Select yearonly field range. This field will display the range as selected below on form.') . '</strong>';
$options = array_combine(range(1900, date('Y') - 1), range(1900, date('Y') - 1));
$element['yearonly_from'] = [
'#type' => 'select',
'#title' => $this
->t('From'),
'#default_value' => $this
->getSetting('yearonly_from'),
'#options' => $options,
'#description' => $this
->t('Select starting year.'),
'#weight' => 1,
];
$options = [
'now' => 'NOW',
];
$options += array_combine(range(date('Y') + 1, date('Y') + 50), range(date('Y') + 1, date('Y') + 50));
$element['yearonly_to'] = [
'#type' => 'select',
'#title' => $this
->t('To'),
'#default_value' => $this
->getSetting('yearonly_to'),
'#options' => $options,
'#description' => $this
->t('Select last year.'),
'#weight' => 1,
];
return $element;
}