Commit 5a8e7bd7 authored by catch's avatar catch

Issue #1361232 by sun, Berdir, aspilicious, fago, klausi, amateescu: Make the...

Issue #1361232 by sun, Berdir, aspilicious, fago, klausi, amateescu: Make the taxonomy entities classed objects.
parent 99269244
......@@ -403,9 +403,18 @@ function drupal_write_record($table, &$record, $primary_keys = array()) {
continue;
}
// Skip fields that are not provided, default values are already known
// by the database. property_exists() allows to explicitly set a value to
// NULL.
if (!property_exists($object, $field)) {
// Skip fields that are not provided, default values are already known
// by the database.
$default_fields[] = $field;
continue;
}
// However, if $object is an entity class instance, then class properties
// always exist, as they cannot be unset. Therefore, if $field is a serial
// type and the value is NULL, skip it.
// @see http://php.net/manual/en/function.property-exists.php
if ($info['type'] == 'serial' && !isset($object->$field)) {
$default_fields[] = $field;
continue;
}
......
......@@ -196,7 +196,7 @@ protected function preSave(EntityInterface $comment) {
/**
* Overrides EntityDatabaseStorageController::postSave().
*/
protected function postSave(EntityInterface $comment) {
protected function postSave(EntityInterface $comment, $update) {
// Update the {node_comment_statistics} table prior to executing the hook.
$this->updateNodeStatistics($comment->nid);
if ($comment->status == COMMENT_PUBLISHED) {
......
......@@ -33,11 +33,30 @@ public function id();
/**
* Returns whether the entity is new.
*
* Usually an entity is new if no ID exists for it yet. However, entities may
* be enforced to be new with existing IDs too.
*
* @return
* TRUE if the entity is new, or FALSE if the entity has already been saved.
*
* @see EntityInterface::enforceIsNew()
*/
public function isNew();
/**
* Enforces an entity to be new.
*
* Allows migrations to create entities with pre-defined IDs by forcing the
* entity to be new before saving.
*
* @param bool $value
* (optional) Whether the entity should be forced to be new. Defaults to
* TRUE.
*
* @see EntityInterface::isNew()
*/
public function enforceIsNew($value = TRUE);
/**
* Returns the type of the entity.
*
......@@ -147,6 +166,13 @@ class Entity implements EntityInterface {
*/
protected $bundleKey;
/**
* Boolean indicating whether the entity should be forced to be new.
*
* @var bool
*/
protected $enforceIsNew;
/**
* Constructs a new entity object.
*/
......@@ -179,9 +205,14 @@ public function id() {
* Implements EntityInterface::isNew().
*/
public function isNew() {
// We support creating entities with pre-defined IDs to ease migrations.
// For that the "is_new" property may be set to TRUE.
return !empty($this->is_new) || empty($this->{$this->idKey});
return !empty($this->enforceIsNew) || empty($this->{$this->idKey});
}
/**
* Implements EntityInterface::enforceIsNew().
*/
public function enforceIsNew($value = TRUE) {
$this->enforceIsNew = $value;
}
/**
......
......@@ -403,6 +403,18 @@ protected function cacheSet($entities) {
*/
interface EntityStorageControllerInterface extends DrupalEntityControllerInterface {
/**
* Constructs a new entity object, without permanently saving it.
*
* @param $values
* An array of values to set, keyed by property name. If the entity type has
* bundles the bundle key has to be specified.
*
* @return EntityInterface
* A new entity object.
*/
public function create(array $values);
/**
* Deletes permanently saved entities.
*
......@@ -441,6 +453,14 @@ class EntityStorageException extends Exception { }
*/
class EntityDatabaseStorageController extends DrupalDefaultEntityController implements EntityStorageControllerInterface {
/**
* Implements EntityStorageControllerInterface::create().
*/
public function create(array $values) {
$class = isset($this->entityInfo['entity class']) ? $this->entityInfo['entity class'] : 'Entity';
return new $class($values, $this->entityType);
}
/**
* Implements EntityStorageControllerInterface::delete().
*/
......@@ -496,18 +516,21 @@ public function save(EntityInterface $entity) {
if (!$entity->isNew()) {
$return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey);
$this->resetCache(array($entity->{$this->idKey}));
$this->postSave($entity);
$this->postSave($entity, TRUE);
$this->invokeHook('update', $entity);
}
else {
$return = drupal_write_record($this->entityInfo['base table'], $entity);
$this->postSave($entity);
// Reset general caches, but keep caches specific to certain entities.
$this->resetCache(array());
$entity->enforceIsNew(FALSE);
$this->postSave($entity, FALSE);
$this->invokeHook('insert', $entity);
}
// Ignore slave server temporarily.
db_ignore_slave();
unset($entity->is_new);
unset($entity->original);
return $return;
......@@ -531,8 +554,12 @@ protected function preSave(EntityInterface $entity) { }
*
* Used after the entity is saved, but before invoking the insert or update
* hook.
*
* @param $update
* (bool) TRUE if the entity has been updated, or FALSE if it has been
* inserted.
*/
protected function postSave(EntityInterface $entity) { }
protected function postSave(EntityInterface $entity, $update) { }
/**
* Acts on entities before they are deleted.
......
......@@ -270,7 +270,7 @@ function entity_delete_multiple($entity_type, $ids) {
}
/**
* Constructs a new entity object, without saving it to the database.
* Constructs a new entity object, without permanently saving it.
*
* @param $entity_type
* The type of the entity.
......@@ -282,13 +282,13 @@ function entity_delete_multiple($entity_type, $ids) {
* A new entity object.
*/
function entity_create($entity_type, array $values) {
$info = entity_get_info($entity_type) + array('entity class' => 'Entity');
$class = $info['entity class'];
return new $class($values, $entity_type);
return entity_get_controller($entity_type)->create($values);
}
/**
* Gets the entity controller class for an entity type.
*
* @return EntityStorageControllerInterface
*/
function entity_get_controller($entity_type) {
$controllers = &drupal_static(__FUNCTION__, array());
......
......@@ -245,22 +245,22 @@ class EntityCrudHookTestCase extends DrupalWebTestCase {
* Tests hook invocations for CRUD operations on taxonomy terms.
*/
public function testTaxonomyTermHooks() {
$vocabulary = (object) array(
$vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => 'Test vocabulary',
'machine_name' => 'test',
'langcode' => LANGUAGE_NOT_SPECIFIED,
'description' => NULL,
'module' => 'entity_crud_hook_test',
);
));
taxonomy_vocabulary_save($vocabulary);
$term = (object) array(
$term = entity_create('taxonomy_term', array(
'vid' => $vocabulary->vid,
'name' => 'Test term',
'langcode' => LANGUAGE_NOT_SPECIFIED,
'description' => NULL,
'format' => 1,
);
));
$_SESSION['entity_crud_hook_test'] = array();
taxonomy_term_save($term);
......@@ -305,13 +305,13 @@ class EntityCrudHookTestCase extends DrupalWebTestCase {
* Tests hook invocations for CRUD operations on taxonomy vocabularies.
*/
public function testTaxonomyVocabularyHooks() {
$vocabulary = (object) array(
$vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => 'Test vocabulary',
'machine_name' => 'test',
'langcode' => LANGUAGE_NOT_SPECIFIED,
'description' => NULL,
'module' => 'entity_crud_hook_test',
);
));
$_SESSION['entity_crud_hook_test'] = array();
taxonomy_vocabulary_save($vocabulary);
......
......@@ -158,11 +158,11 @@ class FieldUIManageFieldsTestCase extends FieldUITestCase {
$this->drupalCreateContentType(array('type' => 'article', 'name' => 'Article'));
// Create a vocabulary named "Tags".
$vocabulary = (object) array(
$vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => 'Tags',
'machine_name' => 'tags',
'langcode' => LANGUAGE_NOT_SPECIFIED,
);
));
taxonomy_vocabulary_save($vocabulary);
$field = array(
......
......@@ -79,7 +79,9 @@ function forum_form_submit($form, &$form_state) {
$type = t('forum');
}
$term = (object) $form_state['values'];
// @todo Set explicit entity properties instead of arbitrary form values.
form_state_values_clean($form_state);
$term = entity_create('taxonomy_term', $form_state['values']);
$status = taxonomy_term_save($term);
switch ($status) {
case SAVED_NEW:
......
......@@ -30,7 +30,7 @@ function forum_enable() {
// Create the forum vocabulary if it does not exist.
$vocabulary = taxonomy_vocabulary_load(variable_get('forum_nav_vocabulary', 0));
if (!$vocabulary) {
$edit = array(
$vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => t('Forums'),
'machine_name' => 'forums',
'langcode' => language_default()->langcode,
......@@ -38,8 +38,7 @@ function forum_enable() {
'hierarchy' => 1,
'module' => 'forum',
'weight' => -10,
);
$vocabulary = (object) $edit;
));
taxonomy_vocabulary_save($vocabulary);
variable_set('forum_nav_vocabulary', $vocabulary->vid);
}
......@@ -61,14 +60,13 @@ function forum_enable() {
field_create_field($field);
// Create a default forum so forum posts can be created.
$edit = array(
$term = entity_create('taxonomy_term', array(
'name' => t('General discussion'),
'langcode' => language_default()->langcode,
'description' => '',
'parent' => array(0),
'vid' => $vocabulary->vid,
);
$term = (object) $edit;
));
taxonomy_term_save($term);
// Create the instance on the bundle.
......
......@@ -468,7 +468,7 @@ function forum_permission() {
/**
* Implements hook_taxonomy_term_delete().
*/
function forum_taxonomy_term_delete(stdClass $term) {
function forum_taxonomy_term_delete(TaxonomyTerm $term) {
// For containers, remove the tid from the forum_containers variable.
$containers = variable_get('forum_containers', array());
$key = array_search($term->tid, $containers);
......
......@@ -266,7 +266,7 @@ function path_form_taxonomy_form_term_alter(&$form, $form_state) {
/**
* Implements hook_taxonomy_term_insert().
*/
function path_taxonomy_term_insert($term) {
function path_taxonomy_term_insert(TaxonomyTerm $term) {
if (isset($term->path)) {
$path = $term->path;
$path['alias'] = trim($path['alias']);
......@@ -283,7 +283,7 @@ function path_taxonomy_term_insert($term) {
/**
* Implements hook_taxonomy_term_update().
*/
function path_taxonomy_term_update($term) {
function path_taxonomy_term_update(TaxonomyTerm $term) {
if (isset($term->path)) {
$path = $term->path;
$path['alias'] = trim($path['alias']);
......@@ -304,7 +304,7 @@ function path_taxonomy_term_update($term) {
/**
* Implements hook_taxonomy_term_delete().
*/
function path_taxonomy_term_delete($term) {
function path_taxonomy_term_delete(TaxonomyTerm $term) {
// Delete all aliases associated with this term.
path_delete(array('source' => 'taxonomy/term/' . $term->tid));
}
......@@ -230,11 +230,11 @@ class PathTaxonomyTermTestCase extends PathTestCase {
parent::setUp(array('taxonomy'));
// Create a Tags vocabulary for the Article node type.
$vocabulary = (object) array(
$vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => t('Tags'),
'machine_name' => 'tags',
);
taxonomy_vocabulary_save($vocabulary);
));
$vocabulary->save();
// Create and login user.
$web_user = $this->drupalCreateUser(array('administer url aliases', 'administer taxonomy', 'access administration pages'));
......
......@@ -8,7 +8,7 @@
/**
* Implements hook_taxonomy_term_load().
*/
function taxonomy_test_taxonomy_term_load($terms) {
function taxonomy_test_taxonomy_term_load(array $terms) {
foreach ($terms as $term) {
$antonym = taxonomy_test_get_antonym($term->tid);
if ($antonym) {
......@@ -20,7 +20,7 @@ function taxonomy_test_taxonomy_term_load($terms) {
/**
* Implements hook_taxonomy_term_insert().
*/
function taxonomy_test_taxonomy_term_insert($term) {
function taxonomy_test_taxonomy_term_insert(TaxonomyTerm $term) {
if (!empty($term->antonym)) {
db_insert('taxonomy_term_antonym')
->fields(array(
......@@ -34,7 +34,7 @@ function taxonomy_test_taxonomy_term_insert($term) {
/**
* Implements hook_taxonomy_term_update().
*/
function taxonomy_test_taxonomy_term_update($term) {
function taxonomy_test_taxonomy_term_update(TaxonomyTerm $term) {
if (!empty($term->antonym)) {
db_merge('taxonomy_term_antonym')
->key(array('tid' => $term->tid))
......@@ -48,7 +48,7 @@ function taxonomy_test_taxonomy_term_update($term) {
/**
* Implements hook_taxonomy_term_delete().
*/
function taxonomy_test_taxonomy_term_delete($term) {
function taxonomy_test_taxonomy_term_delete(TaxonomyTerm $term) {
db_delete('taxonomy_term_antonym')
->condition('tid', $term->tid)
->execute();
......
......@@ -298,6 +298,10 @@ abstract class UpgradePathTestCase extends DrupalWebTestCase {
drupal_load('module', $module);
}
// Re-register autoload functions.
spl_autoload_register('drupal_autoload_class');
spl_autoload_register('drupal_autoload_interface');
// Reload hook implementations
module_implements_reset();
......
......@@ -101,31 +101,27 @@ function theme_taxonomy_overview_vocabularies($variables) {
/**
* Form builder for the vocabulary editing form.
*
* @param TaxonomyVocabulary|null $vocabulary
* (optional) The taxonomy vocabulary entity to edit. If NULL or omitted, the
* form creates a new vocabulary.
*
* @ingroup forms
* @see taxonomy_form_vocabulary_submit()
* @see taxonomy_form_vocabulary_validate()
*/
function taxonomy_form_vocabulary($form, &$form_state, $edit = array()) {
function taxonomy_form_vocabulary($form, &$form_state, TaxonomyVocabulary $vocabulary = NULL) {
// During initial form build, add the entity to the form state for use
// during form building and processing. During a rebuild, use what is in the
// form state.
if (!isset($form_state['vocabulary'])) {
$vocabulary = is_object($edit) ? $edit : (object) $edit;
$defaults = array(
'name' => '',
'machine_name' => '',
'description' => '',
'hierarchy' => TAXONOMY_HIERARCHY_DISABLED,
'weight' => 0,
// Default the new vocabulary to the site's default language. This is
// the most likely default value until we have better flexible settings.
// @todo See http://drupal.org/node/258785 and followups.
'langcode' => language_default()->langcode,
);
foreach ($defaults as $key => $value) {
if (!isset($vocabulary->$key)) {
$vocabulary->$key = $value;
}
// Create a new TaxonomyVocabulary entity for the add form.
if (!isset($vocabulary)) {
$vocabulary = entity_create('taxonomy_vocabulary', array(
// Default the new vocabulary to the site's default language. This is
// the most likely default value until we have better flexible settings.
// @todo See http://drupal.org/node/258785 and followups.
'langcode' => language_default()->langcode,
));
}
$form_state['vocabulary'] = $vocabulary;
}
......@@ -156,10 +152,6 @@ function taxonomy_form_vocabulary($form, &$form_state, $edit = array()) {
'exists' => 'taxonomy_vocabulary_machine_name_load',
),
);
$form['old_machine_name'] = array(
'#type' => 'value',
'#value' => $vocabulary->machine_name,
);
$form['description'] = array(
'#type' => 'textfield',
'#title' => t('Description'),
......@@ -222,6 +214,9 @@ function taxonomy_form_vocabulary_submit($form, &$form_state) {
$vocabulary = $form_state['vocabulary'];
entity_form_submit_build_entity('taxonomy_vocabulary', $vocabulary, $form, $form_state);
// Prevent leading and trailing spaces in vocabulary names.
$vocabulary->name = trim($vocabulary->name);
switch (taxonomy_vocabulary_save($vocabulary)) {
case SAVED_NEW:
drupal_set_message(t('Created new vocabulary %name.', array('%name' => $vocabulary->name)));
......@@ -246,11 +241,14 @@ function taxonomy_form_vocabulary_submit($form, &$form_state) {
* Display a tree of all the terms in a vocabulary, with options to edit
* each one. The form is made drag and drop by the theme function.
*
* @param TaxonomyVocabulary $vocabulary
* The taxonomy vocabulary entity to list terms for.
*
* @ingroup forms
* @see taxonomy_overview_terms_submit()
* @see theme_taxonomy_overview_terms()
*/
function taxonomy_overview_terms($form, &$form_state, $vocabulary) {
function taxonomy_overview_terms($form, &$form_state, TaxonomyVocabulary $vocabulary) {
global $pager_page_array, $pager_total, $pager_total_items;
// Check for confirmation forms.
......@@ -644,35 +642,36 @@ function theme_taxonomy_overview_terms($variables) {
/**
* Form function for the term edit form.
*
* @param TaxonomyTerm|null $term
* (optional) The taxonomy term entity to edit. If NULL or omitted, the form
* creates a new term.
* @param TaxonomyVocabulary|null $vocabulary
* (optional) A taxonomy vocabulary entity to create the term in. Required if
* the term is omitted.
*
* @ingroup forms
* @see taxonomy_form_term_validate()
* @see taxonomy_form_term_submit()
*/
function taxonomy_form_term($form, &$form_state, $edit = array(), $vocabulary = NULL) {
function taxonomy_form_term($form, &$form_state, TaxonomyTerm $term = NULL, TaxonomyVocabulary $vocabulary = NULL) {
// During initial form build, add the term entity to the form state for use
// during form building and processing. During a rebuild, use what is in the
// form state.
if (!isset($form_state['term'])) {
$term = is_object($edit) ? $edit : (object) $edit;
// Create a new TaxonomyTerm entity for the add form.
if (!isset($term)) {
$term = entity_create('taxonomy_term', array(
'vid' => $vocabulary->vid,
'vocabulary_machine_name' => $vocabulary->machine_name,
// Default the new vocabulary to the site's default language. This is
// the most likely default value until we have better flexible settings.
// @todo See http://drupal.org/node/258785 and followups.
'langcode' => language_default()->langcode,
));
}
if (!isset($vocabulary) && isset($term->vid)) {
$vocabulary = taxonomy_vocabulary_load($term->vid);
}
$defaults = array(
'name' => '',
'description' => '',
'format' => NULL,
'vocabulary_machine_name' => isset($vocabulary) ? $vocabulary->machine_name : NULL,
'tid' => NULL,
'weight' => 0,
// Default the new term to the site's default language. This is the most
// likely default value until we have better flexible settings.
// @todo See http://drupal.org/node/258785 and followups.
'langcode' => language_default()->langcode,
);
foreach ($defaults as $key => $value) {
if (!isset($term->$key)) {
$term->$key = $value;
}
}
$form_state['term'] = $term;
}
else {
......@@ -858,6 +857,9 @@ function taxonomy_form_term_submit_build_taxonomy_term($form, &$form_state) {
$term = $form_state['term'];
entity_form_submit_build_entity('taxonomy_term', $term, $form, $form_state);
// Prevent leading and trailing spaces in term names.
$term->name = trim($term->name);
// Convert text_format field into values expected by taxonomy_term_save().
$description = $form_state['values']['description'];
$term->description = $description['value'];
......
......@@ -16,10 +16,10 @@
* Modules implementing this hook can act on the vocabulary objects before they
* are returned by taxonomy_vocabulary_load_multiple().
*
* @param $vocabulary
* An array of taxonomy vocabulary objects.
* @param array $vocabularies
* An array of taxonomy vocabulary entities.
*/
function hook_taxonomy_vocabulary_load($vocabularies) {
function hook_taxonomy_vocabulary_load(array $vocabularies) {
foreach ($vocabularies as $vocabulary) {
$vocabulary->synonyms = variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE);
}
......@@ -32,10 +32,10 @@ function hook_taxonomy_vocabulary_load($vocabularies) {
* Modules implementing this hook can act on the vocabulary object before it is
* inserted or updated.
*
* @param $vocabulary
* A taxonomy vocabulary object.
* @param TaxonomyVocabulary $vocabulary
* A taxonomy vocabulary entity.
*/
function hook_taxonomy_vocabulary_presave($vocabulary) {
function hook_taxonomy_vocabulary_presave(TaxonomyVocabulary $vocabulary) {
$vocabulary->foo = 'bar';
}
......@@ -45,10 +45,10 @@ function hook_taxonomy_vocabulary_presave($vocabulary) {
* Modules implementing this hook can act on the vocabulary object when saved
* to the database.
*
* @param $vocabulary
* A taxonomy vocabulary object.
* @param TaxonomyVocabulary $vocabulary
* A taxonomy vocabulary entity.
*/
function hook_taxonomy_vocabulary_insert($vocabulary) {
function hook_taxonomy_vocabulary_insert(TaxonomyVocabulary $vocabulary) {
if ($vocabulary->synonyms) {
variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', TRUE);
}
......@@ -59,10 +59,10 @@ function hook_taxonomy_vocabulary_insert($vocabulary) {
*
* Modules implementing this hook can act on the vocabulary object when updated.
*
* @param $vocabulary
* A taxonomy vocabulary object.
* @param TaxonomyVocabulary $vocabulary
* A taxonomy vocabulary entity.
*/
function hook_taxonomy_vocabulary_update($vocabulary) {
function hook_taxonomy_vocabulary_update(TaxonomyVocabulary $vocabulary) {
$status = $vocabulary->synonyms ? TRUE : FALSE;
if ($vocabulary->synonyms) {
variable_set('taxonomy_' . $vocabulary->vid . '_synonyms', $status);
......@@ -76,14 +76,13 @@ function hook_taxonomy_vocabulary_update($vocabulary) {
* field_attach_delete_bundle() is called and before the vocabulary is actually
* removed from the database.
*
* @param $vocabulary
* The taxonomy vocabulary object for the vocabulary that is about to be
* deleted.
* @param TaxonomyVocabulary $vocabulary
* The taxonomy vocabulary entity that is about to be deleted.
*
* @see hook_taxonomy_vocabulary_delete()
* @see taxonomy_vocabulary_delete()
*/
function hook_taxonomy_vocabulary_predelete($vocabulary) {
function hook_taxonomy_vocabulary_predelete(TaxonomyVocabulary $vocabulary) {
if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) {
variable_del('taxonomy_' . $vocabulary->vid . '_synonyms');
}
......@@ -96,13 +95,13 @@ function hook_taxonomy_vocabulary_predelete($vocabulary) {
* field_attach_delete_bundle() has been called and after the vocabulary has
* been removed from the database.
*
* @param $vocabulary
* The taxonomy vocabulary object for the vocabulary that has been deleted.
* @param TaxonomyVocabulary $vocabulary
* The taxonomy vocabulary entity that has been deleted.
*
* @see hook_taxonomy_vocabulary_predelete()
* @see taxonomy_vocabulary_delete()
*/
function hook_taxonomy_vocabulary_delete($vocabulary) {
function hook_taxonomy_vocabulary_delete(TaxonomyVocabulary $vocabulary) {
if (variable_get('taxonomy_' . $vocabulary->vid . '_synonyms', FALSE)) {
variable_del('taxonomy_' . $vocabulary->vid . '_synonyms');
}
......@@ -121,10 +120,10 @@ function hook_taxonomy_vocabulary_delete($vocabulary) {
* altering properties provided by the {taxonomy_term_data} table, since this
* may affect the way results are loaded from cache in subsequent calls.
*
* @param $terms
* An array of term objects, indexed by tid.
* @param array $terms
* An array of taxonomy term entities, indexed by tid.
*/
function hook_taxonomy_term_load($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)));
foreach ($result as $record) {
$terms[$record->tid]->foo = $record->foo;
......@@ -137,10 +136,10 @@ function hook_taxonomy_term_load($terms) {
* Modules implementing this hook can act on the term object before it is
* inserted or updated.
*
* @param $term
* A term object.
* @param TaxonomyTerm $term
* A taxonomy term entity.
*/
function hook_taxonomy_term_presave($term) {
function hook_taxonomy_term_presave(TaxonomyTerm $term) {
$term->foo = 'bar';
}
......@@ -150,10 +149,10 @@ function hook_taxonomy_term_presave($term) {
* Modules implementing this hook can act on the term object when saved to
* the database.
*
* @param $term
* A taxonomy term object.
* @param TaxonomyTerm $term
* A taxonomy term entity.
*/
function hook_taxonomy_term_insert($term) {
function hook_taxonomy_term_insert(TaxonomyTerm $term) {
if (!empty($term->synonyms)) {
foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) {
if ($synonym) {
......@@ -173,10 +172,10 @@ function hook_taxonomy_term_insert($term) {
*
* Modules implementing this hook can act on the term object when updated.
*
* @param $term
* A taxonomy term object.
* @param TaxonomyTerm $term
* A taxonomy term entity.
*/
function hook_taxonomy_term_update($term) {
function hook_taxonomy_term_update(TaxonomyTerm $term) {
hook_taxonomy_term_delete($term);
if (!empty($term->synonyms)) {
foreach (explode ("\n", str_replace("\r", '', $term->synonyms)) as $synonym) {
......@@ -199,12 +198,12 @@ function hook_taxonomy_term_update($term) {
* field_attach_delete() is called and before the term is actually removed from
* the database.
*
* @param $term
* The taxonomy term object for the term that is about to be deleted.
* @param TaxonomyTerm $term
* The taxonomy term entity that is about to be deleted.
*
* @see taxonomy_term_delete()
*/
function hook_taxonomy_term_predelete($term) {
function hook_taxonomy_term_predelete(TaxonomyTerm $term) {
db_delete('term_synoynm')->condition('tid', $term->tid)->execute();
}
......@@ -214,12 +213,12 @@ function hook_taxonomy_term_predelete($term) {
* This hook is invoked from taxonomy_term_delete() after field_attach_delete()
* has been called and after the term has been removed from the database.
*
* @param $term
* The taxonomy term object for the term that has been deleted.
* @param TaxonomyTerm $term
* The taxonomy term entity that has been deleted.
*
* @see taxonomy_term_delete()
*/
function hook_taxonomy_term_delete($term) {
function hook_taxonomy_term_delete(TaxonomyTerm $term) {
db_delete('term_synoynm')->condition('tid', $term->tid)->execute();
}
......@@ -237,7 +236,7 @@ function hook_taxonomy_term_delete($term) {
* documentation respectively for details.
*
* @param $build
* A renderable array representing the node content.
* A renderable array representing the taxonomy term content.
*
* @see hook_entity_view_alter()
*/
......@@ -248,7 +247,7 @@ function hook_taxonomy_term_view_alter(&$build) {
}
// Add a #post_render callback to act on the rendered HTML of the term.