public function IframeWidgetBase::massageFormValues in Iframe 8
Same name and namespace in other branches
- 8.2 src/Plugin/Field/FieldWidget/IframeWidgetBase.php \Drupal\iframe\Plugin\Field\FieldWidget\IframeWidgetBase::massageFormValues()
Massages the form values into the format expected for field values.
Parameters
array $values: The submitted form values produced by the widget.
- If the widget does not manage multiple values itself, the array holds the values generated by the multiple copies of the $element generated by the formElement() method, keyed by delta.
- If the widget manages multiple values, the array holds the values of the form element generated by the formElement() method.
array $form: The form structure where field elements are attached to. This might be a full form structure, or a sub-element of a larger form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state.
Return value
array An array of field values, keyed by delta.
Overrides WidgetBase::massageFormValues
File
- src/
Plugin/ Field/ FieldWidget/ IframeWidgetBase.php, line 367
Class
- IframeWidgetBase
- Plugin implementation base functions.
Namespace
Drupal\iframe\Plugin\Field\FieldWidgetCode
public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
// Global values.
$field_settings = $this
->getFieldSettings();
$settings = $this
->getSettings() + $field_settings;
if (isset($settings['expose_class']) && $settings['expose_class']) {
$this->allowedAttributes['class'] = 1;
}
// \iframe_debug(0, __METHOD__ . ' settings', $settings);
// \iframe_debug(0, __METHOD__ . ' old-values', $values);
foreach ($values as $delta => $value) {
/*
* Validate that all keys are available,
* in the user-has-only-some-values case too.
*/
$testvalue = $value + $settings;
$newvalue = [];
foreach ($testvalue as $key => $val) {
if (isset($this->allowedAttributes[$key]) && $this->allowedAttributes[$key]) {
$newvalue[$key] = $val;
}
elseif (isset($settings[$key])) {
$newvalue[$key] = $settings[$key];
}
else {
$newvalue[$key] = $val;
}
}
if (!empty($settings['class']) && !strstr($newvalue['class'], $settings['class'])) {
$newvalue['class'] = trim(implode(" ", [
$settings['class'],
$newvalue['class'],
]));
}
$new_values[$delta] = $newvalue;
}
// \iframe_debug(0, __METHOD__ . ' new-values', $new_values);
return $new_values;
}