diff --git a/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php b/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php index 6e3ebeb4bb0107e6550063fc54a342a0613914d3..1600b588da4a06592339f1284c02204ab245f094 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 @@ public function buildForm(array $form, array &$form_state) { $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 @@ public function submitForm(array &$form, array &$form_state) { ->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 0000000000000000000000000000000000000000..848914740bd836453d2c4fc0fd44fc8b398eb016 --- /dev/null +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitSetupFormTest.php @@ -0,0 +1,79 @@ +<?php + +/** + * @file + * Contains \Drupal\system\Tests\Image\ToolkitSetupFormTest. + */ + +namespace Drupal\system\Tests\Image; + +use Drupal\simpletest\WebTestBase; + +/** + * Functional tests for the Image toolkit setup form. + */ +class ToolkitSetupFormTest extends WebTestBase { + + /** + * Admin user account. + * + * @var \Drupal\user\Entity\User + */ + protected $admin_user; + + /** + * Modules to enable. + * + * @var array + */ + public static $modules = array('system', 'image_test'); + + /** + * {@inheritdoc} + */ + public static function getInfo() { + return array( + 'name' => '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 fadc21ab9ba1c6cad0106deef54641997fb87e4a..4d27aa6c18102f21900ad7b6107261029db03f55 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 0000000000000000000000000000000000000000..42a38c442eb9810a19f1174e7990f07639cf6523 --- /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 d677d139aea3eea3328ed04c98dd225ed7c50d3e..5d62a825800df10fd4f7ffafffd2a3ba7bfcc944 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}