Commit a6a4adc9 authored by alexpott's avatar alexpott

Issue #1981316 by aspilicious, andypost, pcambra, swentel: Drop procedural...

Issue #1981316 by aspilicious, andypost, pcambra, swentel: Drop procedural usage of fields in [f-l] modules.
parent db0e9117
......@@ -67,14 +67,15 @@ function getLastFileId() {
* A list of widget settings that will be added to the widget defaults.
*/
function createFileField($name, $type_name, $field_settings = array(), $instance_settings = array(), $widget_settings = array()) {
$field = array(
$field_definition = array(
'field_name' => $name,
'type' => 'file',
'settings' => array(),
'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1,
);
$field['settings'] = array_merge($field['settings'], $field_settings);
$field = field_create_field($field);
$field_definition['settings'] = array_merge($field_definition['settings'], $field_settings);
$field = entity_create('field_entity', $field_definition);
$field->save();
$this->attachFileField($name, 'node', $type_name, $instance_settings, $widget_settings);
return $field;
......@@ -106,7 +107,7 @@ function attachFileField($name, $entity_type, $bundle, $instance_settings = arra
'settings' => array(),
);
$instance['settings'] = array_merge($instance['settings'], $instance_settings);
field_create_instance($instance);
entity_create('field_instance', $instance)->save();
entity_get_form_display($entity_type, $bundle, 'default')
->setComponent($name, array(
......@@ -123,7 +124,7 @@ function updateFileField($name, $type_name, $instance_settings = array(), $widge
$instance = field_info_instance('node', $name, $type_name);
$instance['settings'] = array_merge($instance['settings'], $instance_settings);
field_update_instance($instance);
$instance->save();
entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')
->setComponent($instance['field_name'], array(
......@@ -238,4 +239,5 @@ function assertFileIsPermanent(FileInterface $file, $message = NULL) {
$message = isset($message) ? $message : t('File %file is permanent.', array('%file' => $file->getFileUri()));
$this->assertTrue($file->isPermanent(), $message);
}
}
......@@ -52,7 +52,7 @@ function testRequired() {
$this->assertFileEntryExists($node_file, t('File entry exists after uploading to the required field.'));
// Try again with a multiple value field.
field_delete_field($field_name);
$field->delete();
$this->createFileField($field_name, $type_name, array('cardinality' => FIELD_CARDINALITY_UNLIMITED), array('required' => '1'));
// Try to post a new node without uploading a file in the multivalue field.
......@@ -153,4 +153,5 @@ function testFileExtension() {
$this->assertFileExists($node_file, t('File exists after uploading a file with extension checking.'));
$this->assertFileEntryExists($node_file, t('File entry exists after uploading a file with extension checking.'));
}
}
......@@ -44,18 +44,16 @@ public function setUp() {
$this->installSchema('file', 'file_managed');
$this->installSchema('file', 'file_usage');
$field = array(
entity_create('field_entity', array(
'field_name' => 'file_test',
'type' => 'file',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
field_create_field($field);
$instance = array(
))->save();
entity_create('field_instance', array(
'entity_type' => 'entity_test',
'field_name' => 'file_test',
'bundle' => 'entity_test',
);
field_create_instance($instance);
))->save();
file_put_contents('public://example.txt', $this->randomName());
$this->file = entity_create('file', array(
'uri' => 'public://example.txt',
......
......@@ -53,7 +53,7 @@ function forum_enable() {
// is being enabled at the same time as taxonomy after both modules have been
// enabled, the field might exist but still be marked inactive.
if (!field_read_field('taxonomy_forums', array('include_inactive' => TRUE))) {
$field = array(
entity_create('field_entity', array(
'field_name' => 'taxonomy_forums',
'type' => 'taxonomy_term_reference',
'settings' => array(
......@@ -64,8 +64,7 @@ function forum_enable() {
),
),
),
);
field_create_field($field);
))->save();
// Create a default forum so forum posts can be created.
$term = entity_create('taxonomy_term', array(
......@@ -78,14 +77,13 @@ function forum_enable() {
$term->save();
// Create the instance on the bundle.
$instance = array(
entity_create('field_instance', array(
'field_name' => 'taxonomy_forums',
'entity_type' => 'node',
'label' => $vocabulary->name,
'bundle' => 'forum',
'required' => TRUE,
);
field_create_instance($instance);
))->save();
// Assign form display settings for the 'default' form mode.
entity_get_form_display('node', 'forum', 'default')
......@@ -124,7 +122,7 @@ function forum_uninstall() {
variable_del('node_options_forum');
field_delete_field('taxonomy_forums');
field_info_field('taxonomy_forums')->delete();
// Purge field data now to allow taxonomy module to be uninstalled
// if this is the only field remaining.
field_purge_batch(10);
......
......@@ -78,49 +78,43 @@ function setUp() {
language_save($german);
// Create the test text field.
$field = array(
entity_create('field_entity', array(
'field_name' => 'field_test_text',
'type' => 'text',
'translatable' => FALSE,
);
field_create_field($field);
$instance = array(
))->save();
entity_create('field_instance', array(
'entity_type' => 'entity_test',
'field_name' => 'field_test_text',
'bundle' => 'entity_test',
);
field_create_instance($instance);
))->save();
// Create the test translatable field.
$field = array(
entity_create('field_entity', array(
'field_name' => 'field_test_translatable_text',
'type' => 'text',
'translatable' => TRUE,
);
field_create_field($field);
$instance = array(
))->save();
entity_create('field_instance', array(
'entity_type' => 'entity_test',
'field_name' => 'field_test_translatable_text',
'bundle' => 'entity_test',
);
field_create_instance($instance);
))->save();
// Create the test entity reference field.
$field = array(
entity_create('field_entity', array(
'translatable' => TRUE,
'settings' => array(
'target_type' => 'entity_test',
),
'field_name' => 'field_test_entity_reference',
'type' => 'entity_reference',
);
field_create_field($field);
$instance = array(
))->save();
entity_create('field_instance', array(
'entity_type' => 'entity_test',
'field_name' => 'field_test_entity_reference',
'bundle' => 'entity_test',
);
field_create_instance($instance);
))->save();
// Set up the mock serializer.
$normalizers = array(
......
......@@ -51,30 +51,28 @@ function testDefaultImages() {
$widget_settings = array(
'preview_image_style' => 'medium',
);
$this->createImageField($field_name, 'article', $field_settings, $instance_settings, $widget_settings);
$instance = $this->createImageField($field_name, 'article', $field_settings, $instance_settings, $widget_settings);
$field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, 'article');
// Add another instance with another default image to the page content type.
$instance2 = array(
'field_name' => $field['field_name'],
$instance2 = entity_create('field_instance', array(
'field_name' => $field->id(),
'entity_type' => 'node',
'bundle' => 'page',
'label' => $instance['label'],
'required' => $instance['required'],
'label' => $instance->label(),
'required' => $instance->required,
'settings' => array(
'default_image' => $default_images['instance2']->id(),
),
);
field_create_instance($instance2);
$instance2 = field_info_instance('node', $field_name, 'page');
));
$instance2->save();
$widget_settings = entity_get_form_display($instance['entity_type'], $instance['bundle'], 'default')->getComponent($field['field_name']);
entity_get_form_display('node', 'page', 'default')
->setComponent($field['field_name'], $widget_settings)
->setComponent($field->id(), $widget_settings)
->save();
entity_get_display('node', 'page', 'default')
->setComponent($field['field_name'])
->setComponent($field->id())
->save();
// Confirm the defaults are present on the article field settings form.
......@@ -145,7 +143,7 @@ function testDefaultImages() {
// Upload a new default for the field.
$field['settings']['default_image'] = array($default_images['field_new']->id());
field_update_field($field);
$field->save();
// Confirm that the new default is used on the article field settings form.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id/field");
......@@ -180,7 +178,7 @@ function testDefaultImages() {
// Upload a new default for the article's field instance.
$instance['settings']['default_image'] = $default_images['instance_new']->id();
field_update_instance($instance);
$instance->save();
// Confirm the new field instance default is used on the article field
// admin form.
......@@ -219,7 +217,7 @@ function testDefaultImages() {
// Remove the instance default from articles.
$instance['settings']['default_image'] = 0;
field_update_instance($instance);
$instance->save();
// Confirm the article field instance default has been removed.
$this->drupalGet("admin/structure/types/manage/article/fields/$instance->id");
......@@ -251,4 +249,5 @@ function testDefaultImages() {
)
);
}
}
......@@ -76,7 +76,7 @@ function createImageField($name, $type_name, $field_settings = array(), $instanc
'cardinality' => !empty($field_settings['cardinality']) ? $field_settings['cardinality'] : 1,
);
$field['settings'] = array_merge($field['settings'], $field_settings);
field_create_field($field);
entity_create('field_entity', $field)->save();
$instance = array(
'field_name' => $field['field_name'],
......@@ -88,7 +88,8 @@ function createImageField($name, $type_name, $field_settings = array(), $instanc
'settings' => array(),
);
$instance['settings'] = array_merge($instance['settings'], $instance_settings);
$field_instance = field_create_instance($instance);
$field_instance = entity_create('field_instance', $instance);
$field_instance->save();
entity_get_form_display('node', $type_name, 'default')
->setComponent($field['field_name'], array(
......@@ -127,4 +128,5 @@ function uploadNodeImage($image, $field_name, $type) {
preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches);
return isset($matches[1]) ? $matches[1] : FALSE;
}
}
......@@ -43,18 +43,16 @@ public function setUp() {
$this->installSchema('file', array('file_managed', 'file_usage'));
$field = array(
entity_create('field_entity', array(
'field_name' => 'image_test',
'type' => 'image',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
field_create_field($field);
$instance = array(
))->save();
entity_create('field_instance', array(
'entity_type' => 'entity_test',
'field_name' => 'image_test',
'bundle' => 'entity_test',
);
field_create_instance($instance);
))->save();
file_unmanaged_copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = entity_create('file', array(
'uri' => 'public://example.jpg',
......
......@@ -35,17 +35,15 @@ public function setUp() {
parent::setUp();
// Create an link field and instance for validation.
$this->field = array(
entity_create('field_entity', array(
'field_name' => 'field_test',
'type' => 'link',
);
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();
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment