public function access_by_ref_settings_form::submitForm in Access by Reference 8
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
- src/
Form/ access_by_ref_settings_form.php, line 257
Class
- access_by_ref_settings_form
- Configure example settings for this site.
Namespace
Drupal\access_by_ref\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Retrieve the configuration
$vals = $form_state
->getValues()['abr'];
foreach ($vals as $key => $row) {
$sql = '';
$id = explode(':', $key)[1];
$cbox = $row['cbox'];
// Delete this.
if ($cbox == 1) {
$sql = "DELETE FROM {access_by_ref} WHERE `id` = :rowid";
$result = \Drupal::database()
->query($sql, array(
':rowid' => $id,
));
break;
// go to next row
}
unset($row['cbox']);
// remove it from the array
$parms = array_combine(array(
':node_type',
':reference_type',
':node_field',
':reference_data',
), $row);
// unused array, set it to a string to avoid an error
$parms[':reference_data'] = '';
if ($id == 'new' && strlen($parms[':node_type']) > 3 && strlen($parms[':reference_type']) > 3) {
$sql = "INSERT INTO {access_by_ref} (`node_type`, `node_field`, `reference_type`, `reference_data`) VALUES ( :node_type, :node_field, :reference_type, :reference_data)";
}
else {
if ($id !== 'new') {
// it's an update
$sql = "UPDATE {access_by_ref} SET `node_type` = :node_type, `node_field`= :node_field, `reference_type`=:reference_type, `reference_data` = :reference_data\n WHERE `id` = :id ";
// Add that parm.
$parms[':id'] = $id;
}
}
// okay, now run the query
if ($sql !== '') {
$result = \Drupal::database()
->query($sql, $parms);
}
}
// Flush the cache.
$this
->flush_twig();
}