public function ComputedFieldItemBase::fieldSettingsForm in Computed Field 8.2
Same name and namespace in other branches
- 3.x src/Plugin/Field/FieldType/ComputedFieldItemBase.php \Drupal\computed_field\Plugin\Field\FieldType\ComputedFieldItemBase::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
3 calls to ComputedFieldItemBase::fieldSettingsForm()
- ComputedDecimalItem::fieldSettingsForm in src/
Plugin/ Field/ FieldType/ ComputedDecimalItem.php - Returns a form for the field-level settings.
- ComputedFloatItem::fieldSettingsForm in src/
Plugin/ Field/ FieldType/ ComputedFloatItem.php - Returns a form for the field-level settings.
- ComputedIntegerItem::fieldSettingsForm in src/
Plugin/ Field/ FieldType/ ComputedIntegerItem.php - Returns a form for the field-level settings.
3 methods override ComputedFieldItemBase::fieldSettingsForm()
- ComputedDecimalItem::fieldSettingsForm in src/
Plugin/ Field/ FieldType/ ComputedDecimalItem.php - Returns a form for the field-level settings.
- ComputedFloatItem::fieldSettingsForm in src/
Plugin/ Field/ FieldType/ ComputedFloatItem.php - Returns a form for the field-level settings.
- ComputedIntegerItem::fieldSettingsForm in src/
Plugin/ Field/ FieldType/ ComputedIntegerItem.php - Returns a form for the field-level settings.
File
- src/
Plugin/ Field/ FieldType/ ComputedFieldItemBase.php, line 30
Class
- ComputedFieldItemBase
- Plugin base of the generic field type.
Namespace
Drupal\computed_field\Plugin\Field\FieldTypeCode
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = $this
->getFieldSettingsFormBase($form, $form_state);
$settings = $this
->getSettings();
$element['prefix'] = [
'#type' => 'textfield',
'#title' => t('Prefix'),
'#default_value' => $settings['prefix'],
'#size' => 60,
'#description' => t("Define a string that should be prefixed to the value, like '\$ ' or '€ '. Leave blank for none. Separate singular and plural values with a pipe ('pound|pounds')."),
];
$element['suffix'] = [
'#type' => 'textfield',
'#title' => t('Suffix'),
'#default_value' => $settings['suffix'],
'#size' => 60,
'#description' => t("Define a string that should be suffixed to the value, like ' m', ' kb/s'. Leave blank for none. Separate singular and plural values with a pipe ('pound|pounds')."),
];
$element['code']['#title'] = $this
->t('Code (PHP) to compute the numeric value');
$element['code']['#description'] .= t('
<p>
Here\'s a simple example using the <code>$entity</code>-array which sets the computed field\'s value to the value of the sum of the number fields (<code>field_a</code> and <code>field_b</code>) in an entity:
<ul>
<li><code>$value = $entity->field_a->value + $entity->field_b->value;</code></li>
</ul>
</p>
<p>
An alternative example using the <code>$fields</code>-array:
<ul>
<li><code>$value = $fields[\'field_a\'][0][\'value\'] + $fields[\'field_b\'][0][\'value\'];</code></li>
</ul>
</p>
');
return $element;
}