class LazyForm in Lazy-load 8
Same name and namespace in other branches
- 8.3 src/Form/LazyForm.php \Drupal\lazy\Form\LazyForm
- 8.2 src/Form/LazyForm.php \Drupal\lazy\Form\LazyForm
Configure Lazy 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\lazy\Form\LazyForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of LazyForm
1 string reference to 'LazyForm'
File
- src/
Form/ LazyForm.php, line 12
Namespace
Drupal\lazy\FormView source
class LazyForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'lazy_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'lazy.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('lazy.settings');
$filter_enabled = lazy_is_enabled();
$description = $this
->t('The inline images and iframes will be lazy-loaded for the selected text-formats');
$desc_extra = $this
->t('The %filter filter must be enabled for at least one <a href=":path">text-format</a>.', [
':path' => Url::fromRoute('filter.admin_overview')
->toString(),
'%filter' => 'Lazy-load',
]);
if (!(bool) $config
->get('alter_tag')['img'] && !(bool) $config
->get('alter_tag')['iframe']) {
$this
->messenger()
->addStatus($this
->t('Lazy-load is currently disabled. Update configuration in global settings to enable it.'), 'warning');
}
$form['settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Global settings'),
'#open' => TRUE,
];
$form['settings']['alter_tag'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Select the inline elements to be lazy-loaded via filter.'),
'#options' => [
'img' => $this
->t('Enable for images (%img tags)', [
'%img' => '<img>',
]),
'iframe' => $this
->t('Enable for iframes (%iframe tags)', [
'%iframe' => '<iframe>',
]),
],
'#default_value' => $config
->get('alter_tag'),
'#description' => $description . ($filter_enabled ? '' : $desc_extra),
'#disabled' => !$filter_enabled,
];
$form['settings']['image_fields'] = [
'#type' => 'checkbox',
'#title' => '<del>' . $this
->t('Enable on image fields attached to fieldable entities. For example, content-types, blocks, paragraphs.') . '</del>',
'#description' => $this
->t('This option is now controlled separately for each image field, in their display settings.'),
'#default_value' => 0,
'#return_value' => TRUE,
'#disabled' => TRUE,
];
$form['settings']['placeholderSrc'] = [
'#type' => 'textfield',
'#title' => $this
->t('Placeholder image URL'),
'#default_value' => $config
->get('placeholderSrc'),
'#maxlength' => 255,
'#required' => TRUE,
];
$form['paths'] = array(
'#type' => 'details',
'#title' => $this
->t('Disabled pages'),
'#description' => $this
->t('Lazy-loading is disabled for both <em>image fields</em> and <em>inline images/iframes</em> on following pages.'),
'#open' => FALSE,
);
$form['paths']['disabled_paths'] = array(
'#type' => 'textarea',
'#title' => t('Pages'),
'#default_value' => $config
->get('disabled_paths'),
'#description' => $this
->t("Specify pages by using their paths. Enter one path per line. The '*' character is a wildcard. An example path is %user-wildcard for every user page. %front is the front page.", [
'%user-wildcard' => '/user/*',
'%front' => '<front>',
]),
);
$form['blazy'] = [
'#type' => 'details',
'#title' => $this
->t('bLazy configuration'),
'#description' => $this
->t('<p><a href=":url">bLazy</a> is a lightweight lazy loading and multi-serving image script created by Bjoern Klinggaard. See its website for usage details and demos.</p>', [
':url' => 'http://dinbror.dk/blog/blazy/',
]),
'#open' => FALSE,
];
$form['blazy']['loadInvisible'] = [
'#type' => 'checkbox',
'#title' => $this
->t('loadInvisible'),
'#description' => $this
->t('If checked loads invisible (hidden) elements.'),
'#default_value' => $config
->get('loadInvisible'),
'#return_value' => TRUE,
];
$form['blazy']['offset'] = [
'#type' => 'number',
'#title' => $this
->t('offset'),
'#description' => $this
->t('The offset controls how early you want the elements to be loaded before they’re visible.'),
'#default_value' => $config
->get('offset'),
'#min' => 0,
'#required' => TRUE,
];
$form['blazy']['saveViewportOffsetDelay'] = [
'#type' => 'number',
'#title' => $this
->t('saveViewportOffsetDelay'),
'#description' => $this
->t('Delay for how often it should call the saveViewportOffset function on resize.'),
'#default_value' => $config
->get('saveViewportOffsetDelay'),
'#min' => 0,
'#required' => TRUE,
];
$form['blazy']['validateDelay'] = [
'#type' => 'number',
'#title' => $this
->t('validateDelay'),
'#description' => $this
->t('Delay for how often it should call the validate function on scroll/resize.'),
'#default_value' => $config
->get('validateDelay'),
'#min' => 0,
'#required' => TRUE,
];
$form['blazy']['selector'] = [
'#type' => 'textfield',
'#title' => $this
->t('Selector class'),
'#description' => $this
->t('Element selector for elements that should lazy load. Do not include a leading period.'),
'#default_value' => $config
->get('selector'),
'#required' => TRUE,
];
$form['blazy']['skipClass'] = [
'#type' => 'textfield',
'#title' => $this
->t('skipClass'),
'#description' => $this
->t('Elements having this class name will be ignored.'),
'#default_value' => $config
->get('skipClass'),
'#required' => TRUE,
];
$form['blazy']['errorClass'] = [
'#type' => 'textfield',
'#title' => $this
->t('errorClass'),
'#description' => $this
->t('The classname an element will get if something goes wrong.'),
'#default_value' => $config
->get('errorClass'),
'#required' => TRUE,
];
$form['blazy']['successClass'] = [
'#type' => 'textfield',
'#title' => $this
->t('successClass'),
'#description' => $this
->t('The classname an element will get when loaded.'),
'#default_value' => $config
->get('successClass'),
'#required' => TRUE,
];
$form['blazy']['src'] = [
'#type' => 'textfield',
'#title' => $this
->t('src'),
'#description' => $this
->t('Attribute where the original element source will be assigned. Do not change this unless attribute is used for other purposes.'),
'#default_value' => $config
->get('src'),
'#required' => TRUE,
];
$form['clear_cache'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Check the box to clear the cache'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this
->config('lazy.settings')
->set('alter_tag', $form_state
->getValue('alter_tag'))
->set('disabled_paths', $form_state
->getValue('disabled_paths'))
->set('errorClass', $form_state
->getValue('errorClass'))
->set('loadInvisible', (bool) $form_state
->getValue('loadInvisible'))
->set('offset', (int) $form_state
->getValue('offset'))
->set('saveViewportOffsetDelay', (int) $form_state
->getValue('saveViewportOffsetDelay'))
->set('selector', $form_state
->getValue('selector'))
->set('skipClass', $form_state
->getValue('skipClass'))
->set('src', $form_state
->getValue('src'))
->set('successClass', $form_state
->getValue('successClass'))
->set('validateDelay', $form_state
->getValue('validateDelay'))
->set('placeholderSrc', $form_state
->getValue('placeholderSrc'))
->save();
parent::submitForm($form, $form_state);
if ($form_state
->getValue('clear_cache')) {
$this
->cacheClear();
}
}
/**
* Clears all caches, then redirects to the previous page.
*/
public function cacheClear() {
drupal_flush_all_caches();
$this
->messenger()
->addMessage('Cache cleared.');
// return $this->redirect('lazy.config_form');
}
}
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 |
LazyForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
LazyForm:: |
public | function | Clears all caches, then redirects to the previous page. | |
LazyForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
LazyForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LazyForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
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. |