function _social_core_node_cancel in Open Social 10.1.x
Same name and namespace in other branches
- 10.3.x modules/social_features/social_core/social_core.module \_social_core_node_cancel()
- 10.0.x modules/social_features/social_core/social_core.module \_social_core_node_cancel()
- 10.2.x modules/social_features/social_core/social_core.module \_social_core_node_cancel()
Redirects to the previous page, or home when pressing cancel form.
Parameters
array $form: Join and leave form.
\Drupal\Core\Form\FormStateInterface $form_state: Form state interface.
1 string reference to '_social_core_node_cancel'
- 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 1017 - The Social core module.
Code
function _social_core_node_cancel(array &$form, FormStateInterface $form_state) {
// By default the front page will be used,
// especially for adding a node.
$form_state
->setRedirect('<front>');
// If we have an existing node, we rather go to the node itself.
if (!empty($form_state
->getFormObject()
->getEntity())) {
$entity = $form_state
->getFormObject()
->getEntity();
if ($entity instanceof NodeInterface && $entity
->id() !== NULL) {
$form_state
->setRedirect('entity.node.canonical', [
'node' => $entity
->id(),
[],
]);
}
}
}