class AdminForm in Evercurrent 8
Same name and namespace in other branches
- 8.2 src/Form/AdminForm.php \Drupal\evercurrent\Form\AdminForm
Class AdminForm.
@package Drupal\evercurrent\Form
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\evercurrent\Form\AdminForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of AdminForm
1 string reference to 'AdminForm'
File
- src/
Form/ AdminForm.php, line 20 - Contains Drupal\evercurrent\Form\AdminForm.
Namespace
Drupal\evercurrent\FormView source
class AdminForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'evercurrent.admin_config',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'admin_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('evercurrent.admin_config');
$form['send'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enable sending update reports'),
'#description' => $this
->t('Check this to enable sending information about available updates to the Ricochet Maintenance server.'),
'#default_value' => $config
->get('send'),
'#weight' => 1,
];
$form['target_address'] = [
'#type' => 'textfield',
'#title' => $this
->t('Server URL'),
'#description' => $this
->t('The target environment URL'),
'#maxlength' => 300,
'#size' => 40,
'#default_value' => $config
->get('target_address'),
'#weight' => 2,
];
$form['key'] = [
'#type' => 'textfield',
'#title' => $this
->t('API Key'),
'#description' => $this
->t('The API key for this site. It should contain only lower case letters and numbers.
If you have development and staging environments,
you should not store the API key in this field, but in your production environment\'s settings.php as follows:
<i>$settings["evercurrent_environment_token"] = "myapikey";</i>
This is important if you are using different environments. See this module\'s documentation for more information.'),
'#maxlength' => 32,
'#size' => 32,
'#default_value' => $config
->get('key'),
'#weight' => 4,
];
$form['details'] = [
'#type' => 'details',
'#title' => $this
->t('Advanced'),
'#open' => FALSE,
'#weight' => 5,
];
$form['details']['listen'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Listen for new API key'),
'#description' => $this
->t('If set, the module will listen for an API key sent from the Maintenance server. Once it has received an API key, it will immediately attempt to send updates to the maintenance server using this API key. If this update succeeds, the API key will be saved. When it is saved, the listening will be automatically stopped.'),
'#default_value' => $config
->get('listen'),
];
$form['details']['interval'] = [
'#type' => 'select',
'#title' => t('Report frequency'),
'#description' => t('The frequency for sending updates to the server. Use this if your cron runs very often.'),
'#default_value' => $config
->get('interval'),
'#options' => [
0 => t('Every time Cron runs'),
3600 => t('Every hour'),
3600 * 12 => t('Every 12 hours'),
60 * 60 * 24 => t('Every 24 hours'),
],
];
$settings_token = Settings::get('evercurrent_environment_token', NULL);
if ($settings_token) {
$form['override'] = array(
'#type' => 'checkbox',
'#title' => $this
->t('Override API key stored in settings.php'),
'#description' => $this
->t("An API key '<b>%key</b>' has been detected in your site's settings.php file.\nIf you want to override that key, check this box. The API key in the 'API key' field below will then be used instead.", array(
'%key' => $settings_token,
)),
'#default_value' => $config
->get('override'),
'#weight' => 3,
);
$form['key']['#states'] = array(
'disabled' => array(
':input[name="override"]' => array(
'checked' => FALSE,
),
),
);
}
$form['send_now'] = array(
'#type' => 'checkbox',
'#title' => t('Send update report when saving configuration'),
'#description' => t('Check this to attempt sending updates to the server immediately after you have saved this form.'),
'#weight' => 10,
);
return parent::buildForm($form, $form_state);
}
/**
* {@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);
$this
->config('evercurrent.admin_config')
->set('send', $form_state
->getValue('send'))
->set('listen', $form_state
->getValue('listen'))
->set('target_address', $form_state
->getValue('target_address'))
->set('key', $form_state
->getValue('key'))
->set('interval', $form_state
->getValue('interval'))
->set('override', $form_state
->getValue('override'))
->save();
if ($form_state
->getValue('send_now') == TRUE) {
drupal_set_message('Attempting to contact server..');
$updateHelper = \Drupal::service('evercurrent.update_helper');
$result = $updateHelper
->sendUpdates(TRUE, NULL, TRUE);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AdminForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
AdminForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
AdminForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AdminForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
AdminForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
ConfigFormBase:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
13 |
ConfigFormBase:: |
public | function | Constructs a \Drupal\system\ConfigFormBase object. | 11 |
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. | |
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. |