diff --git a/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php b/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php index 6e3ebeb4bb0..1600b588da4 100644 --- a/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php +++ b/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php @@ -69,22 +69,26 @@ class ImageToolkitForm extends ConfigFormBase { $form['image_toolkit'] = array( '#type' => 'radios', - '#title' => t('Select an image processing toolkit'), + '#title' => $this->t('Select an image processing toolkit'), '#default_value' => $current_toolkit, '#options' => array(), ); - // If we have available toolkits, allow the user to select the image toolkit - // to use and load the settings forms. + // 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] = array( - '#type' => 'fieldset', - '#title' => t('@toolkit settings', array('@toolkit' => $definition['title'])), - '#collapsible' => TRUE, - '#collapsed' => ($id == $current_toolkit) ? FALSE : TRUE, + '#type' => 'details', + '#title' => $this->t('@toolkit settings', array('@toolkit' => $definition['title'])), + '#collapsed' => FALSE, '#tree' => TRUE, + '#states' => array( + 'visible' => array( + ':radio[name="image_toolkit"]' => array('value' => $id), + ), + ), ); $form['image_toolkit_settings'][$id] += $toolkit->settingsForm(); } @@ -101,7 +105,6 @@ class ImageToolkitForm extends ConfigFormBase { ->save(); // Call the form submit handler for each of the toolkits. - // Get the toolkit settings forms. foreach ($this->availableToolkits as $toolkit) { $toolkit->settingsFormSubmit($form, $form_state); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitSetupFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitSetupFormTest.php new file mode 100644 index 00000000000..848914740bd --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitSetupFormTest.php @@ -0,0 +1,79 @@ + 'Image toolkit setup form tests', + 'description' => 'Check image toolkit setup form.', + 'group' => 'Image', + ); + } + + /** + * {@inheritdoc} + */ + public function setUp() { + parent::setUp(); + $this->admin_user = $this->drupalCreateUser(array( + 'access administration pages', + )); + $this->drupalLogin($this->admin_user); + } + + /** + * Test Image toolkit setup form. + */ + function testToolkitSetupForm() { + // Get form. + $this->drupalGet('admin/config/media/image-toolkit'); + + // Test that default toolkit is GD. + $this->assertFieldByName('image_toolkit', 'gd', 'The default image toolkit is GD.'); + + // Test changing the jpeg image quality. + $edit = array('gd[image_jpeg_quality]' => '70'); + $this->drupalPostForm(NULL, $edit, 'Save configuration'); + $this->assertEqual(\Drupal::config('system.image.gd')->get('jpeg_quality'), '70'); + + // Test changing the toolkit. + $edit = array('image_toolkit' => 'test'); + $this->drupalPostForm(NULL, $edit, 'Save configuration'); + $this->assertEqual(\Drupal::config('system.image')->get('toolkit'), 'test'); + $this->assertFieldByName('test[test_parameter]', '10'); + + // Test changing the test toolkit parameter. + $edit = array('test[test_parameter]' => '20'); + $this->drupalPostForm(NULL, $edit, 'Save configuration'); + $this->assertEqual(\Drupal::config('system.image.test_toolkit')->get('test_parameter'), '20'); + } +} diff --git a/core/modules/system/system.routing.yml b/core/modules/system/system.routing.yml index fadc21ab9ba..4d27aa6c181 100644 --- a/core/modules/system/system.routing.yml +++ b/core/modules/system/system.routing.yml @@ -187,7 +187,7 @@ system.image_toolkit_settings: _form: 'Drupal\system\Form\ImageToolkitForm' _title: 'Image toolkit' requirements: - _permission: 'administer administration pages' + _permission: 'access administration pages' system.site_maintenance_mode: path: '/admin/config/development/maintenance' diff --git a/core/modules/system/tests/modules/image_test/config/system.image.test_toolkit.yml b/core/modules/system/tests/modules/image_test/config/system.image.test_toolkit.yml new file mode 100644 index 00000000000..42a38c442eb --- /dev/null +++ b/core/modules/system/tests/modules/image_test/config/system.image.test_toolkit.yml @@ -0,0 +1 @@ +test_parameter: 10 diff --git a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php index d677d139aea..5d62a825800 100644 --- a/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php +++ b/core/modules/system/tests/modules/image_test/lib/Drupal/image_test/Plugin/ImageToolkit/TestToolkit.php @@ -25,13 +25,25 @@ class TestToolkit extends ImageToolkitBase { */ public function settingsForm() { $this->logCall('settings', array()); - return array(); + $form['test_parameter'] = array( + '#type' => 'number', + '#title' => $this->t('Test toolkit parameter'), + '#description' => $this->t('A toolkit parameter for testing purposes.'), + '#min' => 0, + '#max' => 100, + '#default_value' => \Drupal::config('system.image.test_toolkit')->get('test_parameter'), + ); + return $form; } /** * {@inheritdoc} */ - public function settingsFormSubmit($form, &$form_state) {} + public function settingsFormSubmit($form, &$form_state) { + \Drupal::config('system.image.test_toolkit') + ->set('test_parameter', $form_state['values']['test']['test_parameter']) + ->save(); + } /** * {@inheritdoc}