class SettingsForm in Textimage 8.3
Same name and namespace in other branches
- 8.4 src/Form/SettingsForm.php \Drupal\textimage\Form\SettingsForm
Main Textimage settings admin 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\textimage\Form\SettingsForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of SettingsForm
1 string reference to 'SettingsForm'
File
- src/
Form/ SettingsForm.php, line 16
Namespace
Drupal\textimage\FormView source
class SettingsForm extends ConfigFormBase {
/**
* The Textimage factory.
*
* @var \Drupal\textimage\TextimageFactory
*/
protected $textimageFactory;
/**
* The font selector plugin manager.
*
* @var \Drupal\image_effects\Plugin\ImageEffectsPluginManager
*/
protected $fontManager;
/**
* The Image factory.
*
* @var \Drupal\Core\Image\ImageFactory
*/
protected $imageFactory;
/**
* Constructs the class for Textimage settings form.
*
* @param \Drupal\textimage\TextimageFactory $textimage_factory
* The Textimage factory.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\image_effects\Plugin\ImageEffectsPluginManager $font_plugin_manager
* The font selector plugin manager.
* @param \Drupal\Core\Image\ImageFactory $image_factory
* The Image factory.
*/
public function __construct(TextimageFactory $textimage_factory, ConfigFactoryInterface $config_factory, ImageEffectsPluginManager $font_plugin_manager, ImageFactory $image_factory) {
parent::__construct($config_factory);
$this->textimageFactory = $textimage_factory;
$this->fontManager = $font_plugin_manager;
$this->imageFactory = $image_factory;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('textimage.factory'), $container
->get('config.factory'), $container
->get('plugin.manager.image_effects.font_selector'), $container
->get('image.factory'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'textimage_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'textimage.settings',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this
->config('textimage.settings');
$form['settings'] = [
'#type' => 'container',
'#tree' => TRUE,
'#attributes' => [
'id' => 'textimage-settings-main',
],
];
// Main part of settings form.
$form['settings']['main'] = [
'#type' => 'details',
'#open' => TRUE,
'#title' => $this
->t('Main settings'),
];
// Default image file format/extension.
$extensions = $this->imageFactory
->getSupportedExtensions();
$options = array_combine($extensions, $extensions);
$form['settings']['main']['default_extension'] = [
'#type' => 'select',
'#options' => $options,
'#title' => $this
->t('Default image file extension'),
'#default_value' => $config
->get('default_extension'),
'#required' => TRUE,
'#description' => $this
->t('Select the default extension of the image files produced by Textimage. This can be overridden by image style effects that specify a format conversion like e.g. <em>Convert</em>. This setting does not affect image derivatives created by the Image module.'),
];
// Default font.
$font_plugin = $this->fontManager
->getPlugin($this
->config('image_effects.settings')
->get('font_selector.plugin_id'));
$form['settings']['main']['default_font_uri'] = $font_plugin
->selectionElement([
'#title' => $this
->t('Default font'),
'#description' => $this
->t('Select the default font to be used by Textimage.'),
'#default_value' => $config
->get('default_font.uri'),
]);
// URL generation.
$form['settings']['url_generation'] = [
'#type' => 'details',
'#title' => $this
->t('URL generation'),
'#open' => TRUE,
];
$form['settings']['url_generation']['enabled'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Enabled'),
'#description' => $this
->t("When selected, direct generation of Textimage images is enabled for users having the 'Generate Textimage URL derivatives' permission."),
'#default_value' => $config
->get('url_generation.enabled'),
];
$form['settings']['url_generation']['text_separator'] = [
'#type' => 'textfield',
'#title' => $this
->t('Text separator'),
'#maxlength' => 5,
'#required' => TRUE,
'#description' => $this
->t("Indicate the sequence of characters to be used to split the URL text string in separate strings. Each string will be consumed by a 'Text overlay' effect in the sequence specified within the image style. Note that slashes '/' and plus '+' characters are not allowed."),
'#default_value' => $config
->get('url_generation.text_separator'),
];
// Maintenance.
$form['settings']['maintenance'] = [
'#type' => 'details',
'#title' => $this
->t('Maintenance'),
];
$form['settings']['maintenance']['debug'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Display debugging information'),
'#default_value' => $config
->get('debug'),
'#description' => $this
->t("Logs Textimage debug messages and shows them to users with the '%permission' permissions.", [
'%permission' => implode(', ', [
$this
->t('Administer site configuration'),
$this
->t('Administer image styles'),
]),
]),
];
$form['settings']['maintenance']['flush_all_label'] = [
'#markup' => $this
->t('Remove all image files generated via Textimage, flush all the image styles, and clear the Textimage cache.') . '<br/>',
];
$form['settings']['maintenance']['flush_all'] = [
'#type' => 'submit',
'#name' => 'flush_all',
'#value' => $this
->t('Cleanup Textimage'),
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if (preg_match('/[+\\/]/', $form_state
->getValue([
'settings',
'url_generation',
'text_separator',
]))) {
$form_state
->setErrorByName('settings][url_generation][text_separator', $this
->t('Invalid characters specified for the text separator.'));
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = $this
->config('textimage.settings');
// Redirect to cleanup if required.
if ($form_state
->getTriggeringElement()['#name'] == 'flush_all') {
$form_state
->setRedirect('textimage.flush_all');
return;
}
// Main settings.
$font_plugin = $this->fontManager
->getPlugin($this
->config('image_effects.settings')
->get('font_selector.plugin_id'));
$config
->set('default_extension', $form_state
->getValue([
'settings',
'main',
'default_extension',
]))
->set('default_font.name', $font_plugin
->getDescription($form_state
->getValue([
'settings',
'main',
'default_font_uri',
])))
->set('default_font.uri', $form_state
->getValue([
'settings',
'main',
'default_font_uri',
]));
// URL generation.
$config
->set('url_generation.enabled', $form_state
->getValue([
'settings',
'url_generation',
'enabled',
]))
->set('url_generation.text_separator', $form_state
->getValue([
'settings',
'url_generation',
'text_separator',
]));
// Maintenance.
$config
->set('debug', $form_state
->getValue([
'settings',
'maintenance',
'debug',
]));
$config
->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. | |
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 | The font selector plugin manager. | |
SettingsForm:: |
protected | property | The Image factory. | |
SettingsForm:: |
protected | property | The Textimage factory. | |
SettingsForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
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:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
SettingsForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
SettingsForm:: |
public | function |
Constructs the class for Textimage settings form. 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. |