diff --git a/core/modules/entity/entity.class.inc b/core/modules/entity/entity.class.inc index f1c7048..1f97acd 100644 --- a/core/modules/entity/entity.class.inc +++ b/core/modules/entity/entity.class.inc @@ -193,8 +193,8 @@ class Entity implements EntityInterface { * 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 pre-set to TRUE. + // We support creating entities with pre-defined IDs to ease migrations by + // pre-setting the "is_new" property to TRUE. // Otherwise, set the "is_new" property based on whether there is an ID, // so especially preSave() and postSave() can rely on the value during // saving of the entity. diff --git a/core/modules/taxonomy/taxonomy.admin.inc b/core/modules/taxonomy/taxonomy.admin.inc index 132ee99..b268b40 100644 --- a/core/modules/taxonomy/taxonomy.admin.inc +++ b/core/modules/taxonomy/taxonomy.admin.inc @@ -101,29 +101,22 @@ function theme_taxonomy_overview_vocabularies($variables) { /** * Form builder for the vocabulary editing form. * + * @param TaxonomyVocabulary|null $vocabulary + * (optional) The TaxonomyVocabulary 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, $vocabulary = array()) { +function taxonomy_form_vocabulary($form, &$form_state, $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'])) { - if (!is_object($vocabulary) || !($vocabulary instanceof TaxonomyVocabulary)) { - $vocabulary = entity_create('taxonomy_vocabulary', (array) $vocabulary); - } - $defaults = array( - 'name' => '', - 'machine_name' => '', - 'description' => '', - 'hierarchy' => TAXONOMY_HIERARCHY_DISABLED, - 'weight' => 0, - ); - 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()); } $form_state['vocabulary'] = $vocabulary; } @@ -634,33 +627,30 @@ function theme_taxonomy_overview_terms($variables) { /** * Form function for the term edit form. * + * @param TaxonomyTerm|null $term + * (optional) The TaxonomyTerm entity to edit. If NULL or omitted, the + * form creates a new term. + * @param TaxonomyVocabulary|null $vocabulary + * (optional) A TaxonomyVocabulary entity to create the term in. + * * @ingroup forms + * @see taxonomy_form_term_validate() * @see taxonomy_form_term_submit() */ -function taxonomy_form_term($form, &$form_state, $term = array(), $vocabulary = NULL) { +function taxonomy_form_term($form, &$form_state, $term = NULL, $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'])) { - if (!is_object($term) || !($term instanceof TaxonomyTerm)) { - $term = entity_create('taxonomy_term', (array) $term); + // Create a new TaxonomyTerm entity for the add form. + if (!isset($term)) { + $term = entity_create('taxonomy_term', array( + 'vocabulary_machine_name' => isset($vocabulary) ? $vocabulary->machine_name : NULL, + )); } 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, - ); - foreach ($defaults as $key => $value) { - if (!isset($term->$key)) { - $term->$key = $value; - } - } $form_state['term'] = $term; } else { diff --git a/core/modules/taxonomy/taxonomy.entity.inc b/core/modules/taxonomy/taxonomy.entity.inc index a2164f9..ac656ff 100644 --- a/core/modules/taxonomy/taxonomy.entity.inc +++ b/core/modules/taxonomy/taxonomy.entity.inc @@ -47,8 +47,10 @@ class TaxonomyTerm extends Entity { /** * The weight of this term in relation to other terms of the same vocabulary. + * + * @var integer */ - public $weight; + public $weight = 0; } /** @@ -232,12 +234,14 @@ class TaxonomyVocabulary extends Entity { * * @var integer */ - public $hierarchy; + public $hierarchy = TAXONOMY_HIERARCHY_DISABLED; /** * The weight of this vocabulary in relation to other vocabularies. + * + * @var integer */ - public $weight; + public $weight = 0; } /** diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module index 020759b..9a6c0a1 100644 --- a/core/modules/taxonomy/taxonomy.module +++ b/core/modules/taxonomy/taxonomy.module @@ -365,7 +365,7 @@ function taxonomy_menu() { $items['admin/structure/taxonomy/%taxonomy_vocabulary_machine_name/add'] = array( 'title' => 'Add term', 'page callback' => 'drupal_get_form', - 'page arguments' => array('taxonomy_form_term', array(), 3), + 'page arguments' => array('taxonomy_form_term', NULL, 3), 'access arguments' => array('administer taxonomy'), 'type' => MENU_LOCAL_ACTION, 'file' => 'taxonomy.admin.inc', diff --git a/core/modules/taxonomy/taxonomy.test b/core/modules/taxonomy/taxonomy.test index fd903ee..a7abf44 100644 --- a/core/modules/taxonomy/taxonomy.test +++ b/core/modules/taxonomy/taxonomy.test @@ -1180,7 +1180,7 @@ class TaxonomyHooksTestCase extends TaxonomyWebTestCase { 'antonym' => 'Short', ); $this->drupalPost('taxonomy/term/' . $term->tid . '/edit', $edit, t('Save')); - entity_get_controller('taxonomy_term')->resetCache(array($term->tid)); + taxonomy_terms_static_reset(); $term = taxonomy_term_load($term->tid); $this->assertEqual($edit['antonym'], $term->antonym, t('Antonym was successfully edited'));