class FacebookAlbumForm in Facebook Album 8
Configure facebook_album settings for this site.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\facebook_album\Form\FacebookAlbumForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of FacebookAlbumForm
1 string reference to 'FacebookAlbumForm'
File
- src/
Form/ FacebookAlbumForm.php, line 19 - Contains \Drupal\facebook_album\Form\FacebookAlbumForm.
Namespace
Drupal\facebook_album\FormView source
class FacebookAlbumForm extends ConfigFormBase {
/**
* The Drupal configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The FB Album controller.
*
* @var FacebookAlbumInterface
*/
protected $facebook_album;
/**
* {@inheritdoc}
*
* @param FacebookAlbumInterface $facebook_album
* The controls of facebook album.
*/
public function __construct(ConfigFactoryInterface $config_factory, FacebookAlbumInterface $facebook_album) {
parent::__construct($config_factory);
$this->configFactory = $config_factory;
$this->facebook_album = $facebook_album;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('facebook_album.controller'));
}
/**
* {@inheritdoc}
*/
public function getFormID() {
return 'facebook_album_config_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'facebook_album.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
// Get module configuration.
$config = $this
->config('facebook_album.settings')
->get();
// @TODO: Style this, add more detail
if (!empty($config['access_token'])) {
$form['notice'] = [
'#markup' => $this
->t('You already have configured your application.'),
];
}
$form['app_id'] = [
'#type' => 'textfield',
'#title' => $this
->t('Facebook App ID'),
'#default_value' => $config['app_id'],
'#required' => TRUE,
'#description' => $this
->t('The application ID specified in your Facebook App\'s dashboard page.'),
];
$form['app_secret'] = [
'#type' => 'password',
'#title' => $this
->t('Facebook App Secret'),
'#default_value' => $config['app_secret'],
'#required' => TRUE,
'#description' => $this
->t('The application secret specified in your Facebook App\'s dashboard page. This field remains blank for security purposes. If you have already saved your application secret, leave this field blank, unless you wish to update it.'),
];
return parent::buildForm($form, $form_state);
}
/**
* Call Facebook and get an access token for the given app
*
* @param array $form
* @param \Drupal\Core\Form\FormStateInterface $form_state
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$app_id = $form_state
->getValue('app_id');
$app_secret = $form_state
->getValue('app_secret');
$auth_path = FACEBOOK_ALBUM_API_AUTH_PATH . 'access_token';
$parameters = [
'client_id' => $app_id,
'client_secret' => $app_secret,
'grant_type' => 'client_credentials',
];
$response = $this->facebook_album
->get($auth_path, $parameters);
if (isset($response['error'])) {
$message = $this->facebook_album
->translate_error($response['error']['code'], $response['error']['message']);
$form_state
->setErrorByName('app_secret', $message);
}
else {
$form_state
->setValue('access_token', $response['access_token']);
}
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$page_id = $form_state
->getValue('page_id');
$app_id = $form_state
->getValue('app_id');
$app_secret = $form_state
->getValue('app_secret');
$access_token = $form_state
->getValue('access_token');
// Get module configuration.
$this
->config('facebook_album.settings')
->set('page_id', $page_id)
->set('app_id', $app_id)
->set('app_secret', $app_secret)
->set('access_token', $access_token)
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FacebookAlbumForm:: |
protected | property |
The Drupal configuration factory. Overrides FormBase:: |
|
FacebookAlbumForm:: |
protected | property | The FB Album controller. | |
FacebookAlbumForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
FacebookAlbumForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
FacebookAlbumForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
FacebookAlbumForm:: |
public | function | ||
FacebookAlbumForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
FacebookAlbumForm:: |
public | function |
Call Facebook and get an access token for the given app Overrides FormBase:: |
|
FacebookAlbumForm:: |
public | function |
Overrides ConfigFormBase:: |
|
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
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. Overrides UrlGeneratorTrait:: |
|
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. | |
FormInterface:: |
public | function | Returns a unique string identifying the form. | 236 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
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. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
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. | 1 |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |