class JsonApiImageStylesAdminForm in JSON:API Image Styles 2.0.x
Same name and namespace in other branches
- 8 src/Form/JsonApiImageStylesAdminForm.php \Drupal\jsonapi_image_styles\Form\JsonApiImageStylesAdminForm
Provides an admin form for modifying the module configuration.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, RedirectDestinationTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
- class \Drupal\jsonapi_image_styles\Form\JsonApiImageStylesAdminForm
- class \Drupal\Core\Form\ConfigFormBase uses ConfigFormBaseTrait
Expanded class hierarchy of JsonApiImageStylesAdminForm
1 string reference to 'JsonApiImageStylesAdminForm'
File
- src/
Form/ JsonApiImageStylesAdminForm.php, line 14
Namespace
Drupal\jsonapi_image_styles\FormView source
class JsonApiImageStylesAdminForm extends ConfigFormBase {
/**
* Entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a \Drupal\system\ConfigFormBase object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* Entity type manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($config_factory);
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() : array {
return [
'jsonapi_image_styles.settings',
];
}
/**
* {@inheritdoc}
*/
public function getFormId() : string {
return 'jsonapi_image_styles_admin_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) : array {
$config = $this
->config('jsonapi_image_styles.settings');
$options = [];
$styles = $this->entityTypeManager
->getStorage('image_style')
->loadMultiple();
foreach ($styles as $name => $style) {
$options[$name] = $style
->label();
}
$form['image_styles'] = [
'#type' => 'checkboxes',
'#title' => $this
->t('Image styles'),
'#description' => $this
->t('Select image styles to expose for JSON:API. If none are selected, all styles are exposed.'),
'#options' => $options,
'#default_value' => is_array($config
->get('image_styles')) ? $config
->get('image_styles') : [],
];
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) : void {
parent::submitForm($form, $form_state);
$this
->config('jsonapi_image_styles.settings')
->set('image_styles', $form_state
->getValue('image_styles'))
->save();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfigFormBaseTrait:: |
protected | function | Retrieves a configuration object. | |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 3 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 3 |
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. | |
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:: |
72 |
JsonApiImageStylesAdminForm:: |
protected | property | Entity type manager. | |
JsonApiImageStylesAdminForm:: |
public | function |
Form constructor. Overrides ConfigFormBase:: |
|
JsonApiImageStylesAdminForm:: |
public static | function |
Instantiates a new instance of this class. Overrides ConfigFormBase:: |
|
JsonApiImageStylesAdminForm:: |
protected | function |
Gets the configuration names that will be editable. Overrides ConfigFormBaseTrait:: |
|
JsonApiImageStylesAdminForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
JsonApiImageStylesAdminForm:: |
public | function |
Form submission handler. Overrides ConfigFormBase:: |
|
JsonApiImageStylesAdminForm:: |
public | function |
Constructs a \Drupal\system\ConfigFormBase object. Overrides ConfigFormBase:: |
|
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. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
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. | 4 |
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. |