function _social_core_path_widget_submit in Open Social 10.3.x
Same name and namespace in other branches
- 10.0.x modules/social_features/social_core/social_core.module \_social_core_path_widget_submit()
- 10.1.x modules/social_features/social_core/social_core.module \_social_core_path_widget_submit()
- 10.2.x modules/social_features/social_core/social_core.module \_social_core_path_widget_submit()
Custom form submit handler for handling an path alias update.
Parameters
array $form: The form array.
\Drupal\Core\Form\FormStateInterface $form_state: Form state.
Throws
\Drupal\Core\Entity\EntityStorageException
1 string reference to '_social_core_path_widget_submit'
- social_core_form_node_form_alter in modules/
social_features/ social_core/ social_core.module - Implements hook_form_FORM_ID_alter().
File
- modules/
social_features/ social_core/ social_core.module, line 983 - The Social core module.
Code
function _social_core_path_widget_submit(array $form, FormStateInterface $form_state) {
// Path uses the pathauto checkbox to decide whether or not to save
// the automatically generated alias, or use a custom one.
// since we hide the element, and the default is checked,
// the path will never be overridden if someone updates it.
// So we need to check this in our custom submit handler.
$default_path = isset($form['path']['widget'][0]['alias']['#default_value']) ? $form['path']['widget'][0]['alias']['#default_value'] : '';
$input = $form_state
->getUserInput();
$updated_path = isset($input['path'][0]['alias']) ? $input['path'][0]['alias'] : '';
// If we don't have a match, make sure we override the checkbox as well.
if ($updated_path !== $default_path) {
// Override the User input, act as if this was changed.
$input['path'][0]['pathauto'] = "0";
$form_state
->setUserInput($input);
// Override the value.
$form_state
->setValue([
'path',
'0',
'pathauto',
], "0");
// If the updated path is empty, make it automatic again.
if (empty($updated_path)) {
$input['path'][0]['pathauto'] = "1";
$form_state
->setUserInput($input);
$form_state
->setValue([
'path',
'0',
'pathauto',
], "1");
}
}
}