class Settings in Flickr API Integration 8
Implements the Flickr API Settings form controller.
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\flickr_api\Form\Settings
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of Settings
See also
1 string reference to 'Settings'
File
- src/
Form/ Settings.php, line 18
Namespace
Drupal\flickr_api\FormView source
class Settings extends ConfigFormBase {
/**
* The date formatter service.
*
* @var \Drupal\Core\Datetime\DateFormatterInterface
*/
protected $dateFormatter;
/**
* Settings constructor.
*
* @param \Drupal\flickr_api\Form\ConfigFactoryInterface $config_factory
* Config Factory.
* @param \Drupal\flickr_api\Form\DateFormatterInterface $date_formatter
* Date Formatter.
*/
public function __construct(ConfigFactoryInterface $config_factory, DateFormatterInterface $date_formatter) {
parent::__construct($config_factory);
$this->dateFormatter = $date_formatter;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('date.formatter'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'flickr_api_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'flickr_api.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('flickr_api.settings');
$form['credentials'] = [
'#type' => 'fieldset',
'#title' => $this
->t('OAuth Settings'),
];
$form['credentials']['help'] = [
'#type' => '#markup',
'#markup' => $this
->t('API Key from Flickr. Get an API Key at @link.', [
'@link' => Link::fromTextAndUrl('https://www.flickr.com/services/apps/create/apply', Url::fromUri('https://www.flickr.com/services/apps/create/apply'))
->toString(),
]),
];
$form['credentials']['api_key'] = [
'#type' => 'textfield',
'#title' => $this
->t('API Key'),
'#default_value' => $config
->get('api_key'),
];
$form['credentials']['api_secret'] = [
'#type' => 'textfield',
'#title' => $this
->t('API key secret'),
'#default_value' => $config
->get('api_secret'),
];
$form['flickr_api'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Flickr API Settings'),
'#description' => $this
->t('The following settings connect Flickr API module with external APIs.'),
];
$form['flickr_api']['host_uri'] = [
'#type' => 'textfield',
'#title' => $this
->t('Flickr URL'),
'#default_value' => $config
->get('host_uri'),
];
$form['flickr_api']['api_uri'] = [
'#type' => 'textfield',
'#title' => $this
->t('Flickr API URL'),
'#default_value' => $config
->get('api_uri'),
];
$form['caching'] = [
'#type' => 'details',
'#title' => $this
->t('Flickr API Caching'),
'#open' => TRUE,
'#description' => $this
->t('API caching is recommended for all websites.'),
];
// Identical options to the ones for block caching.
// @see \Drupal\Core\Block\BlockBase::buildConfigurationForm()
$period = [
0,
60,
180,
300,
600,
900,
1800,
2700,
3600,
10800,
21600,
32400,
43200,
86400,
];
$period = array_map([
$this->dateFormatter,
'formatInterval',
], array_combine($period, $period));
$period[0] = '<' . $this
->t('no caching') . '>';
$form['caching']['api_cache_maximum_age'] = [
'#type' => 'select',
'#title' => $this
->t('API cache maximum age'),
'#default_value' => $config
->get('api_cache_maximum_age'),
'#options' => $period,
'#description' => $this
->t('The maximum time a API request can be cached by Drupal.'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('flickr_api.settings')
->set('api_key', $form_state
->getValue('api_key'))
->set('api_secret', $form_state
->getValue('api_secret'))
->set('host_uri', $form_state
->getValue('host_uri'))
->set('api_uri', $form_state
->getValue('api_uri'))
->set('api_cache_maximum_age', $form_state
->getValue('api_cache_maximum_age'))
->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 | |
FormBase:: |
protected | property | The config factory. | 1 |
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. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
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. | |
Settings:: |
protected | property | The date formatter service. | |
Settings:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
Settings:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
Settings:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
Settings:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
Settings:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
Settings:: |
public | function |
Settings constructor. Overrides ConfigFormBase:: |
|
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. |