public function AmswapConfigForm::submitForm in Admin Menu Swap 7.2
Same name and namespace in other branches
- 8 src/Form/AmswapConfigForm.php \Drupal\amswap\Form\AmswapConfigForm::submitForm()
1 call to AmswapConfigForm::submitForm()
- AmswapConfigForm::amswap_delete_pair in src/Form/AmswapConfigForm.php
File
- src/Form/AmswapConfigForm.php, line 138
Class
- AmswapConfigForm
- Class AmswapConfigForm.
Namespace
Drupal\amswap\Form
Code
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$trigger = $form_state
->getTriggeringElement();
$pairs = [];
$pair_index = 0;
$num_pairs = $form_state
->get('num_pairs');
$num_pairs = $num_pairs ? $num_pairs : 1;
for ($i = 0; $i < $num_pairs; $i++) {
$role = $form_state
->getValue('pair-' . $i . '-role');
$menu = $form_state
->getValue('pair-' . $i . '-menu');
if ($role && $menu) {
$pairs[$pair_index]['role'] = $role;
$pairs[$pair_index]['menu'] = $menu;
$pair_index++;
}
elseif (strpos($trigger['#id'], 'delete') === FALSE) {
$msg = t('Pair ' . ($i + 1) . ' was missing either a role or a menu value, so was not saved.');
drupal_set_message($msg, 'warning', FALSE);
}
}
$this
->config('amswap.amswapconfig')
->set('role_menu_pairs', $pairs)
->save();
$url = \Drupal\Core\Url::fromRoute('system.performance_settings');
$link = \Drupal\Core\Link::fromTextAndUrl('Clear caches', $url);
$msg = $link
->toString() . ' to see the changes.';
$rendered_msg = \Drupal\Core\Render\Markup::create($msg);
drupal_set_message($rendered_msg, 'status', FALSE);
}