<?php
use Drupal\Core\Entity\EntityInterface;
function hook_taxonomy_vocabulary_create(\Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
if (!isset($vocabulary->foo)) {
$vocabulary->foo = NULL;
}
}
function hook_taxonomy_vocabulary_load(array $vocabularies) {
$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;
}
}
function hook_taxonomy_vocabulary_presave(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
$vocabulary->foo = 'bar';
}
function hook_taxonomy_vocabulary_insert(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
if ($vocabulary
->id() == 'my_vocabulary') {
$vocabulary->weight = 100;
}
}
function hook_taxonomy_vocabulary_update(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
db_insert('mytable')
->fields(array(
'vid' => $vocabulary
->id(),
'foo' => $vocabulary->foo,
))
->execute();
}
function hook_taxonomy_vocabulary_predelete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
db_delete('mytable_index')
->condition('vid', $vocabulary
->id())
->execute();
}
function hook_taxonomy_vocabulary_delete(Drupal\taxonomy\Plugin\Core\Entity\Vocabulary $vocabulary) {
db_delete('mytable')
->condition('vid', $vocabulary
->id())
->execute();
}
function hook_taxonomy_term_create(\Drupal\taxonomy\Plugin\Core\Entity\Term $term) {
if (!isset($term->foo)) {
$term->foo = 'some_initial_value';
}
}
function hook_taxonomy_term_load(array $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->tid]->foo = $record->foo;
}
}
function hook_taxonomy_term_presave(Drupal\taxonomy\Term $term) {
$term->foo = 'bar';
}
function hook_taxonomy_term_insert(Drupal\taxonomy\Term $term) {
db_insert('mytable')
->fields(array(
'tid' => $term
->id(),
'foo' => $term->foo,
))
->execute();
}
function hook_taxonomy_term_update(Drupal\taxonomy\Term $term) {
db_insert('mytable')
->fields(array(
'tid' => $term
->id(),
'foo' => $term->foo,
))
->execute();
}
function hook_taxonomy_term_predelete(Drupal\taxonomy\Term $term) {
db_delete('mytable_index')
->condition('tid', $term
->id())
->execute();
}
function hook_taxonomy_term_delete(Drupal\taxonomy\Term $term) {
db_delete('mytable')
->condition('tid', $term
->id())
->execute();
}
function hook_taxonomy_term_view(\Drupal\taxonomy\Plugin\Core\Entity\Term $term, \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display, $view_mode, $langcode) {
if ($display
->getComponent('mymodule_addition')) {
$term->content['mymodule_addition'] = array(
'#markup' => mymodule_addition($term),
'#theme' => 'mymodule_my_additional_field',
);
}
}
function hook_taxonomy_term_view_alter(&$build, \Drupal\taxonomy\Plugin\Core\Entity\Term $term, \Drupal\entity\Plugin\Core\Entity\EntityDisplay $display) {
if ($build['#view_mode'] == 'full' && isset($build['an_additional_field'])) {
$build['an_additional_field']['#weight'] = -10;
}
$build['#post_render'][] = 'my_module_taxonomy_term_post_render';
}