Commit 127538ee authored by alexpott's avatar alexpott

Revert "Issue #1946438 by tim.plunkett: Convert confirm_form() in...

Revert "Issue #1946438 by tim.plunkett: Convert confirm_form() in openid.pages.inc to the new form interface."

This reverts commit 08a58426.
parent 9b1c15fa
<?php
/**
* @file
* Contains \Drupal\openid\Form\UserDeleteForm.
*/
namespace Drupal\openid\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\ControllerInterface;
use Drupal\Core\Database\Connection;
use Drupal\user\UserInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides a form to delete a user's Open ID identity.
*/
class UserDeleteForm extends ConfirmFormBase implements ControllerInterface {
/**
* The user account.
*
* @var \Drupal\user\UserInterface
*/
protected $account;
/**
* The account identity ID.
*
* @var int
*/
protected $aid;
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* Constructs a new UserDeleteForm object.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public function __construct(Connection $database) {
$this->database = $database;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static(
$container->get('database')
);
}
/**
* {@inheritdoc}
*/
protected function getQuestion() {
$identifier = $this->database->query("SELECT identifier FROM {openid_identities} WHERE uid = :uid AND aid = :aid", array(
':uid' => $this->account->id(),
':aid' => $this->aid,
))->fetchField();
return t('Are you sure you want to delete the OpenID %identifier for %user?', array('%identifier' => $identifier, '%user' => $this->account->label()));
}
/**
* {@inheritdoc}
*/
protected function getCancelPath() {
return 'user/' . $this->account->id() . '/openid';
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'openid_user_delete_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, array &$form_state, UserInterface $account = NULL, $aid = NULL) {
$this->aid = $aid;
$this->account = $account;
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, array &$form_state) {
$query = $this->database->delete('openid_identities')
->condition('uid', $this->account->id())
->condition('aid', $this->aid)
->execute();
if ($query) {
drupal_set_message(t('OpenID deleted.'));
}
$form_state['redirect'] = 'user/' . $this->account->id() . '/openid';
}
}
......@@ -36,7 +36,11 @@ function openid_menu() {
);
$items['user/%user/openid/delete'] = array(
'title' => 'Delete OpenID',
'route_name' => 'openid_user_delete_form',
'page callback' => 'drupal_get_form',
'page arguments' => array('openid_user_delete_form', 1),
'access callback' => 'entity_page_access',
'access arguments' => array(1, 'update'),
'file' => 'openid.pages.inc',
);
return $items;
}
......
......@@ -104,3 +104,26 @@ function openid_user_add_submit($form, &$form_state) {
$return_to = url('user/' . arg(1) . '/openid', array('absolute' => TRUE));
openid_begin($form_state['values']['openid_identifier'], $return_to);
}
/**
* Menu callback; Delete the specified OpenID identity from the system.
*/
function openid_user_delete_form($form, $form_state, $account, $aid = 0) {
$identifier = db_query("SELECT identifier FROM {openid_identities} WHERE uid = :uid AND aid = :aid", array(
':uid' => $account->uid,
':aid' => $aid,
))
->fetchField();
return confirm_form(array(), t('Are you sure you want to delete the OpenID %identifier for %user?', array('%identifier' => $identifier, '%user' => $account->name)), 'user/' . $account->uid . '/openid');
}
function openid_user_delete_form_submit($form, &$form_state) {
$query = db_delete('openid_identities')
->condition('uid', $form_state['build_info']['args'][0]->uid)
->condition('aid', $form_state['build_info']['args'][1])
->execute();
if ($query) {
drupal_set_message(t('OpenID deleted.'));
}
$form_state['redirect'] = 'user/' . $form_state['build_info']['args'][0]->uid . '/openid';
}
openid_user_delete_form:
pattern: '/user/{account}/openid/delete/{aid}'
options:
converters:
account: 'user'
defaults:
_form: 'Drupal\openid\Form\UserDeleteForm'
requirements:
_entity_access: 'account.update'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment