function ccl_add_form_submit in Custom Contextual Links 8
Same name and namespace in other branches
- 7 ccl.admin.inc \ccl_add_form_submit()
Submit handler for ccl_add_form().
See also
2 calls to ccl_add_form_submit()
- CclActionsForm::submitForm in ccl_actions/
src/ Form/ CclActionsForm.php - Form submission handler.
- ccl_actions_form_submit in ccl_actions/
ccl_actions.module - Submit handler for ccl_actions_form().
File
- ./
ccl.admin.inc, line 318 - Provides administrative functions for ccl.
Code
function ccl_add_form_submit($form, &$form_state) {
// Clean up the values array.
$form_state
->cleanValues();
$values = $form_state['values'];
// Extract the options out of the values.
$options = array();
foreach ($values as $key => $data) {
if (strpos($key, 'ccl_') === FALSE) {
$options[$key] = $data;
}
}
$record = array(
'type' => $values['ccl_type'],
'title' => $values['ccl_title'],
'link' => $values['ccl_link'],
'options' => serialize($options),
);
if (isset($form_state['clid'])) {
$record['clid'] = $form_state['clid'];
$res = \Drupal::database()
->merge('ccl')
->fields($record)
->key([
'clid',
])
->execute();
}
else {
$res = \Drupal::database()
->insert('ccl')
->fields($record)
->execute();
}
if ($res) {
drupal_set_message(t('Contextual link saved.'));
_ccl_update_cache();
}
else {
drupal_set_message(t('There was an error writing this record to the database. Please try again.'), 'error');
}
drupal_goto('admin/config/user-interface/ccl');
}