class ImageToolkitForm
Same name and namespace in other branches
- 11.x core/modules/system/src/Form/ImageToolkitForm.php \Drupal\system\Form\ImageToolkitForm
Configures image toolkit settings for this site.
@internal
Hierarchy
- class \Drupal\Core\Form\FormBase extends \Drupal\Core\Form\FormInterface, \Drupal\Core\DependencyInjection\ContainerInjectionInterface uses \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Logger\LoggerChannelTrait, \Drupal\Core\Messenger\MessengerTrait, \Drupal\Core\Routing\RedirectDestinationTrait, \Drupal\Core\StringTranslation\StringTranslationTrait
- class \Drupal\Core\Form\ConfigFormBase uses \Drupal\Core\Form\ConfigFormBaseTrait implements \Drupal\Core\Form\FormBase
- class \Drupal\system\Form\ImageToolkitForm implements \Drupal\Core\Form\ConfigFormBase
- class \Drupal\Core\Form\ConfigFormBase uses \Drupal\Core\Form\ConfigFormBaseTrait implements \Drupal\Core\Form\FormBase
Expanded class hierarchy of ImageToolkitForm
1 string reference to 'ImageToolkitForm'
- system.routing.yml in core/
modules/ system/ system.routing.yml - core/modules/system/system.routing.yml
File
-
core/
modules/ system/ src/ Form/ ImageToolkitForm.php, line 16
Namespace
Drupal\system\FormView source
class ImageToolkitForm extends ConfigFormBase {
/**
* An array containing currently available toolkits.
*
* @var \Drupal\Core\ImageToolkit\ImageToolkitInterface[]
*/
protected $availableToolkits = [];
/**
* Constructs an ImageToolkitForm object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The factory for configuration objects.
* @param \Drupal\Core\ImageToolkit\ImageToolkitManager $manager
* The image toolkit plugin manager.
*/
public function __construct(ConfigFactoryInterface $config_factory, ImageToolkitManager $manager) {
parent::__construct($config_factory);
foreach ($manager->getAvailableToolkits() as $id => $definition) {
$this->availableToolkits[$id] = $manager->createInstance($id);
}
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container->get('config.factory'), $container->get('image.toolkit.manager'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'system_image_toolkit_settings';
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return [
'system.image',
];
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$current_toolkit = $this->config('system.image')
->get('toolkit');
$form['image_toolkit'] = [
'#type' => 'radios',
'#title' => $this->t('Select an image processing toolkit'),
'#default_value' => $current_toolkit,
'#options' => [],
];
// If we have more than one image toolkit, allow the user to select the one
// to use, and load each of the toolkits' settings form.
foreach ($this->availableToolkits as $id => $toolkit) {
$definition = $toolkit->getPluginDefinition();
$form['image_toolkit']['#options'][$id] = $definition['title'];
$form['image_toolkit_settings'][$id] = [
'#type' => 'details',
'#title' => $this->t('@toolkit settings', [
'@toolkit' => $definition['title'],
]),
'#open' => TRUE,
'#tree' => TRUE,
'#states' => [
'visible' => [
':radio[name="image_toolkit"]' => [
'value' => $id,
],
],
],
];
$form['image_toolkit_settings'][$id] += $toolkit->buildConfigurationForm([], $form_state);
}
return parent::buildForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
// Call the form validation handler for each of the toolkits.
foreach ($this->availableToolkits as $toolkit) {
$toolkit->validateConfigurationForm($form, $form_state);
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->config('system.image')
->set('toolkit', $form_state->getValue('image_toolkit'))
->save();
// Call the form submit handler for each of the toolkits.
foreach ($this->availableToolkits as $toolkit) {
$toolkit->submitConfigurationForm($form, $form_state);
}
parent::submitForm($form, $form_state);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.