Skip to content

Instantly share code, notes, and snippets.

@adityaanurag
Last active June 26, 2017 16:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save adityaanurag/ba7f1a359bd20fdc6554e6516087621f to your computer and use it in GitHub Desktop.
Save adityaanurag/ba7f1a359bd20fdc6554e6516087621f to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\batch_example\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
/**
* Class DeleteNodeForm.
*
* @package Drupal\batch_example\Form
*/
class DeleteNodeForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'delete_node_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['delete_node'] = array(
'#type' => 'submit',
'#value' => $this->t('Delete Node'),
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$nids = \Drupal::entityQuery('node')
->condition('type', 'article')
->sort('created', 'ASC')
->execute();
$batch = array(
'title' => t('Deleting Node...'),
'operations' => array(
array(
'\Drupal\batch_example\DeleteNode::deleteNodeExample',
array($nids)
),
),
'finished' => '\Drupal\batch_example\DeleteNode::deleteNodeExampleFinishedCallback',
);
batch_set($batch);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment