function field_inheritance_entity_form_submit in Field Inheritance 8
Same name and namespace in other branches
- 2.0.x field_inheritance.module \field_inheritance_entity_form_submit()
Form Submit Callback: Field Inheritance Entity Form.
1 string reference to 'field_inheritance_entity_form_submit'
- field_inheritance_form_alter in ./
field_inheritance.module - Implements hook_form_alter().
File
- ./
field_inheritance.module, line 279 - Contains field_inheritance.module.
Code
function field_inheritance_entity_form_submit(&$form, FormStateInterface $form_state) {
$state = \Drupal::keyValue('field_inheritance');
$entity = $form_state
->getFormObject()
->getEntity();
$values = $form_state
->getValues();
$state_key = $entity
->getEntityTypeId() . ':' . $entity
->uuid();
$state_value = [];
if (!empty($values['field_inheritance_enable'])) {
$state_value['enabled'] = TRUE;
foreach ($values as $value_name => $value) {
if (strpos($value_name, 'field_inheritance_field_') === 0) {
$inheritance_name = preg_replace('/^field_inheritance_field_(skip|entity)_/', '', $value_name);
if (!empty($values['field_inheritance_field_skip_' . $inheritance_name])) {
$state_value[$inheritance_name]['skip'] = TRUE;
}
elseif (!empty($values['field_inheritance_field_entity_' . $inheritance_name])) {
$state_value[$inheritance_name]['entity'] = $value;
}
}
}
}
else {
$state_value['enabled'] = FALSE;
}
if (!empty($state_value)) {
$state
->set($state_key, $state_value);
}
else {
$state
->delete($state_key);
}
}