function ReferenceOptionLimitEntityreferenceTestCase::changeFieldSettings in Reference field option limit 7
Helper to change the field settings.
Parameters
$settings: An array of settings to apply, with the following properties:
- 'widget': The widget type to set on the matching field instance.
- 'cardinality': The cardinality to set on the matching field.
- 'default': The default value to set on the matching field instance.
- 'empty_behaviour': Whether the limited field shows all options or none when the matching field is initially empty.
1 call to ReferenceOptionLimitEntityreferenceTestCase::changeFieldSettings()
- ReferenceOptionLimitEntityreferenceTestCase::testNodeCreateForm in tests/
reference_option_limit.test - Test the functionality on a node create form.
File
- tests/
reference_option_limit.test, line 323 - Contains tests for the Reference option limit module.
Class
- ReferenceOptionLimitEntityreferenceTestCase
- Test use of the module with entityreference fields.
Code
function changeFieldSettings($settings) {
$country_field_info = field_info_field('test_rol_er_country');
$country_instance_info = field_info_instance('node', 'test_rol_er_country', 'test_rol_node_article');
$city_instance_info = field_info_instance('node', 'test_rol_er_city', 'test_rol_node_article');
// Set the cardinality on the field.
$country_field_info['cardinality'] = $settings['cardinality'];
// Set the widget type on the instance.
$country_instance_info['widget']['type'] = $settings['widget'];
// Set the empty default behaviour on the instance of the limited field,
// i.e., the city.
$city_instance_info['options_limit_empty_behaviour'] = $settings['empty_behaviour'];
// Set the default value on the instance.
if (empty($settings['default'])) {
$default = NULL;
}
else {
$default = array();
foreach ($settings['default'] as $entity_label) {
$node = $this
->getNodeByTitle($entity_label);
$default[]['target_id'] = $node->nid;
}
}
$country_instance_info['default_value'] = $default;
field_update_field($country_field_info);
field_update_instance($country_instance_info);
field_update_instance($city_instance_info);
}