public SwitchShortcutSet::submitForm(array &$form, FormStateInterface $form_state)
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- core/modules/shortcut/src/Form/SwitchShortcutSet.php, line 169
Class
- SwitchShortcutSet
- Builds the shortcut set switch form.
Namespace
Drupal\shortcut\Form
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | public function submitForm( array & $form , FormStateInterface $form_state ) { $account = $this ->currentUser(); $account_is_user = $this ->user->id() == $account ->id(); if ( $form_state ->getValue( 'set' ) == 'new' ) { // Save a new shortcut set with links copied from the user's default set. /* @var \Drupal\shortcut\Entity\ShortcutSet $set */ $set = $this ->shortcutSetStorage->create( array ( 'id' => $form_state ->getValue( 'id' ), 'label' => $form_state ->getValue( 'label' ), )); $set ->save(); $replacements = array ( '%user' => $this ->user->label(), '%set_name' => $set ->label(), ':switch-url' => $this ->url( '<current>' ), ); if ( $account_is_user ) { // Only administrators can create new shortcut sets, so we know they have // access to switch back. drupal_set_message( $this ->t( 'You are now using the new %set_name shortcut set. You can edit it from this page or <a href=":switch-url">switch back to a different one.</a>' , $replacements )); } else { drupal_set_message( $this ->t( '%user is now using a new shortcut set called %set_name. You can edit it from this page.' , $replacements )); } $form_state ->setRedirect( 'entity.shortcut_set.customize_form' , array ( 'shortcut_set' => $set ->id()) ); } else { // Switch to a different shortcut set. /* @var \Drupal\shortcut\Entity\ShortcutSet $set */ $set = $this ->shortcutSetStorage->load( $form_state ->getValue( 'set' )); $replacements = array ( '%user' => $this ->user->getDisplayName(), '%set_name' => $set ->label(), ); drupal_set_message( $account_is_user ? $this ->t( 'You are now using the %set_name shortcut set.' , $replacements ) : $this ->t( '%user is now using the %set_name shortcut set.' , $replacements )); } // Assign the shortcut set to the provided user account. $this ->shortcutSetStorage->assignUser( $set , $this ->user); } |
Please login to continue.