diff --git a/core/modules/openid/lib/Drupal/openid/Form/UserDeleteForm.php b/core/modules/openid/lib/Drupal/openid/Form/UserDeleteForm.php new file mode 100644 index 0000000000000000000000000000000000000000..233cd4479e7e0c1487579182c060429e42ba7d68 --- /dev/null +++ b/core/modules/openid/lib/Drupal/openid/Form/UserDeleteForm.php @@ -0,0 +1,110 @@ +<?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'; + } + +} diff --git a/core/modules/openid/openid.module b/core/modules/openid/openid.module index ad4da7b87ea037b01b51580d46140914f9850f1c..3d5944805226c353dcfdbe21d6275e11bf3fe5d0 100644 --- a/core/modules/openid/openid.module +++ b/core/modules/openid/openid.module @@ -36,11 +36,7 @@ function openid_menu() { ); $items['user/%user/openid/delete'] = array( 'title' => 'Delete OpenID', - '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', + 'route_name' => 'openid_user_delete_form', ); return $items; } diff --git a/core/modules/openid/openid.pages.inc b/core/modules/openid/openid.pages.inc index 81a59056c7081d4d120aedcc05cdd42c6d6c87fd..df730af12634017cc5edd2a39f344dcc2fd8cbbd 100644 --- a/core/modules/openid/openid.pages.inc +++ b/core/modules/openid/openid.pages.inc @@ -104,26 +104,3 @@ 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'; -} diff --git a/core/modules/openid/openid.routing.yml b/core/modules/openid/openid.routing.yml new file mode 100644 index 0000000000000000000000000000000000000000..a6a34e81b115361e5827495b3b1ec17fa1c47727 --- /dev/null +++ b/core/modules/openid/openid.routing.yml @@ -0,0 +1,9 @@ +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'