TwitterAccountsDeleteForm.php in Tweet Feed 8.3
File
src/Form/TwitterAccountsDeleteForm.php
View source
<?php
namespace Drupal\tweet_feed\Form;
use Drupal\Core\Form\ConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
class TwitterAccountsDeleteForm extends ConfirmFormBase {
protected $account_machine_name;
public function buildForm(array $form, FormStateInterface $form_state, string $account_machine_name = NULL) {
$this->account_machine_name = $account_machine_name;
$form = parent::buildForm($form, $form_state);
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = \Drupal::service('config.factory')
->getEditable('tweet_feed.twitter_accounts');
$accounts = $config
->get('accounts');
unset($accounts[$this->account_machine_name]);
$config
->set('accounts', $accounts)
->save();
drupal_set_message($this
->t('The Twitter API account %account was deleted.', [
'%account' => $this->account_machine_name,
]));
$form_state
->setRedirect('tweet_feed.twitter_accounts');
return;
}
public function getFormId() : string {
return "tweet_feed_twitter_accounts_confirm_delete";
}
public function getCancelUrl() {
return new Url('tweet_feed.twitter_accounts');
}
public function getQuestion() {
return t('Do you want to delete %account_machine_name?', [
'%account_machine_name' => $this->account_machine_name,
]);
}
}