DeleteActionForm.php in Activity 8
File
src/Form/DeleteActionForm.php
View source
<?php
namespace Drupal\activity\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class DeleteActionForm extends DeleteForm {
public function getFormId() {
return 'delete_activities_action_form';
}
public function buildForm(array $form, FormStateInterface $form_state, $label = '') {
$form = parent::buildForm($form, $form_state);
$form['delete_activities'] = [
'#type' => 'label',
'#title' => t('Delete this action? This cannot be undone.'),
];
$form['cancel_delete'] = [
'#title' => $this
->t('Cancel'),
'#type' => 'link',
'#url' => Url::fromUri('internal:/activities/all'),
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$query = $this->database
->delete('activity');
$query
->condition('action_id', $this->pathArgs[5]);
$query
->execute();
$url = Url::fromUri('internal:/activities/all');
$form_state
->setRedirectUrl($url);
drupal_set_message(t('Action @action deleted.', [
'@action' => $this->pathArgs[5],
]));
}
}