function EditTestBase::createFieldWithInstance

Creates a field and an instance of it.

Parameters

string $field_name: The field name.

string $type: The field type.

int $cardinality: The field's cardinality.

string $label: The field's label (used everywhere: widget label, formatter label).

array $instance_settings:

string $widget_type: The widget type.

array $widget_settings: The widget settings.

string $formatter_type: The formatter type.

array $formatter_settings: The formatter settings.

6 calls to EditTestBase::createFieldWithInstance()
EditIntegrationTest::setUp in drupal/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php
Sets the default field storage backend for fields created during tests.
EditorSelectionTest::testNumber in drupal/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php
Tests a number field, with cardinality 1 and >1.
EditorSelectionTest::testText in drupal/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php
Tests a textual field, without/with text processing, with cardinality 1 and >1, always without a WYSIWYG editor present.
EditorSelectionTest::testTextWysiwyg in drupal/core/modules/edit/lib/Drupal/edit/Tests/EditorSelectionTest.php
Tests a textual field, with text processing, with cardinality 1 and >1, always with an Editor plugin present that supports textual fields with text processing, but with varying text format compatibility.
MetadataGeneratorTest::testEditorWithCustomMetadata in drupal/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php

... See full list

File

drupal/core/modules/edit/lib/Drupal/edit/Tests/EditTestBase.php, line 55
Contains \Drupal\edit\Tests\EditTestBase.

Class

EditTestBase
Parent class for Edit tests.

Namespace

Drupal\edit\Tests

Code

function createFieldWithInstance($field_name, $type, $cardinality, $label, $instance_settings, $widget_type, $widget_settings, $formatter_type, $formatter_settings) {
  $field = $field_name . '_field';
  $this->field = array(
    'field_name' => $field_name,
    'type' => $type,
    'cardinality' => $cardinality,
  );
  $this->{$field} = field_create_field($this->field);
  $instance = $field_name . '_instance';
  $this->{$instance} = array(
    'field_name' => $field_name,
    'entity_type' => 'entity_test',
    'bundle' => 'entity_test',
    'label' => $label,
    'description' => $label,
    'weight' => mt_rand(0, 127),
    'settings' => $instance_settings,
  );
  field_create_instance($this->{$instance});
  entity_get_form_display('entity_test', 'entity_test', 'default')
    ->setComponent($field_name, array(
    'type' => $widget_type,
    'label' => $label,
    'settings' => $widget_settings,
  ))
    ->save();
  entity_get_display('entity_test', 'entity_test', 'default')
    ->setComponent($field_name, array(
    'label' => 'above',
    'type' => $formatter_type,
    'settings' => $formatter_settings,
  ))
    ->save();
}