class TwitterAccountsForm in Tweet Feed 4.x
Same name and namespace in other branches
- 8.3 src/Form/TwitterAccountsForm.php \Drupal\tweet_feed\Form\TwitterAccountsForm
Form controller for Tweet entity edit forms.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\tweet_feed\Form\TwitterAccountsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of TwitterAccountsForm
1 string reference to 'TwitterAccountsForm'
File
- src/
Form/ TwitterAccountsForm.php, line 14
Namespace
Drupal\tweet_feed\FormView source
class TwitterAccountsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'tweet_feed.twitter_accounts',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'tweet_feed_twitter_accounts';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state, $account_machine_name = NULL) {
$config = $this
->config('tweet_feed.twitter_accounts');
// Set up our settings form for this particular account (new or update)
if (!empty($account_machine_name)) {
$accounts = $config
->get('accounts');
$account = $accounts[$account_machine_name];
$form['account_machine_name'] = [
'#type' => 'hidden',
'#value' => $account_machine_name,
];
$form['account_update'] = [
'#type' => 'hidden',
'#value' => 1,
];
$account_name = $account['account_name'];
$consumer_key = $account['consumer_key'];
$consumer_secret = $account['consumer_secret'];
$oauth_token = $account['oauth_token'];
$oauth_token_secret = $account['oauth_token_secret'];
$account_name_disabled = TRUE;
}
else {
$account_name = $consumer_key = $oauth_token = NULL;
$consumer_secret = $oauth_token_secret = NULL;
$account_name_disabled = FALSE;
}
$form['tweet_feed_account'] = array(
'#type' => 'fieldset',
'#title' => t('Tweet Feed Twitter API Account Information Form'),
'#description' => t('Provide information about the Twitter API account you wish to add. These can be used to get the feeds for any of our configurable options.'),
);
$form['tweet_feed_account']['account_name'] = array(
'#type' => 'textfield',
'#title' => t('Account Name'),
'#max_length' => 128,
'#disabled' => $account_name_disabled,
'#required' => TRUE,
'#default_value' => $account_name,
);
$form['tweet_feed_account']['consumer_key'] = array(
'#type' => 'textfield',
'#title' => t('Consumer Key'),
'#max_length' => 255,
'#required' => TRUE,
'#default_value' => $consumer_key,
);
$form['tweet_feed_account']['consumer_secret'] = array(
'#type' => 'textfield',
'#title' => t('Consumer Secret'),
'#max_length' => 255,
'#required' => TRUE,
'#default_value' => $consumer_secret,
);
$form['tweet_feed_account']['oauth_token'] = array(
'#type' => 'textfield',
'#title' => t('Oauth Token'),
'#max_length' => 255,
'#required' => TRUE,
'#default_value' => $oauth_token,
);
$form['tweet_feed_account']['oauth_token_secret'] = array(
'#type' => 'textfield',
'#title' => t('Oauth Token Secret'),
'#max_length' => 255,
'#required' => TRUE,
'#default_value' => $oauth_token_secret,
);
$form = parent::buildForm($form, $form_state);
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
$config = $this
->config('tweet_feed.twitter_accounts');
$accounts = $config
->get('accounts');
$values = $form_state
->getValues();
// If we're updating, then do things differently
if (empty($values['account_update'])) {
$account_machine_name = preg_replace('/[^a-z0-9]+/', '_', strtolower($values['account_name']));
if (!empty($accounts[$account_machine_name])) {
$suffix = 1;
do {
$new_account_machine_name = $account_machine_name . '_' . $suffix;
$suffix++;
} while (!empty($accounts[$new_account_machine_name]));
$account_machine_name = $new_account_machine_name;
}
if (empty($accounts[$account_machine_name])) {
$accounts[$account_machine_name] = [];
}
else {
$account_machine_name = $values['account_machine_name'];
}
}
else {
$account_machine_name = $values['account_machine_name'];
}
$accounts[$account_machine_name]['account_name'] = $values['account_name'];
$accounts[$account_machine_name]['consumer_key'] = $values['consumer_key'];
$accounts[$account_machine_name]['consumer_secret'] = $values['consumer_secret'];
$accounts[$account_machine_name]['oauth_token'] = $values['oauth_token'];
$accounts[$account_machine_name]['oauth_token_secret'] = $values['oauth_token_secret'];
$this
->config('tweet_feed.twitter_accounts')
->set('accounts', $accounts)
->save();
$url = Url::fromRoute('tweet_feed.twitter_accounts');
$form_state
->setRedirectUrl($url);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
18 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 16 |
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function | Returns a redirect response object for the specified route. | |
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
TwitterAccountsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
TwitterAccountsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
TwitterAccountsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
TwitterAccountsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
TwitterAccountsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |