class AutofloatSettingsForm in AutoFloat 8
Class AutofloatSettingsForm.
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\autofloat\Form\AutofloatSettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of AutofloatSettingsForm
1 string reference to 'AutofloatSettingsForm'
File
- src/
Form/ AutofloatSettingsForm.php, line 11
Namespace
Drupal\autofloat\FormView source
class AutofloatSettingsForm extends ConfigFormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'autofloat_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'autofloat.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->configFactory
->get('autofloat.settings');
$form['autofloat_start'] = [
'#type' => 'radios',
'#title' => $this
->t('Start with the first image on the..'),
'#options' => [
0 => $this
->t('right'),
1 => $this
->t('left (swaps "odd" and "even" classes)'),
],
'#default_value' => $config
->get('start'),
'#description' => $this
->t('Clear the site cache to apply changes.'),
];
$form['autofloat_css'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Use autofloat.css'),
'#default_value' => $config
->get('css'),
'#description' => $this
->t('Uncheck to take care of the floating and margins yourself in custom css.'),
];
$form['target_settings'] = [
'#type' => 'fieldset',
'#title' => $this
->t('Selector/rejector settings'),
'#description' => $this
->t('Images will float unless they have the class "nofloat". Clear the site cache to apply changes. Avoid adding classes manually by defining classes here added by other modules/filters. Use your browser inspector to find them.'),
];
$form['target_settings']['autofloat_target'] = [
'#type' => 'radios',
'#title' => $this
->t('Elements to target'),
'#options' => [
'div' => $this
->t('div'),
'span' => $this
->t('span'),
],
'#default_value' => $config
->get('target'),
'#description' => $this
->t('Clear the site cache to apply changes.'),
];
$form['target_settings']['autofloat_selector'] = [
'#type' => 'textfield',
'#title' => $this
->t('Additional selector classes to float'),
'#default_value' => $config
->get('selector'),
'#description' => $this
->t('A "selector" with the class "float" will float all containing content, e.g. the image with a caption under it. Optionally define others. Maximum two, divided by a comma. Example: "caption".'),
];
$form['target_settings']['autofloat_rejector'] = [
'#type' => 'textfield',
'#title' => $this
->t('Additional div classes to ignore'),
'#default_value' => $config
->get('rejector'),
'#description' => $this
->t('Images nested within any element with the class "nofloat" will NOT float, e.g. a set of thumbnails. Optionally define others. Maximum two, divided by a comma. Example: "flickr-photoset".'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
// Accept maximum two class value for the selector field.
$limit = $form_state
->getValue('autofloat_selector');
if (substr_count($limit, ',') > 1) {
$form_state
->setErrorByName('autofloat_selector', $this
->t('Not more than two values.'));
}
// Accept maximum two class value for the rejector field.
$limit = $form_state
->getValue('autofloat_rejector');
if (substr_count($limit, ',') > 1) {
$form_state
->setErrorByName('autofloat_rejector', $this
->t('Not more than two values.'));
}
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this->configFactory
->getEditable('autofloat.settings');
$config
->set('start', $form_state
->getValue('autofloat_start'))
->set('css', $form_state
->getValue('autofloat_css'))
->set('target', $form_state
->getValue('autofloat_target'))
->set('selector', $form_state
->getValue('autofloat_selector'))
->set('rejector', $form_state
->getValue('autofloat_rejector'));
$config
->save();
drupal_flush_all_caches();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AutofloatSettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
AutofloatSettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
AutofloatSettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
AutofloatSettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
AutofloatSettingsForm:: |
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. |