You are here

protected function Drupali18nSyncNodeReferenceTestCase::createNodeRefField in i18n node reference synch 7

Creates a node reference field to the specified types.

Parameters

array $target_types: The node types that can be targeted (for example: 'article').

string $field_name: The name of the field to be created.

string $widget: The widget to be used.

1 call to Drupali18nSyncNodeReferenceTestCase::createNodeRefField()
Drupali18nSyncNodeReferenceTestCase::setUp in ./i18n_node_reference.test
Sets up the tests.

File

./i18n_node_reference.test, line 234
Test node reference field synchronization.

Class

Drupali18nSyncNodeReferenceTestCase
Unit test for node reference field synchronisation.

Code

protected function createNodeRefField($target_types, $field_name, $widget = 'options_buttons') {
  $this->field = array(
    'field_name' => $field_name,
    'type' => 'node_reference',
    'cardinality' => -1,
    'settings' => array(
      'referenceable_types' => array(
        drupal_map_assoc($target_types),
      ),
    ),
  );
  field_create_field($this->field);
  $this->instance = array(
    'field_name' => $field_name,
    'entity_type' => 'node',
    'bundle' => 'page',
    'widget' => array(
      'type' => $widget,
    ),
    'display' => array(
      'default' => array(
        'type' => 'node_reference_default',
      ),
    ),
  );
  field_create_instance($this->instance);
}