diff --git a/core/modules/taxonomy/taxonomy.api.php b/core/modules/taxonomy/taxonomy.api.php index 24fcc01..7679b3e 100644 --- a/core/modules/taxonomy/taxonomy.api.php +++ b/core/modules/taxonomy/taxonomy.api.php @@ -22,8 +22,8 @@ * The vocabulary object. */ function hook_taxonomy_vocabulary_create(\Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { - if (!isset($vocabulary->synonyms)) { - $vocabulary->synonyms = FALSE; + if (!isset($vocabulary->foo)) { + $vocabulary->foo = NULL; } } @@ -37,12 +37,15 @@ function hook_taxonomy_vocabulary_create(\Drupal\taxonomy\Plugin\Core\Entity\Voc * An array of taxonomy vocabulary entities. */ function hook_taxonomy_vocabulary_load(array $vocabularies) { - foreach ($vocabularies as $vocabulary) { - $vocabulary->synonyms = variable_get('taxonomy_' . $vocabulary->id() . '_synonyms', FALSE); + $result = db_select('mytable', 'm') + ->fields('m', array('vid', 'foo')) + ->condition('m.vid', array_keys($vocabularies), 'IN') + ->execute(); + foreach ($result as $record) { + $vocabularies[$record->vid]->foo = $record->foo; } } - /** * Act on taxonomy vocabularies before they are saved. * @@ -53,7 +56,7 @@ function hook_taxonomy_vocabulary_load(array $vocabularies) { * A taxonomy vocabulary entity. */ function hook_taxonomy_vocabulary_presave(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { - $vocabulary->foo = 'bar'; + $vocabulary->set('foo') = 'bar'; } /** @@ -66,8 +69,8 @@ function hook_taxonomy_vocabulary_presave(Drupal\taxonomy\Plugin\Core\Entity\Voc * A taxonomy vocabulary entity. */ function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { - if ($vocabulary->synonyms) { - variable_set('taxonomy_' . $vocabulary->id() . '_synonyms', TRUE); + if ($vocabulary->vid = 'my_vocabulary') { + $vocabulary->weight = 100; } } @@ -80,10 +83,11 @@ function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Plugin\Core\Entity\Voca * A taxonomy vocabulary entity. */ function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { - $status = $vocabulary->synonyms ? TRUE : FALSE; - if ($vocabulary->synonyms) { - variable_set('taxonomy_' . $vocabulary->id() . '_synonyms', $status); - } + db_insert('mytable')->fields(array( + 'vid' => $vocabulary->vid, + 'foo' => $vocabulary->foo + )) + ->execute(); } /** @@ -98,9 +102,7 @@ function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Plugin\Core\Entity\Voca * @see hook_taxonomy_vocabulary_delete() */ function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { - if (variable_get('taxonomy_' . $vocabulary->id() . '_synonyms', FALSE)) { - variable_del('taxonomy_' . $vocabulary->id() . '_synonyms'); - } + db_delete('mytable_index')->condition('vid', $vocabulary->vid)->execute(); } /** @@ -115,9 +117,7 @@ function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Plugin\Core\Entity\V * @see hook_taxonomy_vocabulary_predelete() */ function hook_taxonomy_vocabulary_delete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { - if (variable_get('taxonomy_' . $vocabulary->id() . '_synonyms', FALSE)) { - variable_del('taxonomy_' . $vocabulary->id() . '_synonyms'); - } + db_delete('mytable')->condition('vid', $vocabulary->vid)->execute(); } /** @@ -152,9 +152,12 @@ function hook_taxonomy_term_create(\Drupal\taxonomy\Plugin\Core\Entity\Term $ter * An array of taxonomy term entities, indexed by tid. */ function hook_taxonomy_term_load(array $terms) { - $result = db_query('SELECT tid, foo FROM {mytable} WHERE tid IN (:tids)', array(':tids' => array_keys($terms))); + $result = db_select('mytable', 'm') + ->fields('m', array('tid', 'foo')) + ->condition('m.tid', array_keys($terms), 'IN') + ->execute(); foreach ($result as $record) { - $terms[$record->id()]->foo = $record->foo; + $terms[$record->vid]->foo = $record->foo; } } @@ -181,17 +184,8 @@ function hook_taxonomy_term_presave(Drupal\taxonomy\Term $term) { * A taxonomy term entity. */ function hook_taxonomy_term_insert(Drupal\taxonomy\Term $term) { - if (!empty($term->synonyms)) { - foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) { - if ($synonym) { - db_insert('taxonomy_term_synonym') - ->fields(array( - 'tid' => $term->id(), - 'name' => rtrim($synonym), - )) - ->execute(); - } - } + if (empty($term->description)) { + $term->description = 'A default description.'; } } @@ -204,19 +198,11 @@ function hook_taxonomy_term_insert(Drupal\taxonomy\Term $term) { * A taxonomy term entity. */ function hook_taxonomy_term_update(Drupal\taxonomy\Term $term) { - hook_taxonomy_term_delete($term); - if (!empty($term->synonyms)) { - foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) { - if ($synonym) { - db_insert('taxonomy_term_synonym') - ->fields(array( - 'tid' => $term->id(), - 'name' => rtrim($synonym), - )) - ->execute(); - } - } - } + db_insert('mytable')->fields(array( + 'tid' => $term->tid, + 'foo' => $term->foo + )) + ->execute(); } /** @@ -230,7 +216,7 @@ function hook_taxonomy_term_update(Drupal\taxonomy\Term $term) { * The taxonomy term entity that is about to be deleted. */ function hook_taxonomy_term_predelete(Drupal\taxonomy\Term $term) { - db_delete('term_synoynm')->condition('tid', $term->id())->execute(); + db_delete('mytable_index')->condition('tid', $term->tid)->execute(); } /** @@ -243,7 +229,7 @@ function hook_taxonomy_term_predelete(Drupal\taxonomy\Term $term) { * The taxonomy term entity that has been deleted. */ function hook_taxonomy_term_delete(Drupal\taxonomy\Term $term) { - db_delete('term_synoynm')->condition('tid', $term->id())->execute(); + db_delete('mytable')->condition('tid', $term->id())->execute(); } /**