You are here

public function AnonymousPublishingClAdminPrivacy::submitForm in Anonymous Publishing 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

modules/anonymous_publishing_cl/src/Form/AnonymousPublishingClAdminPrivacy.php, line 138

Class

AnonymousPublishingClAdminPrivacy

Namespace

Drupal\anonymous_publishing_cl\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {
  switch ($form_state
    ->getTriggeringElement()['#name']) {
    case 'purge':

      // First delete completly all that are published.
      $this->database
        ->delete('anonymous_publishing')
        ->condition('verified', 1)
        ->execute();

      // For the rest, delete the IP (we need email for whitelist).
      $this->database
        ->update('anonymous_publishing')
        ->fields(array(
        'ip' => '',
      ))
        ->execute();
      $this
        ->messenger()
        ->addMessage(t('All information linking identifiers to published content have been purged.'));
      break;
    case 'save':
      \Drupal::configFactory()
        ->getEditable('anonymous_publishing_cl.settings')
        ->set('retain_period', $form_state
        ->getValue([
        'retain_period',
      ]))
        ->save();
      $this
        ->messenger()
        ->addMessage(t('Rentention period updated.'));
      break;
    default:
      $this
        ->messenger()
        ->addError(t('Unknown operation.'));
      break;
  }
}