public function RadioactivityReferenceItem::storageSettingsForm in Radioactivity 4.0.x
Returns a form for the storage-level settings.
Invoked from \Drupal\field_ui\Form\FieldStorageConfigEditForm to allow administrators to configure storage-level settings.
Field storage might reject settings changes that affect the field storage schema if the storage already has data. When the $has_data parameter is TRUE, the form should not allow changing the settings that take part in the schema() method. It is recommended to set #access to FALSE on the corresponding elements.
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.
bool $has_data: TRUE if the field already has data, FALSE if not.
Return value
array The form definition for the field settings.
Overrides EntityReferenceItem::storageSettingsForm
File
- src/
Plugin/ Field/ FieldType/ RadioactivityReferenceItem.php, line 75
Class
- RadioactivityReferenceItem
- Plugin implementation of the Radioactivity Reference field type.
Namespace
Drupal\radioactivity\Plugin\Field\FieldTypeCode
public function storageSettingsForm(array &$form, FormStateInterface $form_state, $has_data) {
$elements = parent::storageSettingsForm($form, $form_state, $has_data);
$elements['target_type']['#access'] = FALSE;
$elements['profile'] = [
'#type' => 'radios',
'#title' => $this
->t('Energy profile'),
'#default_value' => $this
->getSetting('profile'),
'#required' => TRUE,
'#options' => [
'count' => 'Count',
'linear' => 'Linear',
'decay' => 'Decay',
],
'#description' => $this
->t('Count: Energy increases by 1 with each view. Never decreases.<br/>
Linear: Energy increases by the emission amount. Decreases by 1 per second.<br/>
Decay: Energy increases by the emission amount. Decreases 50% per half-life time.'),
];
$elements['granularity'] = [
'#type' => 'number',
'#title' => $this
->t('Granularity'),
'#min' => 1,
'#default_value' => $this
->getSetting('granularity'),
'#description' => $this
->t('The time in seconds that the energy levels are kept before applying the decay.'),
'#states' => [
'visible' => [
'input[name="settings[profile]"]' => [
[
'value' => 'linear',
],
[
'value' => 'decay',
],
],
],
],
];
$elements['halflife'] = [
'#type' => 'number',
'#title' => $this
->t('Half-life time'),
'#min' => 1,
'#default_value' => $this
->getSetting('halflife'),
'#description' => $this
->t('The time in seconds in which the energy level halves.'),
'#states' => [
'visible' => [
'input[name="settings[profile]"]' => [
'value' => 'decay',
],
],
],
];
$elements['cutoff'] = [
'#type' => 'textfield',
'#title' => $this
->t('Cutoff'),
'#pattern' => '[0-9]+(\\.[0-9]+)?',
'#size' => 20,
'#default_value' => $this
->getSetting('cutoff'),
'#description' => $this
->t('Energy levels under this value is set to zero. Example: 0.5, 2.'),
'#states' => [
'invisible' => [
'input[name="settings[profile]"]' => [
'value' => 'count',
],
],
],
];
return $elements;
}