Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

There is now an abstract base class(ConfirmFormBase) that implements FormInterface with specific methods that represent the parameters used by confirm_form().

The confirm_form() function has thus been removed.

Read more about FormInterface here: http://drupal.org/node/1932058

Drupal 7

<?php
function mymodule_delete_form($form, &$form_state, $id) {
 
$form_state['mymodule_id'] = $id;
  return
confirm_form($form,
   
t('Do you want to delete %id?', array('%id' => $id)),
   
'admin/config/mymodule',
   
t('Only do this if you are sure!'),
   
t('Delete it!'),
   
t('Nevermind')
  );
}
function
mymodule_delete_form_submit($form, &$form_state) {
 
mymodule_delete($form_state['delete']);
}
?>

Drupal 8

<?php
namespace Drupal\mymodule;
use
Drupal\Core\Form\ConfirmFormBase;
/**
* Defines a confirmation form for deleting mymodule data.
*/
class MymoduleDeleteForm extends ConfirmFormBase {
 
/**
   * The ID of the item to delete.
   *
   * @var string
   */
 
protected $id;
 
/**
   * {@inheritdoc}
   */
 
public function getQuestion() {
    return
t('Do you want to delete %id?', array('%id' => $this->id));
  }
 
/**
   * {@inheritdoc}
   */
   
public function getCancelRoute() {
    return array(
     
'route_name' => 'my_module.myroute',
    );
  }
 
/**
   * {@inheritdoc}
   */
   
public function getDescription() {
    return
t('Only do this if you are sure!');
  }
 
/**
   * {@inheritdoc}
   */
   
public function getConfirmText() {
    return
t('Delete it!');
  }
 
/**
   * {@inheritdoc}
   */
   
public function getCancelText() {
    return
t('Nevermind');
  }
 
/**
   * {@inheritdoc}
   *
   * @param int $id
   *   (optional) The ID of the item to be deleted.
   */
 
public function buildForm(array $form, array &$form_state, $id = NULL) {
   
$this->id = $id;
    return
parent::buildForm($form, $form_state);
  }
 
/**
   * {@inheritdoc}
   */
 
public function submitForm(array &$form, array &$form_state) {
   
mymodule_delete($this->id);
  }
}
?>

If you are implementing a confirm form for an entity using _entity_form this is even easier.
Drupal\Core\Entity\EntityConfirmFormBase will store the entity in a property called entity. Which means you only have to do something like this:

<?php
namespace Drupal\mymodule;
use
Drupal\Core\Entity\EntityConfirmFormBase;
class
MyEntityDeleteForm extends EntityConfirmFormBase {
 
/**
   * {@inheritdoc}
   */
 
public function getQuestion() {
    return
t('Are you sure you want to delete myentity %myentity?', array('%myentity' => $this->entity->label()));
  }
 
/**
   * {@inheritdoc}
   */
 
public function getConfirmText() {
    return
t('Delete');
  }
 
/**
   * {@inheritdoc}
   */
 
public function getCancelRoute() {
    return array(
     
'route_name' => 'myentity.admin',
    );
  }
 
/**
   * {@inheritdoc}
   */
 
public function submit(array $form, array &$form_state) {
   
$this->entity->delete();
  }
}
?>
Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done