class ResourceHintsConfigForm in Resource Hints 8
Configure resource hints 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\resource_hints\Form\ResourceHintsConfigForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of ResourceHintsConfigForm
1 file declares its use of ResourceHintsConfigForm
- resource_hints.module in ./
resource_hints.module - Module hooks for the resource hints module.
1 string reference to 'ResourceHintsConfigForm'
File
- src/
Form/ ResourceHintsConfigForm.php, line 11
Namespace
Drupal\resource_hints\FormView source
class ResourceHintsConfigForm extends ConfigFormBase {
const OUTPUT_LINK_HEADER = 0;
const OUTPUT_LINK_ELEMENT = 1;
const DNS_PREFETCH_ENABLED = 'on';
const DNS_PREFETCH_DISABLED = 'off';
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'resource_hints_admin_config';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'resource_hints.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('resource_hints.settings');
$form['dns_prefetch'] = [
'#type' => 'details',
'#title' => $this
->t('DNS Prefetch'),
'#open' => TRUE,
];
$form['dns_prefetch']['dns_prefetch_output'] = [
'#type' => 'select',
'#title' => $this
->t('Output type'),
'#options' => [
self::OUTPUT_LINK_HEADER => $this
->t('Link Header'),
self::OUTPUT_LINK_ELEMENT => $this
->t('Link Element'),
],
'#default_value' => $config
->get('dns_prefetch_output'),
'#description' => $this
->t('Resource hints can be output as an HTTP Link header or HTML link element'),
];
$form['dns_prefetch']['dns_prefetch_resources'] = [
'#type' => 'textarea',
'#default_value' => implode(PHP_EOL, $config
->get('dns_prefetch_resources')),
'#title' => $this
->t('Resources'),
'#description' => $this
->t('The DNS resources you wish to be prefetched. Enter one resource per line.'),
];
$form['dns_prefetch']['dns_prefetch_control'] = [
'#type' => 'select',
'#title' => $this
->t('DNS Prefetch Control'),
'#options' => [
self::DNS_PREFETCH_ENABLED => $this
->t('Enabled'),
self::DNS_PREFETCH_DISABLED => $this
->t('Disabled'),
],
'#default_value' => $config
->get('dns_prefetch_control'),
'#description' => $this
->t('By default browsers will not use DNS prefetching when a page is served via HTTPS, you must explicitly enable prefetching for HTTPS. Disabling prefetching will prevent browsers using prefetching and any inline attempts to enable it will be ignored.'),
];
$form['preconnect'] = [
'#type' => 'details',
'#title' => $this
->t('Preconnect'),
'#open' => TRUE,
];
$form['preconnect']['preconnect_output'] = [
'#type' => 'select',
'#title' => $this
->t('Output type'),
'#options' => [
self::OUTPUT_LINK_HEADER => $this
->t('Link Header'),
self::OUTPUT_LINK_ELEMENT => $this
->t('Link Element'),
],
'#default_value' => $config
->get('preconnect_output'),
'#description' => $this
->t('Resource hints can be output as an HTTP Link header or HTML link element'),
];
$form['preconnect']['preconnect_resources'] = [
'#type' => 'textarea',
'#default_value' => implode(PHP_EOL, $config
->get('preconnect_resources')),
'#title' => $this
->t('Resources'),
'#description' => $this
->t('The resources you wish to be preconnected. Enter one resource per line.'),
];
$form['prefetch'] = [
'#type' => 'details',
'#title' => $this
->t('Prefetch'),
'#open' => TRUE,
];
$form['prefetch']['prefetch_output'] = [
'#type' => 'select',
'#title' => $this
->t('Output type'),
'#options' => [
self::OUTPUT_LINK_HEADER => $this
->t('Link Header'),
self::OUTPUT_LINK_ELEMENT => $this
->t('Link Element'),
],
'#default_value' => $config
->get('prefetch_output'),
'#description' => $this
->t('Resource hints can be output as an HTTP Link header or HTML link element'),
];
$form['prefetch']['prefetch_resources'] = [
'#type' => 'textarea',
'#default_value' => implode(PHP_EOL, $config
->get('prefetch_resources')),
'#title' => $this
->t('Resources'),
'#description' => $this
->t('The resources you wish to be prefetched. Enter one resource per line.'),
];
$form['prerender'] = [
'#type' => 'details',
'#title' => $this
->t('Prerender'),
'#open' => TRUE,
];
$form['prerender']['prerender_output'] = [
'#type' => 'select',
'#title' => $this
->t('Output type'),
'#options' => [
self::OUTPUT_LINK_HEADER => $this
->t('Link Header'),
self::OUTPUT_LINK_ELEMENT => $this
->t('Link Element'),
],
'#default_value' => $config
->get('prerender_output'),
'#description' => $this
->t('Resource hints can be output as an HTTP Link header or HTML link element'),
];
$form['prerender']['prerender_resources'] = [
'#type' => 'textarea',
'#default_value' => implode(PHP_EOL, $config
->get('prerender_resources')),
'#title' => $this
->t('Resources'),
'#description' => $this
->t('The resources you wish to be prerendered. Enter one resource per line.'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$dns_prefetch_resources = explode(PHP_EOL, $form_state
->getValue('dns_prefetch_resources'));
$preconnect_resources = explode(PHP_EOL, $form_state
->getValue('preconnect_resources'));
$prefetch_resources = explode(PHP_EOL, $form_state
->getValue('prefetch_resources'));
$prerender_resources = explode(PHP_EOL, $form_state
->getValue('prerender_resources'));
$config = \Drupal::service('config.factory')
->getEditable('resource_hints.settings');
$config
->set('dns_prefetch_resources', $dns_prefetch_resources)
->set('dns_prefetch_output', $form_state
->getValue('dns_prefetch_output'))
->set('dns_prefetch_control', $form_state
->getValue('dns_prefetch_control'))
->set('preconnect_resources', $preconnect_resources)
->set('preconnect_output', $form_state
->getValue('preconnect_output'))
->set('prefetch_resources', $prefetch_resources)
->set('prefetch_output', $form_state
->getValue('prefetch_output'))
->set('prerender_resources', $prerender_resources)
->set('prerender_output', $form_state
->getValue('prerender_output'))
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
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. | |
ResourceHintsConfigForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
ResourceHintsConfigForm:: |
constant | |||
ResourceHintsConfigForm:: |
constant | |||
ResourceHintsConfigForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
ResourceHintsConfigForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
ResourceHintsConfigForm:: |
constant | |||
ResourceHintsConfigForm:: |
constant | |||
ResourceHintsConfigForm:: |
public | function |
Form submission handler. 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. |