Verified Commit cc05facb authored by Juraj Nemec's avatar Juraj Nemec
Browse files

Issue #873722 by ezheidtmann, aaron.r.carlton, catch, poker10, MaskyS,...

Issue #873722 by ezheidtmann, aaron.r.carlton, catch, poker10, MaskyS, damiankloip, naxoc: 'autocreate' == 0
parent ee6e6645
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -1513,7 +1513,7 @@ function taxonomy_field_validate($entity_type, $entity, $field, $instance, $lang
  // Build an array of existing term IDs so they can be loaded with
  // taxonomy_term_load_multiple();
  foreach ($items as $delta => $item) {
    if (!empty($item['tid']) && $item['tid'] != 'autocreate') {
    if (!empty($item['tid']) && $item['tid'] !== 'autocreate') {
      $tids[] = $item['tid'];
    }
  }
@@ -1524,7 +1524,7 @@ function taxonomy_field_validate($entity_type, $entity, $field, $instance, $lang
    // allowed values for this field.
    foreach ($items as $delta => $item) {
      $validate = TRUE;
      if (!empty($item['tid']) && $item['tid'] != 'autocreate') {
      if (!empty($item['tid']) && $item['tid'] !== 'autocreate') {
        $validate = FALSE;
        foreach ($field['settings']['allowed_values'] as $settings) {
          // If no parent is specified, check if the term is in the vocabulary.
@@ -1600,7 +1600,7 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance,
  switch ($display['type']) {
    case 'taxonomy_term_reference_link':
      foreach ($items as $delta => $item) {
        if ($item['tid'] == 'autocreate') {
        if ($item['tid'] === 'autocreate') {
          $element[$delta] = array(
            '#markup' => check_plain($item['name']),
          );
@@ -1620,7 +1620,7 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance,

    case 'taxonomy_term_reference_plain':
      foreach ($items as $delta => $item) {
        $name = ($item['tid'] != 'autocreate' ? $item['taxonomy_term']->name : $item['name']);
        $name = ($item['tid'] !== 'autocreate' ? $item['taxonomy_term']->name : $item['name']);
        $element[$delta] = array(
          '#markup' => check_plain($name),
        );
@@ -1631,9 +1631,9 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance,
      foreach ($items as $delta => $item) {
        $entity->rss_elements[] = array(
          'key' => 'category',
          'value' => $item['tid'] != 'autocreate' ? $item['taxonomy_term']->name : $item['name'],
          'value' => $item['tid'] !== 'autocreate' ? $item['taxonomy_term']->name : $item['name'],
          'attributes' => array(
            'domain' => $item['tid'] != 'autocreate' ? url('taxonomy/term/' . $item['tid'], array('absolute' => TRUE)) : '',
            'domain' => $item['tid'] !== 'autocreate' ? url('taxonomy/term/' . $item['tid'], array('absolute' => TRUE)) : '',
          ),
        );
      }
@@ -1678,7 +1678,7 @@ function taxonomy_field_formatter_prepare_view($entity_type, $entities, $field,
  foreach ($entities as $id => $entity) {
    foreach ($items[$id] as $delta => $item) {
      // Force the array key to prevent duplicates.
      if ($item['tid'] != 'autocreate') {
      if ($item['tid'] !== 'autocreate') {
        $tids[$item['tid']] = $item['tid'];
      }
    }
@@ -1697,7 +1697,7 @@ function taxonomy_field_formatter_prepare_view($entity_type, $entities, $field,
          $items[$id][$delta]['taxonomy_term'] = $terms[$item['tid']];
        }
        // Terms to be created are not in $terms, but are still legitimate.
        elseif ($item['tid'] == 'autocreate') {
        elseif ($item['tid'] === 'autocreate') {
          // Leave the item in place.
        }
        // Otherwise, unset the instance value, since the term does not exist.
@@ -1901,7 +1901,7 @@ function taxonomy_rdf_mapping() {
 */
function taxonomy_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
  foreach ($items as $delta => $item) {
    if ($item['tid'] == 'autocreate') {
    if ($item['tid'] === 'autocreate') {
      $term = (object) $item;
      unset($term->tid);
      taxonomy_term_save($term);
+15 −0
Original line number Diff line number Diff line
@@ -1633,6 +1633,21 @@ class TaxonomyTermFieldTestCase extends TaxonomyWebTestCase {
    $this->assertEqual($allowed_values[2]['vocabulary'], 'foo', 'Index 2: Machine name was left untouched.');
  }

  /**
   * Test empty taxonomy term reference field.
   */
  function testEmptyTaxonomyTermReferenceField() {
    // Test if an empty value in the taxonomy reference field would trigger
    // autocreate or if the value would be saved correctly.
    $langcode = LANGUAGE_NONE;
    $entity = field_test_create_stub_entity(NULL, NULL);
    $entity->{$this->field_name}[$langcode][0]['tid'] = 0;
    field_test_entity_save($entity);
    $entity = field_test_entity_test_load($entity->ftid);
    field_test_entity_save($entity);
    $this->pass('Empty term ID does not trigger autocreate.');
  }

}

/**