class TableDragExampleResetForm
Same name in other branches
- 3.x modules/tabledrag_example/src/Form/TableDragExampleResetForm.php \Drupal\tabledrag_example\Form\TableDragExampleResetForm
- 4.0.x modules/tabledrag_example/src/Form/TableDragExampleResetForm.php \Drupal\tabledrag_example\Form\TableDragExampleResetForm
Table drag example reset form.
@package Drupal\tabledrag_example\Form
Hierarchy
- class \Drupal\tabledrag_example\Form\TableDragExampleResetForm extends \Drupal\Core\Form\ConfirmFormBase
Expanded class hierarchy of TableDragExampleResetForm
1 string reference to 'TableDragExampleResetForm'
- tabledrag_example.routing.yml in tabledrag_example/
tabledrag_example.routing.yml - tabledrag_example/tabledrag_example.routing.yml
File
-
tabledrag_example/
src/ Form/ TableDragExampleResetForm.php, line 17
Namespace
Drupal\tabledrag_example\FormView source
class TableDragExampleResetForm extends ConfirmFormBase {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('database'));
}
/**
* Construct a form.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'tabledrag_example_reset';
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this->t('Reset demo data for TableDrag Example');
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
return new Url('tabledrag_example.description');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
return $this->t('Are you sure you want to reset demo data?');
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this->t('Yes, Reset It!');
}
/**
* {@inheritdoc}
*/
public function getCancelText() {
return $this->t('Cancel');
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$data = Fixtures::getSampleItems();
foreach ($data as $id => $item) {
// Add 1 to each array key to match ID.
$id++;
$this->database
->update('tabledrag_example')
->fields([
'weight' => 0,
'pid' => 0,
'description' => $item['description'],
'itemgroup' => $item['itemgroup'],
])
->condition('id', $id, '=')
->execute();
}
$this->messenger()
->addMessage($this->t('Data for TableDrag Example has been reset.'), 'status');
$form_state->setRedirect('tabledrag_example.description');
}
}
Members
Title Sort descending | Modifiers | Object type | Summary |
---|---|---|---|
TableDragExampleResetForm::$database | protected | property | The database connection. |
TableDragExampleResetForm::create | public static | function | |
TableDragExampleResetForm::getCancelText | public | function | |
TableDragExampleResetForm::getCancelUrl | public | function | |
TableDragExampleResetForm::getConfirmText | public | function | |
TableDragExampleResetForm::getDescription | public | function | |
TableDragExampleResetForm::getFormId | public | function | |
TableDragExampleResetForm::getQuestion | public | function | |
TableDragExampleResetForm::submitForm | public | function | |
TableDragExampleResetForm::__construct | public | function | Construct a form. |