public static function EntityViewDisplayAlterer::submitSmartTitleForm in Smart Title 8
Submit callback for saving the smart title configuration.
Parameters
array $form: The renderable array of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The form state object.
File
- src/
EntityViewDisplayAlterer.php, line 230
Class
- EntityViewDisplayAlterer
- Entity view display form alterer class for Smart Title.
Namespace
Drupal\smart_titleCode
public static function submitSmartTitleForm(array &$form, FormStateInterface $form_state) {
if (!($entity = static::getViewDisplayEntityFromFormState($form_state))) {
return;
}
// Check that Smart Title is/should be enabled.
if ((bool) $form_state
->getValue('smart_title__enabled')) {
$settings_to_save = (bool) $form_state
->get('smart_title_tempvalues') ? $form_state
->get('smart_title_tempvalues') : $entity
->getThirdPartySetting('smart_title', 'settings', []);
$field_values = $form_state
->getValue('fields', [
'smart_title' => [],
]);
// If format settings form was opened when the view display form was asked
// to save its config, we want to save values from that format settings
// subform.
if (!empty($field_values['smart_title']['settings_edit_form'])) {
$settings_to_save = (bool) $field_values['smart_title']['settings_edit_form']['settings'] ? $field_values['smart_title']['settings_edit_form']['settings'] : [];
$settings_to_save['smart_title__classes'] = array_values(array_filter(explode(' ', $settings_to_save['smart_title__classes'])));
}
// If field is hidden, remove our settings.
if (!empty($field_values['smart_title']['region']) && $field_values['smart_title']['region'] === 'hidden') {
$entity
->unSetThirdPartySetting('smart_title', 'settings');
}
else {
$settings_to_save += _smart_title_defaults($entity
->getTargetEntityTypeId(), TRUE);
// Save the (possibly new) config.
$entity
->setThirdPartySetting('smart_title', 'settings', $settings_to_save);
}
}
}