Commit 5eff1db9 authored by alexpott's avatar alexpott

Issue #1981336 by aspilicious, andypost, swentel, amateescu: Drop procedural...

Issue #1981336 by aspilicious, andypost, swentel, amateescu: Drop procedural usage of fields in [t*] modules.
parent 2de46154
......@@ -126,7 +126,7 @@ public function postSave(EntityStorageControllerInterface $storage_controller, $
}
}
if ($update_field) {
field_update_field($field);
$field->save();
}
}
}
......@@ -167,11 +167,11 @@ public static function postDelete(EntityStorageControllerInterface $storage_cont
}
if ($modified_field) {
if (empty($taxonomy_field['settings']['allowed_values'])) {
field_delete_field($field_name);
$taxonomy_field->delete();
}
else {
// Update the field definition with the new allowed values.
field_update_field($taxonomy_field);
$taxonomy_field->save();
}
}
}
......
......@@ -35,9 +35,10 @@ function setUp() {
$this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'bypass node access', 'administer content types', 'administer node display'));
$this->drupalLogin($this->admin_user);
$this->vocabulary = $this->createVocabulary();
$this->field_name = 'taxonomy_' . $this->vocabulary->id();
$field = array(
'field_name' => 'taxonomy_' . $this->vocabulary->id(),
$this->field = entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => 'taxonomy_term_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'settings' => array(
......@@ -48,22 +49,20 @@ function setUp() {
),
),
),
);
field_create_field($field);
$this->instance = array(
'field_name' => 'taxonomy_' . $this->vocabulary->id(),
));
$this->field->save();
entity_create('field_instance', array(
'field_name' => $this->field_name,
'bundle' => 'article',
'entity_type' => 'node',
);
field_create_instance($this->instance);
))->save();
entity_get_form_display('node', 'article', 'default')
->setComponent($field['field_name'], array(
->setComponent($this->field_name, array(
'type' => 'options_select',
))
->save();
entity_get_display('node', 'article', 'default')
->setComponent('taxonomy_' . $this->vocabulary->id(), array(
->setComponent($this->field_name, array(
'type' => 'taxonomy_term_reference_link',
))
->save();
......@@ -96,7 +95,7 @@ function testTaxonomyRss() {
$edit = array();
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$edit["title"] = $this->randomName();
$edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->id();
$edit[$this->field_name . '[' . $langcode . '][]'] = $term1->id();
$this->drupalPost('node/add/article', $edit, t('Save'));
// Check that the term is displayed when the RSS feed is viewed.
......
......@@ -43,7 +43,8 @@ public function setUp() {
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
));
$vocabulary->save();
$field = array(
entity_create('field_entity', array(
'field_name' => 'field_test_taxonomy',
'type' => 'taxonomy_term_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
......@@ -55,14 +56,12 @@ public function setUp() {
),
),
),
);
field_create_field($field);
$instance = array(
))->save();
entity_create('field_instance', array(
'entity_type' => 'entity_test',
'field_name' => 'field_test_taxonomy',
'bundle' => 'entity_test',
);
field_create_instance($instance);
))->save();
$this->term = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'vid' => $vocabulary->id(),
......
......@@ -21,7 +21,6 @@ class TermFieldMultipleVocabularyTest extends TaxonomyTestBase {
*/
public static $modules = array('entity_test');
protected $instance;
protected $vocabulary1;
protected $vocabulary2;
......@@ -43,7 +42,7 @@ function setUp() {
// Set up a field and instance.
$this->field_name = drupal_strtolower($this->randomName());
$this->field = array(
entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => 'taxonomy_term_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
......@@ -59,14 +58,12 @@ function setUp() {
),
),
)
);
field_create_field($this->field);
$this->instance = array(
))->save();
entity_create('field_instance', array(
'field_name' => $this->field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
field_create_instance($this->instance);
))->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($this->field_name, array(
'type' => 'options_select',
......
......@@ -46,7 +46,7 @@ function setUp() {
// Setup a field and instance.
$this->field_name = drupal_strtolower($this->randomName());
$this->field = array(
$this->field = entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => 'taxonomy_term_reference',
'settings' => array(
......@@ -57,14 +57,13 @@ function setUp() {
),
),
)
);
field_create_field($this->field);
$this->instance = array(
));
$this->field->save();
entity_create('field_instance', array(
'field_name' => $this->field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
field_create_instance($this->instance);
))->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($this->field_name, array(
'type' => 'options_select',
......@@ -150,7 +149,7 @@ function testTaxonomyTermFieldWidgets() {
function testTaxonomyTermFieldChangeMachineName() {
// Add several entries in the 'allowed_values' setting, to make sure that
// they all get updated.
$this->field['settings']['allowed_values'] = array(
$this->field->settings['allowed_values'] = array(
array(
'vocabulary' => $this->vocabulary->id(),
'parent' => '0',
......@@ -164,7 +163,7 @@ function testTaxonomyTermFieldChangeMachineName() {
'parent' => '0',
),
);
field_update_field($this->field);
$this->field->save();
// Change the machine name.
$new_name = drupal_strtolower($this->randomName());
$this->vocabulary->vid = $new_name;
......
......@@ -33,7 +33,7 @@ function setUp() {
$this->vocabulary = $this->createVocabulary();
$this->field_name_1 = drupal_strtolower($this->randomName());
$this->field_1 = array(
entity_create('field_entity', array(
'field_name' => $this->field_name_1,
'type' => 'taxonomy_term_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
......@@ -45,14 +45,12 @@ function setUp() {
),
),
),
);
field_create_field($this->field_1);
$this->instance_1 = array(
))->save();
entity_create('field_instance', array(
'field_name' => $this->field_name_1,
'bundle' => 'article',
'entity_type' => 'node',
);
field_create_instance($this->instance_1);
))->save();
entity_get_form_display('node', 'article', 'default')
->setComponent($this->field_name_1, array(
'type' => 'options_select',
......@@ -65,7 +63,7 @@ function setUp() {
->save();
$this->field_name_2 = drupal_strtolower($this->randomName());
$this->field_2 = array(
entity_create('field_entity', array(
'field_name' => $this->field_name_2,
'type' => 'taxonomy_term_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
......@@ -77,14 +75,12 @@ function setUp() {
),
),
),
);
field_create_field($this->field_2);
$this->instance_2 = array(
))->save();
entity_create('field_instance', array(
'field_name' => $this->field_name_2,
'bundle' => 'article',
'entity_type' => 'node',
);
field_create_instance($this->instance_2);
))->save();
entity_get_form_display('node', 'article', 'default')
->setComponent($this->field_name_2, array(
'type' => 'options_select',
......
......@@ -41,14 +41,14 @@ function setUp() {
),
),
);
field_create_field($field);
entity_create('field_entity', $field)->save();
$this->instance = array(
$this->instance = entity_create('field_instance', array(
'field_name' => 'taxonomy_' . $this->vocabulary->id(),
'bundle' => 'article',
'entity_type' => 'node',
);
field_create_instance($this->instance);
));
$this->instance->save();
entity_get_form_display('node', 'article', 'default')
->setComponent('taxonomy_' . $this->vocabulary->id(), array(
'type' => 'options_select',
......
......@@ -28,9 +28,9 @@ function setUp() {
$this->drupalLogin($this->admin_user);
$this->vocabulary = $this->createVocabulary();
$this->langcode = Language::LANGCODE_NOT_SPECIFIED;
$field = array(
'field_name' => 'taxonomy_' . $this->vocabulary->id(),
$this->field_name = 'taxonomy_' . $this->vocabulary->id();
entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => 'taxonomy_term_reference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
'settings' => array(
......@@ -41,22 +41,20 @@ function setUp() {
),
),
),
);
field_create_field($field);
))->save();
$this->instance = array(
'field_name' => 'taxonomy_' . $this->vocabulary->id(),
entity_create('field_instance', array(
'field_name' => $this->field_name,
'bundle' => 'article',
'entity_type' => 'node',
);
field_create_instance($this->instance);
))->save();
entity_get_form_display('node', 'article', 'default')
->setComponent('taxonomy_' . $this->vocabulary->id(), array(
->setComponent($this->field_name, array(
'type' => 'options_select',
))
->save();
entity_get_display('node', 'article', 'default')
->setComponent('taxonomy_' . $this->vocabulary->id(), array(
->setComponent($this->field_name, array(
'type' => 'taxonomy_term_reference_link',
))
->save();
......@@ -82,7 +80,7 @@ function testTaxonomyTokenReplacement() {
// Create node with term2.
$edit = array();
$node = $this->drupalCreateNode(array('type' => 'article'));
$edit[$this->instance['field_name'] . '[' . $this->langcode . '][]'] = $term2->id();
$edit[$this->field_name . '[' . $this->langcode . '][]'] = $term2->id();
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
// Generate and test sanitized tokens for term1.
......
......@@ -81,8 +81,9 @@ protected function mockStandardInstall() {
'vid' => 'views_testing_tags',
));
$this->vocabulary->save();
$field = array(
'field_name' => 'field_' . $this->vocabulary->id(),
$this->field_name = 'field_' . $this->vocabulary->id();
entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => 'taxonomy_term_reference',
// Set cardinality to unlimited for tagging.
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
......@@ -94,31 +95,29 @@ protected function mockStandardInstall() {
),
),
),
);
field_create_field($field);
$instance = array(
'field_name' => 'field_' . $this->vocabulary->id(),
))->save();
$instance = entity_create('field_instance', array(
'field_name' => $this->field_name,
'entity_type' => 'node',
'label' => 'Tags',
'bundle' => 'article',
);
field_create_instance($instance);
))->save();
entity_get_form_display('node', 'article', 'default')
->setComponent($instance['field_name'], array(
->setComponent($this->field_name, array(
'type' => 'taxonomy_autocomplete',
'weight' => -4,
))
->save();
entity_get_display('node', 'article', 'default')
->setComponent($instance['field_name'], array(
->setComponent($this->field_name, array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
))
->save();
entity_get_display('node', 'article', 'teaser')
->setComponent($instance['field_name'], array(
->setComponent($this->field_name, array(
'type' => 'taxonomy_term_reference_link',
'weight' => 10,
))
......
......@@ -154,17 +154,15 @@ function testTaxonomyVocabularyLoadMultiple() {
*/
function testTaxonomyVocabularyChangeMachineName() {
// Add a field instance to the vocabulary.
$field = array(
entity_create('field_entity', array(
'field_name' => 'field_test',
'type' => 'test_field',
);
field_create_field($field);
$instance = array(
))->save();
entity_create('field_instance', array(
'field_name' => 'field_test',
'entity_type' => 'taxonomy_term',
'bundle' => $this->vocabulary->id(),
);
field_create_instance($instance);
))->save();
// Change the machine name.
$old_name = $this->vocabulary->id();
......@@ -188,15 +186,19 @@ function testUninstallReinstall() {
// Fields and field instances attached to taxonomy term bundles should be
// removed when the module is uninstalled.
$this->field_name = drupal_strtolower($this->randomName() . '_field_name');
$this->field_definition = array('field_name' => $this->field_name, 'type' => 'text', 'cardinality' => 4);
field_create_field($this->field_definition);
$this->field_definition = array(
'field_name' => $this->field_name,
'type' => 'text',
'cardinality' => 4
);
entity_create('field_entity', $this->field_definition)->save();
$this->instance_definition = array(
'field_name' => $this->field_name,
'entity_type' => 'taxonomy_term',
'bundle' => $this->vocabulary->id(),
'label' => $this->randomName() . '_label',
);
field_create_instance($this->instance_definition);
entity_create('field_instance', $this->instance_definition)->save();
module_disable(array('taxonomy'));
require_once DRUPAL_ROOT . '/core/includes/install.inc';
......@@ -209,7 +211,7 @@ function testUninstallReinstall() {
// an instance of this field on the same bundle name should be successful.
$this->vocabulary->enforceIsNew();
$this->vocabulary->save();
field_create_field($this->field_definition);
field_create_instance($this->instance_definition);
entity_create('field_entity', $this->field_definition)->save();
entity_create('field_instance', $this->instance_definition)->save();
}
}
......@@ -53,19 +53,16 @@ function setUp() {
function testTelephoneField() {
// Add the telepone field to the article content type.
$field = array(
entity_create('field_entity', array(
'field_name' => 'field_telephone',
'type' => 'telephone',
);
field_create_field($field);
$instance = array(
))->save();
entity_create('field_instance', array(
'field_name' => 'field_telephone',
'label' => 'Telephone Number',
'entity_type' => 'node',
'bundle' => 'article',
);
field_create_instance($instance);
))->save();
entity_get_form_display('node', 'article', 'default')
->setComponent('field_telephone', array(
......
......@@ -35,17 +35,15 @@ public function setUp() {
parent::setUp();
// Create a telephone field and instance for validation.
$this->field = array(
entity_create('field_entity', array(
'field_name' => 'field_test',
'type' => 'telephone',
);
field_create_field($this->field);
$this->instance = array(
))->save();
entity_create('field_instance', array(
'entity_type' => 'entity_test',
'field_name' => 'field_test',
'bundle' => 'entity_test',
);
field_create_instance($this->instance);
))->save();
}
/**
......
......@@ -67,21 +67,21 @@ function setUp() {
$this->formatter_type = 'text_plain';
$this->formatter_settings = array();
$this->field = array(
$this->field = entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => $this->field_type,
'settings' => $this->field_settings,
);
$this->field = field_create_field($this->field);
));
$this->field->save();
$this->instance = array(
$this->instance = entity_create('field_instance', array(
'entity_type' => $this->entity_type,
'bundle' => $this->bundle,
'field_name' => $this->field_name,
'label' => $this->randomName(),
'settings' => $this->instance_settings,
);
$this->instance = field_create_instance($this->instance);
));
$this->instance->save();
$this->view_mode = 'default';
$this->display = entity_get_display($this->entity_type, $this->bundle, $this->view_mode)
......
......@@ -23,7 +23,6 @@ class TextFieldTest extends WebTestBase {
*/
public static $modules = array('entity_test');
protected $instance;
protected $admin_user;
protected $web_user;
......@@ -51,26 +50,25 @@ function setUp() {
function testTextFieldValidation() {
// Create a field with settings to validate.
$max_length = 3;
$this->field = array(
$this->field = entity_create('field_entity', array(
'field_name' => drupal_strtolower($this->randomName()),
'type' => 'text',
'settings' => array(
'max_length' => $max_length,
)
);
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field['field_name'],
));
$this->field->save();
entity_create('field_instance', array(
'field_name' => $this->field->id(),
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
field_create_instance($this->instance);
))->save();
// Test valid and invalid values with field_attach_validate().
$entity = entity_create('entity_test', array());
$langcode = Language::LANGCODE_NOT_SPECIFIED;
for ($i = 0; $i <= $max_length + 2; $i++) {
$entity->{$this->field['field_name']}->value = str_repeat('x', $i);
$entity->{$this->field->id()}->value = str_repeat('x', $i);
try {
field_attach_validate($entity);
$this->assertTrue($i <= $max_length, "Length $i does not cause validation error when max_length is $max_length");
......@@ -96,9 +94,12 @@ function _testTextfieldWidgets($field_type, $widget_type) {
// Setup a field and instance
$entity_type = 'entity_test';
$this->field_name = drupal_strtolower($this->randomName());
$this->field = array('field_name' => $this->field_name, 'type' => $field_type);
field_create_field($this->field);
$this->instance = array(
$this->field = entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => $field_type
));
$this->field->save();
entity_create('field_instance', array(
'field_name' => $this->field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
......@@ -106,8 +107,7 @@ function _testTextfieldWidgets($field_type, $widget_type) {
'settings' => array(
'text_processing' => TRUE,
),
);
field_create_instance($this->instance);
))->save();
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($this->field_name, array(
'type' => $widget_type,
......@@ -162,9 +162,12 @@ function testTextfieldWidgetsFormatted() {
function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
// Setup a field and instance
$this->field_name = drupal_strtolower($this->randomName());
$this->field = array('field_name' => $this->field_name, 'type' => $field_type);
field_create_field($this->field);
$this->instance = array(
$this->field = entity_create('field_entity', array(
'field_name' => $this->field_name,
'type' => $field_type
));
$this->field->save();
entity_create('field_instance', array(
'field_name' => $this->field_name,
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
......@@ -172,8 +175,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) {
'settings' => array(
'text_processing' => TRUE,
),
);
field_create_instance($this->instance);
))->save();
entity_get_form_display('entity_test', 'entity_test', 'default')