class BlazySettingsForm in Blazy 8
Same name and namespace in other branches
- 8.2 blazy_ui/src/Form/BlazySettingsForm.php \Drupal\blazy_ui\Form\BlazySettingsForm
- 7 modules/blazy_ui/src/Form/BlazySettingsForm.php \Drupal\blazy_ui\Form\BlazySettingsForm
Defines blazy admin settings 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\blazy_ui\Form\BlazySettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of BlazySettingsForm
1 file declares its use of BlazySettingsForm
- BlazySettingsFormTest.php in tests/
src/ Kernel/ Form/ BlazySettingsFormTest.php
1 string reference to 'BlazySettingsForm'
- blazy_ui.routing.yml in blazy_ui/
blazy_ui.routing.yml - blazy_ui/blazy_ui.routing.yml
File
- blazy_ui/
src/ Form/ BlazySettingsForm.php, line 12
Namespace
Drupal\blazy_ui\FormView source
class BlazySettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'blazy_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'blazy.settings',
];
}
/**
* Implements \Drupal\Core\Form\FormInterface::buildForm().
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('blazy.settings');
$form['admin_css'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Admin CSS'),
'#default_value' => $config
->get('admin_css'),
'#description' => $this
->t('Uncheck to disable blazy related admin compact form styling, only if not compatible with your admin theme.'),
];
$form['responsive_image'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Support Responsive image'),
'#default_value' => $config
->get('responsive_image'),
'#description' => $this
->t('Check to support lazyloading for the core Responsive image module. Be sure to use Blazy formatter to have relevant styling.'),
];
$form['one_pixel'] = [
'#type' => 'checkbox',
'#title' => $this
->t('One pixel placeholder'),
'#default_value' => $config
->get('one_pixel'),
'#description' => $this
->t('By default a one pixel image is the placeholder for lazyloaded Responsive image. Useful to perform a lot better. Uncheck to disable, and use Drupal-managed smallest/fallback image style instead. Be sure to add proper dimensions or at least min-height/min-width via CSS accordingly to avoid layout reflow since Aspect ratio is not supported with Responsive image yet. Disabling this will result in downloading fallback image as well for non-PICTURE element (double downloads).'),
];
$form['blazy'] = [
'#type' => 'container',
'#tree' => TRUE,
'#title' => $this
->t('Blazy JS settings'),
'#description' => $this
->t('The following are JS related settings.'),
];
$form['blazy']['loadInvisible'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Load invisible'),
'#default_value' => $config
->get('blazy.loadInvisible'),
'#description' => $this
->t('Set to true if you want to load invisible (hidden) elements.'),
];
$form['blazy']['offset'] = [
'#type' => 'textfield',
'#title' => $this
->t('Offset'),
'#default_value' => $config
->get('blazy.offset'),
'#description' => $this
->t("The offset controls how early you want the elements to be loaded before they're visible. Default is <strong>100</strong>, so 100px before an element is visible it'll start loading."),
'#field_suffix' => 'px',
'#maxlength' => 5,
'#size' => 10,
];
$form['blazy']['saveViewportOffsetDelay'] = [
'#type' => 'textfield',
'#title' => $this
->t('Save viewport offset delay'),
'#default_value' => $config
->get('blazy.saveViewportOffsetDelay'),
'#description' => $this
->t('Delay for how often it should call the saveViewportOffset function on resize. Default is <strong>50</strong>ms.'),
'#field_suffix' => 'ms',
'#maxlength' => 5,
'#size' => 10,
];
$form['blazy']['validateDelay'] = [
'#type' => 'textfield',
'#title' => $this
->t('Set validate delay'),
'#default_value' => $config
->get('blazy.validateDelay'),
'#description' => $this
->t('Delay for how often it should call the validate function on scroll/resize. Default is <strong>25</strong>ms.'),
'#field_suffix' => 'ms',
'#maxlength' => 5,
'#size' => 10,
];
$form['blazy']['container'] = [
'#type' => 'textfield',
'#title' => $this
->t('Scrolling container'),
'#default_value' => $config
->get('blazy.container'),
'#description' => $this
->t('If you put Blazy within a scrolling container, provide valid comma separated CSS selectors, e.g.: <code>#drupal-modal, .another-scrolling-container</code>. A known scrolling container is <code>#drupal-modal</code> like seen at Media library. A scrolling modal with an iframe like Entity Browser has no issue since the scrolling container is the entire DOM. Must know <code>.blazy</code> parent container which has CSS rules containing <code>overflow</code> with values anything but <code>hidden</code> such as <code>auto or scroll</code>. Press F12 at any browser to inspect elements'),
];
return parent::buildForm($form, $form_state);
}
/**
* Implements \Drupal\Core\Form\FormInterface::submitForm().
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configFactory
->getEditable('blazy.settings')
->set('admin_css', $form_state
->getValue('admin_css'))
->set('responsive_image', $form_state
->getValue('responsive_image'))
->set('one_pixel', $form_state
->getValue('one_pixel'))
->set('blazy.loadInvisible', $form_state
->getValue([
'blazy',
'loadInvisible',
]))
->set('blazy.offset', $form_state
->getValue([
'blazy',
'offset',
]))
->set('blazy.saveViewportOffsetDelay', $form_state
->getValue([
'blazy',
'saveViewportOffsetDelay',
]))
->set('blazy.validateDelay', $form_state
->getValue([
'blazy',
'validateDelay',
]))
->set('blazy.container', $form_state
->getValue([
'blazy',
'container',
]))
->save();
// Invalidate the library discovery cache to update the responsive image.
\Drupal::service('library.discovery')
->clearCachedDefinitions();
$this
->messenger()
->addMessage($this
->t('Be sure to <a href=":clear_cache">clear the cache</a> if trouble to see the updated settings', [
':clear_cache' => Url::fromRoute('system.performance_settings')
->toString(),
]));
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlazySettingsForm:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::buildForm(). Overrides ConfigFormBase:: |
|
BlazySettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
BlazySettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
BlazySettingsForm:: |
public | function |
Implements \Drupal\Core\Form\FormInterface::submitForm(). Overrides ConfigFormBase:: |
|
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. | |
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. |