Issue #2111263 by mondrake: Toolkit setup form displays settings for multiple toolkits.
parent
c28e5144b6
commit
35d043d510
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
}
|
||||
}
|
|
@ -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'
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
test_parameter: 10
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue