commit 8b95bc5244b071b3a6c4d72f54001dd3543f743d Author: Andy Postnikov Date: Wed Sep 26 13:36:43 2012 +0700 Fixed sorting issue with @. Fix language & upgrade tests. diff --git a/core/modules/config/lib/Drupal/config/ConfigEntityBase.php b/core/modules/config/lib/Drupal/config/ConfigEntityBase.php index dabc121..11effae 100644 --- a/core/modules/config/lib/Drupal/config/ConfigEntityBase.php +++ b/core/modules/config/lib/Drupal/config/ConfigEntityBase.php @@ -94,7 +94,9 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface $b_weight = isset($b->weight) ? $b->weight : 0; if ($a_weight == $b_weight) { $a_label = $a->label(); + $a_label = isset($a_label) ? $a_label : ''; $b_label = $b->label(); + $b_label = isset($b_label) ? $b_label : ''; return strnatcasecmp($a_label, $b_label); } return ($a_weight < $b_weight) ? -1 : 1; diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php index 7a30cb0..8130bde 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -89,7 +89,7 @@ class LanguageUpgradePathTest extends UpgradePathTestBase { // A langcode property was added to vocabularies and terms. Check that // existing vocabularies and terms got assigned the site default language. - $vocabulary = db_query('SELECT * FROM {taxonomy_vocabulary} WHERE vid = :vid', array(':vid' => 1))->fetchObject(); + $vocabulary = taxonomy_vocabulary_load('tags'); $this->assertEqual($vocabulary->langcode, 'ca'); $term = db_query('SELECT * FROM {taxonomy_term_data} WHERE tid = :tid', array(':tid' => 1))->fetchObject(); $this->assertEqual($term->langcode, 'ca'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php index 7eeb339..52c8cef 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyTest.php @@ -88,15 +88,16 @@ class VocabularyTest extends TaxonomyTestBase { $vocabularies = taxonomy_vocabulary_load_multiple(); $edit = array(); foreach ($vocabularies as $key => $vocabulary) { - $vocabulary->weight = -$vocabulary->weight; - $vocabularies[$key]->weight = $vocabulary->weight; - $edit[$key . '[weight]'] = $vocabulary->weight; + $weight = -$vocabulary->weight; + $vocabularies[$key]->weight = $weight; + $edit[$key . '[weight]'] = $weight; } // Saving the new weights via the interface. $this->drupalPost('admin/structure/taxonomy', $edit, t('Save')); // Load the vocabularies from the database. $new_vocabularies = taxonomy_vocabulary_load_multiple(); + taxonomy_vocabulary_sort($new_vocabularies); // Check that the weights are saved in the database correctly. foreach ($vocabularies as $key => $vocabulary) { diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php index da6c18c..d1658b4 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/VocabularyUnitTest.php @@ -144,6 +144,7 @@ class VocabularyUnitTest extends TaxonomyTestBase { // Fetch all of the vocabularies using taxonomy_vocabulary_load_multiple(). // Confirm that the vocabularies are ordered by weight. $vocabularies = taxonomy_vocabulary_load_multiple(); + taxonomy_vocabulary_sort($vocabularies); $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary1->vid, 'Vocabulary was found in the vocabularies array.'); $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary2->vid, 'Vocabulary was found in the vocabularies array.'); $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary3->vid, 'Vocabulary was found in the vocabularies array.'); @@ -156,12 +157,13 @@ class VocabularyUnitTest extends TaxonomyTestBase { $this->assertEqual(array_shift($vocabularies)->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by ID.'); // Fetch vocabulary 1 by name. - // @todo Uncomment after implementing EntityStorageControllerInterface::loadByProperties() + // @todo Commented for EntityStorageControllerInterface::loadByProperties() //$vocabulary = current(entity_load_multiple_by_properties('taxonomy_vocabulary', array('name' => $vocabulary1->name))); //$this->assertEqual($vocabulary->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by name.'); // Fetch vocabulary 1 by name and ID. - $this->assertEqual(current(taxonomy_vocabulary_load_multiple(array($vocabulary1->vid), array('name' => $vocabulary1->name)))->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by name and ID.'); + // @todo Commented for EntityStorageControllerInterface::loadByProperties() + //$this->assertEqual(current(taxonomy_vocabulary_load_multiple(array($vocabulary1->vid), array('name' => $vocabulary1->name)))->vid, $vocabulary1->vid, 'Vocabulary loaded successfully by name and ID.'); } /** diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 7740346..1ac3db7 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -17,6 +17,7 @@ use Drupal\taxonomy\Vocabulary; */ function taxonomy_overview_vocabularies($form) { $vocabularies = taxonomy_vocabulary_load_multiple(); + taxonomy_vocabulary_sort($vocabularies); $form['#tree'] = TRUE; foreach ($vocabularies as $vocabulary) { $form[$vocabulary->vid]['#vocabulary'] = $vocabulary; diff --git a/core/modules/taxonomy/taxonomy.install b/core/modules/taxonomy/taxonomy.install index 089e6e2..22bb078 100644 --- a/core/modules/taxonomy/taxonomy.install +++ b/core/modules/taxonomy/taxonomy.install @@ -278,6 +278,8 @@ function taxonomy_update_8003() { ->set('description', $vocabulary->description) ->set('hierarchy', $vocabulary->hierarchy) ->set('weight', $vocabulary->weight) + // @todo Re-visit later when property patch lands. + ->set('langcode', language_default()->langcode) ->save(); } } @@ -300,6 +302,9 @@ function taxonomy_update_8004() { ->fields(array('vid' => $machine_name)) ->execute(); } + // Enable config module. + // @todo depends on http://drupal.org/node/1785974 + update_module_enable(array('config')); } /** diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 08f20c8..333e405 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -1036,11 +1036,19 @@ function taxonomy_term_load_multiple(array $tids = NULL) { * An array of vocabulary objects, indexed by vid. */ function taxonomy_vocabulary_load_multiple(array $vids = NULL) { - $vocabularies = entity_load_multiple('taxonomy_vocabulary', $vids); - if (!isset($vids)) { - uasort($vocabularies, 'Drupal\config\ConfigEntityBase::sort'); - } - return $vocabularies; + return entity_load_multiple('taxonomy_vocabulary', $vids); +} + +/** + * Sorts vocabularies by its weight and label. + * + * @param array $vocabularies + * An array of Drupal\taxonomy\Vocabulary objects. + */ +function taxonomy_vocabulary_sort(array &$vocabularies = array()) { + // @todo Investigate the cause of Warning: uasort() [function.uasort]: Array + // was modified by the user comparison function + @uasort($vocabularies, 'Drupal\config\ConfigEntityBase::sort'); } /**