public function SimpleMathField::buildOptionsForm in Views Simple Math Field 8.2
Same name and namespace in other branches
- 8 src/Plugin/views/field/SimpleMathField.php \Drupal\views_simple_math_field\Plugin\views\field\SimpleMathField::buildOptionsForm()
Default options form that provides the label widget that all fields should have.
Overrides NumericField::buildOptionsForm
File
- src/
Plugin/ views/ field/ SimpleMathField.php, line 87 - Defines Drupal\views_simple_math_field\Plugin\views\field\SimpleMathField.
Class
- SimpleMathField
- Field handler to complete mathematical operation.
Namespace
Drupal\views_simple_math_field\Plugin\views\fieldCode
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
parent::buildOptionsForm($form, $form_state);
$fieldDelta = preg_replace('[\\D]', '', $this->options['id']);
$fieldList = $this->displayHandler
->getFieldLabels();
foreach ($fieldList as $key => $value) {
if ($this->field_alias === $key && $fieldDelta < preg_replace('[\\D]', '', $key)) {
unset($fieldList[$key]);
}
else {
$fieldList[$key] .= new FormattableMarkup(". Formula token: @%field", [
"%field" => $key,
]);
}
}
unset($fieldList[$this->options['id']]);
$form['fieldset_one'] = [
'#type' => 'fieldset',
'#title' => t('Select the fields to use in the formula.'),
'#collapsible' => FALSE,
'#collapsed' => FALSE,
'#weight' => -10,
'#required' => TRUE,
];
$form['fieldset_one']['data_field'] = [
'#type' => 'checkboxes',
'#title' => t('Data Fields'),
'#options' => $fieldList,
'#default_value' => $this->options['fieldset_one']['data_field'],
'#weight' => -10,
];
$form['fieldset_one']['formula'] = [
'#type' => 'textarea',
'#title' => t('Formula'),
'#default_value' => $this->options['fieldset_one']['formula'],
'#weight' => -8,
'#description' => t('Enter the formula to give this field its value. You can use any fields specified in the checkboxes above, using the formula token listed beside the field name. It uses the EvalMath library, refer to this web to see math expressions: <a href=":url">project in github</a>.', [
':url' => Url::fromUri('https://github.com/Tramasec/eval-math')
->toString(),
]),
];
return $form;
}