Commit 63113028 authored by jhodgdon's avatar jhodgdon
Browse files

Issue #1831540 by orb, Berdir, andypost, podarok, Gaelan, znerol, cam8001: Fix...

Issue #1831540 by orb, Berdir, andypost, podarok, Gaelan, znerol, cam8001: Fix up examples in taxonomy.api.php hooks
parent 9a42b9f9
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
* The vocabulary object. * The vocabulary object.
*/ */
function hook_taxonomy_vocabulary_create(\Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { function hook_taxonomy_vocabulary_create(\Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
if (!isset($vocabulary->synonyms)) { if (!isset($vocabulary->foo)) {
$vocabulary->synonyms = FALSE; $vocabulary->foo = NULL;
} }
} }
...@@ -37,12 +37,15 @@ function hook_taxonomy_vocabulary_create(\Drupal\taxonomy\Plugin\Core\Entity\Voc ...@@ -37,12 +37,15 @@ function hook_taxonomy_vocabulary_create(\Drupal\taxonomy\Plugin\Core\Entity\Voc
* An array of taxonomy vocabulary entities. * An array of taxonomy vocabulary entities.
*/ */
function hook_taxonomy_vocabulary_load(array $vocabularies) { function hook_taxonomy_vocabulary_load(array $vocabularies) {
foreach ($vocabularies as $vocabulary) { $result = db_select('mytable', 'm')
$vocabulary->synonyms = variable_get('taxonomy_' . $vocabulary->id() . '_synonyms', FALSE); ->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. * Act on taxonomy vocabularies before they are saved.
* *
...@@ -66,8 +69,8 @@ function hook_taxonomy_vocabulary_presave(Drupal\taxonomy\Plugin\Core\Entity\Voc ...@@ -66,8 +69,8 @@ function hook_taxonomy_vocabulary_presave(Drupal\taxonomy\Plugin\Core\Entity\Voc
* A taxonomy vocabulary entity. * A taxonomy vocabulary entity.
*/ */
function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
if ($vocabulary->synonyms) { if ($vocabulary->id() == 'my_vocabulary') {
variable_set('taxonomy_' . $vocabulary->id() . '_synonyms', TRUE); $vocabulary->weight = 100;
} }
} }
...@@ -80,10 +83,12 @@ function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Plugin\Core\Entity\Voca ...@@ -80,10 +83,12 @@ function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Plugin\Core\Entity\Voca
* A taxonomy vocabulary entity. * A taxonomy vocabulary entity.
*/ */
function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
$status = $vocabulary->synonyms ? TRUE : FALSE; db_insert('mytable')
if ($vocabulary->synonyms) { ->fields(array(
variable_set('taxonomy_' . $vocabulary->id() . '_synonyms', $status); 'vid' => $vocabulary->id(),
} 'foo' => $vocabulary->foo,
))
->execute();
} }
/** /**
...@@ -98,9 +103,9 @@ function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Plugin\Core\Entity\Voca ...@@ -98,9 +103,9 @@ function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Plugin\Core\Entity\Voca
* @see hook_taxonomy_vocabulary_delete() * @see hook_taxonomy_vocabulary_delete()
*/ */
function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
if (variable_get('taxonomy_' . $vocabulary->id() . '_synonyms', FALSE)) { db_delete('mytable_index')
variable_del('taxonomy_' . $vocabulary->id() . '_synonyms'); ->condition('vid', $vocabulary->id())
} ->execute();
} }
/** /**
...@@ -115,9 +120,9 @@ function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Plugin\Core\Entity\V ...@@ -115,9 +120,9 @@ function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Plugin\Core\Entity\V
* @see hook_taxonomy_vocabulary_predelete() * @see hook_taxonomy_vocabulary_predelete()
*/ */
function hook_taxonomy_vocabulary_delete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) { function hook_taxonomy_vocabulary_delete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
if (variable_get('taxonomy_' . $vocabulary->id() . '_synonyms', FALSE)) { db_delete('mytable')
variable_del('taxonomy_' . $vocabulary->id() . '_synonyms'); ->condition('vid', $vocabulary->id())
} ->execute();
} }
/** /**
...@@ -152,9 +157,12 @@ function hook_taxonomy_term_create(\Drupal\taxonomy\Plugin\Core\Entity\Term $ter ...@@ -152,9 +157,12 @@ function hook_taxonomy_term_create(\Drupal\taxonomy\Plugin\Core\Entity\Term $ter
* An array of taxonomy term entities, indexed by tid. * An array of taxonomy term entities, indexed by tid.
*/ */
function hook_taxonomy_term_load(array $terms) { 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) { foreach ($result as $record) {
$terms[$record->id()]->foo = $record->foo; $terms[$record->tid]->foo = $record->foo;
} }
} }
...@@ -181,18 +189,12 @@ function hook_taxonomy_term_presave(Drupal\taxonomy\Term $term) { ...@@ -181,18 +189,12 @@ function hook_taxonomy_term_presave(Drupal\taxonomy\Term $term) {
* A taxonomy term entity. * A taxonomy term entity.
*/ */
function hook_taxonomy_term_insert(Drupal\taxonomy\Term $term) { function hook_taxonomy_term_insert(Drupal\taxonomy\Term $term) {
if (!empty($term->synonyms)) { db_insert('mytable')
foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) { ->fields(array(
if ($synonym) { 'tid' => $term->id(),
db_insert('taxonomy_term_synonym') 'foo' => $term->foo,
->fields(array( ))
'tid' => $term->id(), ->execute();
'name' => rtrim($synonym),
))
->execute();
}
}
}
} }
/** /**
...@@ -204,19 +206,12 @@ function hook_taxonomy_term_insert(Drupal\taxonomy\Term $term) { ...@@ -204,19 +206,12 @@ function hook_taxonomy_term_insert(Drupal\taxonomy\Term $term) {
* A taxonomy term entity. * A taxonomy term entity.
*/ */
function hook_taxonomy_term_update(Drupal\taxonomy\Term $term) { function hook_taxonomy_term_update(Drupal\taxonomy\Term $term) {
hook_taxonomy_term_delete($term); db_insert('mytable')
if (!empty($term->synonyms)) { ->fields(array(
foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) { 'tid' => $term->id(),
if ($synonym) { 'foo' => $term->foo,
db_insert('taxonomy_term_synonym') ))
->fields(array( ->execute();
'tid' => $term->id(),
'name' => rtrim($synonym),
))
->execute();
}
}
}
} }
/** /**
...@@ -230,7 +225,9 @@ function hook_taxonomy_term_update(Drupal\taxonomy\Term $term) { ...@@ -230,7 +225,9 @@ function hook_taxonomy_term_update(Drupal\taxonomy\Term $term) {
* The taxonomy term entity that is about to be deleted. * The taxonomy term entity that is about to be deleted.
*/ */
function hook_taxonomy_term_predelete(Drupal\taxonomy\Term $term) { 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->id())
->execute();
} }
/** /**
...@@ -243,7 +240,9 @@ function hook_taxonomy_term_predelete(Drupal\taxonomy\Term $term) { ...@@ -243,7 +240,9 @@ function hook_taxonomy_term_predelete(Drupal\taxonomy\Term $term) {
* The taxonomy term entity that has been deleted. * The taxonomy term entity that has been deleted.
*/ */
function hook_taxonomy_term_delete(Drupal\taxonomy\Term $term) { 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();
} }
/** /**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment