class SettingsForm in bootstrap simple carousel 8
Class SettingsForm.
Provides a settings form.
@package Drupal\bootstrap_simple_carousel\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\bootstrap_simple_carousel\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
2 files declare their use of SettingsForm
- bootstrap_simple_carousel.install in ./
bootstrap_simple_carousel.install - Defines install of bootstrap simple carousel.
- CarouselBlock.php in src/
Plugin/ Block/ CarouselBlock.php
1 string reference to 'SettingsForm'
File
- src/
Form/ SettingsForm.php, line 18
Namespace
Drupal\bootstrap_simple_carousel\FormView source
class SettingsForm extends ConfigFormBase {
const ORIGINAL_IMAGE_STYLE_ID = 'original';
const DEFAULT_IMAGE_TYPE_ID = 'img-default';
const FLUID_IMAGE_TYPE_ID = 'img-fluid';
const CIRCLE_IMAGE_TYPE_ID = 'img-circle';
/**
* Image style service.
*
* @var \Drupal\image\ImageStyleInterface
*/
protected $imageStyleService;
/**
* SettingsForm constructor.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* Config factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
$this->imageStyleService = $entity_type_manager
->getStorage('image_style');
parent::__construct($config_factory);
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'bootstrap_simple_carousel_admin_settings_form';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'bootstrap_simple_carousel.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('bootstrap_simple_carousel.settings');
$form['interval'] = [
'#type' => 'textfield',
'#title' => $this
->t('Interval'),
'#description' => $this
->t('The amount of time to delay between automatically cycling an item. If false, carousel will not automatically cycle.'),
'#default_value' => $config
->get('interval'),
];
$form['wrap'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Wrap'),
'#description' => $this
->t('Whether the carousel should cycle continuously or have hard stops.'),
'#default_value' => $config
->get('wrap'),
];
$form['pause'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Pause on hover'),
'#description' => $this
->t("If is checked, pauses the cycling of the carousel on mouseenter and resumes the cycling of the carousel on mouseleave. If is unchecked, hovering over the carousel won't pause it."),
'#default_value' => $config
->get('pause'),
];
$form['indicators'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Indicators'),
'#description' => $this
->t('Show carousel indicators'),
'#default_value' => $config
->get('indicators'),
];
$form['controls'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Controls'),
'#description' => $this
->t('Show carousel arrows (next/prev).'),
'#default_value' => $config
->get('controls'),
];
$form['assets'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Assets'),
'#description' => $this
->t("Includes bootstrap framework v4.0.0, don't check it, if you use the bootstrap theme, or the bootstrap framework are already included."),
'#default_value' => $config
->get('assets'),
];
$form['image_type'] = [
'#type' => 'select',
'#title' => $this
->t('Bootstrap image type'),
'#description' => $this
->t('Bootstrap image type for carousel items.'),
'#options' => $this
->getImagesTypes(),
'#default_value' => $config
->get('image_type'),
];
$form['image_style'] = [
'#type' => 'select',
'#title' => $this
->t('Image style'),
'#description' => $this
->t('Image style for carousel items. If you will be use the image styles for bootstrap items, you need to set up the same width for the "bootstrap carousel" container.'),
'#options' => $this
->getImagesStyles(),
'#default_value' => $config
->get('image_style'),
];
return parent::buildForm($form, $form_state);
}
/**
* Return images styles.
*
* @return array
* List of image styles
*/
protected function getImagesStyles() {
$styles = $this->imageStyleService
->loadMultiple();
$options = [
static::ORIGINAL_IMAGE_STYLE_ID => $this
->t('Original image'),
];
foreach ($styles as $key => $value) {
$options[$key] = $value
->get('label');
}
return $options;
}
/**
* Return bootstrap images types.
*
* @return array
* Image types list
*/
protected function getImagesTypes() {
$options = [
static::DEFAULT_IMAGE_TYPE_ID => $this
->t('Image none'),
static::FLUID_IMAGE_TYPE_ID => $this
->t('Image fluid'),
static::CIRCLE_IMAGE_TYPE_ID => $this
->t('Image circle'),
];
return $options;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->configFactory
->getEditable('bootstrap_simple_carousel.settings')
->set('interval', $form_state
->getValue('interval'))
->set('wrap', $form_state
->getValue('wrap'))
->set('pause', $form_state
->getValue('pause'))
->set('indicators', $form_state
->getValue('indicators'))
->set('controls', $form_state
->getValue('controls'))
->set('assets', $form_state
->getValue('assets'))
->set('image_type', $form_state
->getValue('image_type'))
->set('image_style', $form_state
->getValue('image_style'))
->save();
parent::submitForm($form, $form_state);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
SettingsForm:: |
protected | property | Image style service. | |
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
constant | |||
SettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
SettingsForm:: |
constant | |||
SettingsForm:: |
constant | |||
SettingsForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
SettingsForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
SettingsForm:: |
protected | function | Return images styles. | |
SettingsForm:: |
protected | function | Return bootstrap images types. | |
SettingsForm:: |
constant | |||
SettingsForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public | function |
SettingsForm constructor. 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. |