function relation_type_save in Relation 7
Saves a relation bundle.
Parameters
$relation_type: stdClass object with relation type properties. See relation_type_create().
$write_record_keys: Array containing the primary key of the relation ('relation_type'), if updating a relation, or an empty array if creating a new relation.
$rebuild_menu: Boolean indicating whether the the database tables used by various menu functions should be rebuilt. Setting this to FALSE is useful if multiple relation types are being created programmatically.
5 calls to relation_type_save()
- FeedsCSVtoRelationsTest::testUniqueEndpoints in relation_feeds/
tests/ relation.feeds_processor.test - Test unique endpoints setting
- RelationDummyFieldTestCase::testDummyFieldXSS in relation_dummy_field/
tests/ relation_dummy_field.test - Verify that the dummy field protects against XSS attacks.
- RelationTestCase::createRelationTypes in tests/
relation.test - Creates a set of standard relation types.
- relation_ui_type_form_submit in ./
relation_ui.module - Submit data from bundle settings page.
- relation_ui_type_import_submit in ./
relation_ui.module
File
- ./
relation.module, line 257 - Describes relations between entities.
Code
function relation_type_save($relation_type, $write_record_keys = array(), $rebuild_menu = TRUE) {
// Make sure all keys are populated.
$relation_type = relation_type_create($relation_type);
$existing_relation_type = relation_get_types(array(
$relation_type->relation_type,
));
$type = $relation_type->relation_type;
$source_bundles = $relation_type->source_bundles;
$target_bundles = $relation_type->target_bundles;
unset($relation_type->source_bundles, $relation_type->target_bundles);
$transaction = db_transaction();
drupal_write_record('relation_type', $relation_type, $write_record_keys);
// Remove all existing bundles from the relation type before re-adding.
db_delete('relation_bundles')
->condition('relation_type', $type)
->execute();
$query = db_insert('relation_bundles')
->fields(array(
'relation_type',
'entity_type',
'bundle',
'r_index',
));
foreach ($source_bundles as $entity_bundles) {
list($entity_type, $bundle) = explode(':', $entity_bundles, 2);
$query
->values(array(
$type,
$entity_type,
$bundle,
0,
));
}
if ($relation_type->directional) {
foreach ($target_bundles as $entity_bundles) {
list($entity_type, $bundle) = explode(':', $entity_bundles, 2);
$query
->values(array(
$type,
$entity_type,
$bundle,
1,
));
}
}
$query
->execute();
relation_type_ensure_instance($type);
if ($rebuild_menu) {
menu_rebuild();
}
if (empty($existing_relation_type)) {
field_attach_create_bundle('relation', $relation_type->relation_type);
}
}