DeleteForm.php in Activity 8
File
src/Form/DeleteForm.php
View source
<?php
namespace Drupal\activity\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Path\CurrentPathStack;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Database\Connection;
abstract class DeleteForm extends FormBase {
protected $database;
protected $pathArgs;
protected $currentPath;
public function __construct(Connection $database, CurrentPathStack $currentPath) {
$this->database = $database;
$this->currentPath = $currentPath;
$this->pathArgs = $path_args = explode('/', $this->currentPath
->getPath());
}
public static function create(ContainerInterface $container) {
return new static($container
->get('database'), $container
->get('path.current'));
}
public abstract function getFormId();
public function buildForm(array $form, FormStateInterface $form_state, $label = '') {
$form['delete_activities'] = [
'#type' => 'label',
'#title' => '',
];
$form['submit'] = [
'#type' => 'submit',
'#value' => t('Delete'),
];
$form['cancel_delete'] = [
'#title' => $this
->t('Cancel'),
'#type' => 'link',
'#url' => Url::fromUri('internal:/admin/activity'),
];
return $form;
}
public abstract function submitForm(array &$form, FormStateInterface $form_state);
}