OAuthDeleteConsumerForm.php in OAuth 1.0 8
File
src/Form/OAuthDeleteConsumerForm.php
View source
<?php
namespace Drupal\oauth\Form;
use Drupal\Core\Database\Connection;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Symfony\Component\DependencyInjection\ContainerInterface;
class OAuthDeleteConsumerForm extends ConfirmFormBase implements ContainerInjectionInterface {
const NAME = 'oauth_delete_consumer_form';
public static function create(ContainerInterface $container) {
$database = $container
->get('database');
return new static($database);
}
public function __construct(Connection $connection) {
$this->connection = $connection;
}
public function getFormID() {
return static::NAME;
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete this OAuth consumer?');
}
public function getDescription() {
return $this
->t('This action cannot be undone.');
}
public function getCancelUrl() {
return new Url('oauth.user_consumer', [
'user' => \Drupal::currentUser()
->id(),
]);
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function getCancelText() {
return $this
->t('Cancel');
}
public function getFormName() {
return static::NAME;
}
public function buildForm(array $form, FormStateInterface $form_state, $cid = NULL) {
$form['cid'] = array(
'#type' => 'hidden',
'#value' => $cid,
);
$form = parent::buildForm($form, $form_state);
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$values = $form_state
->getValues();
$cid = $values['cid'];
$this->connection
->delete('oauth_consumer')
->condition('cid', $cid)
->execute();
drupal_set_message($this
->t('OAuth consumer deleted.'));
$form_state
->setRedirect('oauth.user_consumer', [
'user' => \Drupal::currentUser()
->id(),
]);
}
}