function restful_test_add_fields in RESTful 7.2
Same name and namespace in other branches
- 7 tests/modules/restful_test/restful_test.module \restful_test_add_fields()
Helper function to add common fields.
Parameters
string $entity_type: The entity type. Defautls to "entity_test".
string $bundle.: The bundle name. Defaults to "main".
Return value
int The vocabulary ID created.
10 calls to restful_test_add_fields()
- RestfulCreateEntityTestCase::setUp in tests/
RestfulCreateEntityTestCase.test - Sets up a Drupal site for running functional and integration tests.
- RestfulCreatePrivateNodeTestCase::setUp in tests/
RestfulCreatePrivateNodeTestCase.test - Sets up a Drupal site for running functional and integration tests.
- RestfulDiscoveryTestCase::testFieldDiscovery in tests/
RestfulDiscoveryTestCase.test - Field discovery.
- RestfulDiscoveryTestCase::testFieldDiscoveryAllowedValues in tests/
RestfulDiscoveryTestCase.test - Field discovery allowed values.
- RestfulForbiddenItemsTestCase::setUp in tests/
RestfulForbiddenItemsTestCase.test - Sets up a Drupal site for running functional and integration tests.
File
- tests/
modules/ restful_test/ restful_test.module, line 88 - Helper module for testing the RESTful module.
Code
function restful_test_add_fields($entity_type = 'entity_test', $bundle = 'main') {
// Text - single.
$field = array(
'field_name' => 'text_single',
'type' => 'text_long',
'entity_types' => array(
$entity_type,
),
'cardinality' => 1,
);
field_create_field($field);
$instance = array(
'field_name' => 'text_single',
'bundle' => $bundle,
'entity_type' => $entity_type,
'label' => t('Text single'),
'settings' => array(
// No text processing
'text_processing' => 0,
),
);
field_create_instance($instance);
// Text - single, with text processing.
$field = array(
'field_name' => 'text_single_processing',
'type' => 'text_long',
'entity_types' => array(
$entity_type,
),
'cardinality' => 1,
);
field_create_field($field);
$instance = array(
'field_name' => 'text_single_processing',
'bundle' => $bundle,
'entity_type' => $entity_type,
'label' => t('Text single with text processing'),
'settings' => array(
'text_processing' => 1,
),
);
field_create_instance($instance);
// Text - multiple.
$field = array(
'field_name' => 'text_multiple',
'type' => 'text_long',
'entity_types' => array(
$entity_type,
),
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
field_create_field($field);
$instance = array(
'field_name' => 'text_multiple',
'bundle' => $bundle,
'entity_type' => $entity_type,
'label' => t('Text multiple'),
'settings' => array(
'text_processing' => 0,
),
);
field_create_instance($instance);
// Text - multiple, with text processing.
$field = array(
'field_name' => 'text_multiple_processing',
'type' => 'text_long',
'entity_types' => array(
$entity_type,
),
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
field_create_field($field);
$instance = array(
'field_name' => 'text_multiple_processing',
'bundle' => $bundle,
'entity_type' => $entity_type,
'label' => t('Text multiple with text processing'),
'settings' => array(
'text_processing' => 1,
),
);
field_create_instance($instance);
// Entity reference - single.
$field = array(
'entity_types' => array(
$entity_type,
),
'settings' => array(
'handler' => 'base',
'target_type' => $entity_type,
'handler_settings' => array(),
),
'field_name' => 'entity_reference_single',
'type' => 'entityreference',
'cardinality' => 1,
);
field_create_field($field);
$instance = array(
'entity_type' => $entity_type,
'field_name' => 'entity_reference_single',
'bundle' => $bundle,
'label' => t('Entity reference single'),
);
field_create_instance($instance);
// Entity reference - multiple.
$field = array(
'entity_types' => array(
$entity_type,
),
'settings' => array(
'handler' => 'base',
'target_type' => $entity_type,
'handler_settings' => array(),
),
'field_name' => 'entity_reference_multiple',
'type' => 'entityreference',
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
field_create_field($field);
$instance = array(
'entity_type' => $entity_type,
'field_name' => 'entity_reference_multiple',
'bundle' => $bundle,
'label' => t('Entity reference multiple'),
);
field_create_instance($instance);
$vocabulary_id = restful_test_create_vocabulary_and_terms();
// Taxonomy term - single.
$field = array(
'field_name' => 'term_single',
'type' => 'taxonomy_term_reference',
'entity_types' => array(
$entity_type,
),
'cardinality' => 1,
);
field_create_field($field);
$instance = array(
'field_name' => 'term_single',
'bundle' => $bundle,
'entity_type' => $entity_type,
'label' => t('Term reference single'),
'settings' => array(
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary_id,
),
),
),
),
);
field_create_instance($instance);
// Taxonomy term - multiple.
$field = array(
'field_name' => 'term_multiple',
'type' => 'taxonomy_term_reference',
'entity_types' => array(
$entity_type,
),
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
field_create_field($field);
$instance = array(
'field_name' => 'term_multiple',
'bundle' => $bundle,
'entity_type' => $entity_type,
'label' => t('Term reference multiple'),
'settings' => array(
'settings' => array(
'allowed_values' => array(
array(
'vocabulary' => $vocabulary_id,
),
),
),
),
);
field_create_instance($instance);
// File field - single.
$field = array(
'field_name' => 'file_single',
'type' => 'file',
'settings' => array(),
'cardinality' => 1,
);
field_create_field($field);
$instance = array(
'field_name' => 'file_single',
'entity_type' => $entity_type,
'label' => 'File single',
'bundle' => $bundle,
);
field_create_instance($instance);
// File field - multiple.
$field = array(
'field_name' => 'file_multiple',
'type' => 'file',
'settings' => array(),
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
field_create_field($field);
$instance = array(
'field_name' => 'file_multiple',
'entity_type' => $entity_type,
'label' => 'File multiple',
'bundle' => $bundle,
);
field_create_instance($instance);
// Image field - single.
$field = array(
'field_name' => 'image_single',
'type' => 'image',
'settings' => array(),
'cardinality' => 1,
);
field_create_field($field);
$instance = array(
'field_name' => 'image_single',
'entity_type' => $entity_type,
'label' => 'Image single',
'bundle' => $bundle,
);
field_create_instance($instance);
// Image field - multiple.
$field = array(
'field_name' => 'image_multiple',
'type' => 'image',
'settings' => array(),
'cardinality' => FIELD_CARDINALITY_UNLIMITED,
);
field_create_field($field);
$instance = array(
'field_name' => 'image_multiple',
'entity_type' => $entity_type,
'label' => 'Image multiple',
'bundle' => $bundle,
);
field_create_instance($instance);
return $vocabulary_id;
}