public function ComputedFieldItemTrait::fieldSettingsForm in Computed Field 8.2
Same name and namespace in other branches
- 3.x src/Plugin/Field/FieldType/ComputedFieldItemTrait.php \Drupal\computed_field\Plugin\Field\FieldType\ComputedFieldItemTrait::fieldSettingsForm()
2 calls to ComputedFieldItemTrait::fieldSettingsForm()
- ComputedFieldItemBase::fieldSettingsForm in src/
Plugin/ Field/ FieldType/ ComputedFieldItemBase.php - Returns a form for the field-level settings.
- ComputedStringItemBase::fieldSettingsForm in src/
Plugin/ Field/ FieldType/ ComputedStringItemBase.php - Returns a form for the field-level settings.
File
- src/
Plugin/ Field/ FieldType/ ComputedFieldItemTrait.php, line 58
Class
- ComputedFieldItemTrait
- Common methods for Computed Field FieldType plugins.
Namespace
Drupal\computed_field\Plugin\Field\FieldTypeCode
public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
$element = [];
$settings = $this
->getSettings();
$element['code'] = [
'#type' => 'textarea',
'#title' => $this
->t('Code (PHP) to compute the value'),
'#default_value' => $settings['code'],
'#required' => TRUE,
'#disabled' => $this
->computeFunctionNameExists(),
'#description' => t('
<p>
<em><strong>WARNING:</strong> We strongly recommend that code be provided by a
hook implementation in one of your custom modules, not here. This is far more
secure than allowing code to be entered into this form from the Web UI. In
addition, any code saved here will be stored in the database instead of your
revision control system, which probably is not what you want. The hook
implementation function signature should be
<strong>%function($entity_type_manager, $entity, $fields, $delta)</strong>,
and the desired value should be returned. If/when it exists, this form element
will be greyed out.</em>
</p>
<p>The variables available to your code include:</p>
<ul>
<li><code>$entity_type_manager</code>: The entity type manager.</li>
<li><code>$entity</code>: The entity the field belongs to.</li>
<li><code>$fields</code>: The list of fields available in this entity.</li>
<li><code>$delta</code>: Current index of the field in case of multi-value computed fields (counting from 0).</li>
<li><code>$value</code>: The resulting value to be set above, or returned in your hook implementation).</li>
</ul>
', [
'%function' => $this
->getComputeFunctionName(),
]),
];
return $element;
}