Skip to content
Snippets Groups Projects
Commit 3b00e7b5 authored by Florent Torregrosa's avatar Florent Torregrosa
Browse files

Issue #3480475 by grimreaper: UI Skins: Fix plugin sorting and PHPCS

parent 92f8536e
No related branches found
No related tags found
1 merge request!23Issue #3480475 by grimreaper: UI Skins: Fix plugin sorting
Pipeline #312806 passed
......@@ -99,6 +99,12 @@ class CssVariablePluginManager extends DefaultPluginManager implements CssVariab
$definitions = $definitions ?? $this->getDefinitions();
\uasort($definitions, static function (CssVariableDefinition $item1, CssVariableDefinition $item2) {
// Sort by weight.
$weight = $item1->getWeight() <=> $item2->getWeight();
if ($weight != 0) {
return $weight;
}
// Sort by category.
$category1 = $item1->getCategory();
if ($category1 instanceof TranslatableMarkup) {
......@@ -112,12 +118,6 @@ class CssVariablePluginManager extends DefaultPluginManager implements CssVariab
return \strnatcasecmp($category1, $category2);
}
// Sort by weight.
$weight = $item1->getWeight() <=> $item2->getWeight();
if ($weight != 0) {
return $weight;
}
// Sort by label ignoring parenthesis.
$label1 = $item1->getLabel();
if ($label1 instanceof TranslatableMarkup) {
......
......@@ -253,7 +253,7 @@ class CssVariablesThemeSettingsForm extends ConfigFormBase {
'#type' => 'container',
// Force an id because otherwise default id is changed when using AJAX.
'#attributes' => [
'id' => HTML::getId('css-variable-values-wrapper-' . $plugin_definition->id()),
'id' => Html::getId('css-variable-values-wrapper-' . $plugin_definition->id()),
],
],
];
......@@ -324,11 +324,11 @@ class CssVariablesThemeSettingsForm extends ConfigFormBase {
$element['actions']['add_more_scope'] = [
'#type' => 'submit',
'#value' => $this->t('Add new scope'),
'#name' => HTML::getId('add_more_scope_' . $plugin_definition->id()),
'#name' => Html::getId('add_more_scope_' . $plugin_definition->id()),
'#submit' => [[$this, 'addNewScope']],
'#ajax' => [
'callback' => [$this, 'addNewScopeCallback'],
'wrapper' => HTML::getId('css-variable-values-wrapper-' . $plugin_definition->id()),
'wrapper' => Html::getId('css-variable-values-wrapper-' . $plugin_definition->id()),
],
'#context' => [
'plugin_id' => $plugin_definition->id(),
......
......@@ -149,121 +149,121 @@ class CssVariablePluginManagerTest extends UnitTestCase {
*/
public function testGetSortedDefinitions(): void {
$this->cssVariablePluginManager->setCssVariables([
'id_z1z2' => [
'category' => 'Z',
'id_1zz2' => [
'weight' => 1,
'category' => 'Z',
'label' => '(Z)',
'id' => 'id_z1z2',
'id' => 'id_1zz2',
],
'id_z1z1' => [
'category' => 'Z',
'id_1zz1' => [
'weight' => 1,
'category' => 'Z',
'label' => 'Z',
'id' => 'id_z1z1',
'id' => 'id_1zz1',
],
'id_z1a2' => [
'category' => 'Z',
'id_1za2' => [
'weight' => 1,
'category' => 'Z',
'label' => '(A)',
'id' => 'id_z1a2',
'id' => 'id_1za2',
],
'id_z1a1' => [
'category' => 'Z',
'id_1za1' => [
'weight' => 1,
'category' => 'Z',
'label' => 'A',
'id' => 'id_z1a1',
'id' => 'id_1za1',
],
'id_z0z2' => [
'category' => 'Z',
'weight' => 0,
'id_1az2' => [
'weight' => 1,
'category' => 'A',
'label' => '(Z)',
'id' => 'id_z0z2',
'id' => 'id_1az2',
],
'id_z0z1' => [
'category' => 'Z',
'weight' => 0,
'id_1az1' => [
'weight' => 1,
'category' => 'A',
'label' => 'Z',
'id' => 'id_z0z1',
'id' => 'id_1az1',
],
'id_z0a2' => [
'category' => 'Z',
'weight' => 0,
'id_1aa2' => [
'weight' => 1,
'category' => 'A',
'label' => '(A)',
'id' => 'id_z0a2',
'id' => 'id_1aa2',
],
'id_z0a1' => [
'category' => 'Z',
'weight' => 0,
'id_1aa1' => [
'weight' => 1,
'category' => 'A',
'label' => 'A',
'id' => 'id_z0a1',
'id' => 'id_1aa1',
],
'id_a1z2' => [
'category' => 'A',
'weight' => 1,
'id_0zz2' => [
'weight' => 0,
'category' => 'Z',
'label' => '(Z)',
'id' => 'id_a1z2',
'id' => 'id_0zz2',
],
'id_a1z1' => [
'category' => 'A',
'weight' => 1,
'id_0zz1' => [
'weight' => 0,
'category' => 'Z',
'label' => 'Z',
'id' => 'id_a1z1',
'id' => 'id_0zz1',
],
'id_a1a2' => [
'category' => 'A',
'weight' => 1,
'id_0za2' => [
'weight' => 0,
'category' => 'Z',
'label' => '(A)',
'id' => 'id_a1a2',
'id' => 'id_0za2',
],
'id_a1a1' => [
'category' => 'A',
'weight' => 1,
'id_0za1' => [
'weight' => 0,
'category' => 'Z',
'label' => 'A',
'id' => 'id_a1a1',
'id' => 'id_0za1',
],
'id_a0z2' => [
'category' => 'A',
'id_0az2' => [
'weight' => 0,
'category' => 'A',
'label' => '(Z)',
'id' => 'id_a0z2',
'id' => 'id_0az2',
],
'id_a0z1' => [
'category' => 'A',
'id_0az1' => [
'weight' => 0,
'category' => 'A',
'label' => 'Z',
'id' => 'id_a0z1',
'id' => 'id_0az1',
],
'id_a0a2' => [
'category' => 'A',
'id_0aa2' => [
'weight' => 0,
'category' => 'A',
'label' => '(A)',
'id' => 'id_a0a2',
'id' => 'id_0aa2',
],
'id_a0a1' => [
'category' => 'A',
'id_0aa1' => [
'weight' => 0,
'category' => 'A',
'label' => 'A',
'id' => 'id_a0a1',
'id' => 'id_0aa1',
],
]);
$expected = [
'id_a0a1',
'id_a0a2',
'id_a0z1',
'id_a0z2',
'id_a1a1',
'id_a1a2',
'id_a1z1',
'id_a1z2',
'id_z0a1',
'id_z0a2',
'id_z0z1',
'id_z0z2',
'id_z1a1',
'id_z1a2',
'id_z1z1',
'id_z1z2',
'id_0aa1',
'id_0aa2',
'id_0az1',
'id_0az2',
'id_0za1',
'id_0za2',
'id_0zz1',
'id_0zz2',
'id_1aa1',
'id_1aa2',
'id_1az1',
'id_1az2',
'id_1za1',
'id_1za2',
'id_1zz1',
'id_1zz2',
];
$sorted_definitions = $this->cssVariablePluginManager->getSortedDefinitions();
......@@ -295,7 +295,7 @@ class CssVariablePluginManagerTest extends UnitTestCase {
'weight' => 0,
],
'cat_2_0_a' => [
'id' => 'cat_1_0_a',
'id' => 'cat_2_0_a',
'category' => 'Cat 2',
'label' => 'A',
'weight' => 0,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment