function crm_core_relationship_ui_type_form in CRM Core 8.2
Same name and namespace in other branches
- 8.3 modules/crm_core_relationship_ui/crm_core_relationship_ui.admin.inc \crm_core_relationship_ui_type_form()
- 8 modules/crm_core_relationship_ui/crm_core_relationship_ui.admin.inc \crm_core_relationship_ui_type_form()
- 7 modules/crm_core_relationship_ui/crm_core_relationship_ui.admin.inc \crm_core_relationship_ui_type_form()
Relation type bundle settings form.
Parameters
$relation_type: Relation type machine name. If this is not provided, assume that we're creating a new relation type.
This function is originally copied from relation_type_form from relation.admin.inc
1 string reference to 'crm_core_relationship_ui_type_form'
- crm_core_relationship_ui_menu in modules/
crm_core_relationship_ui/ crm_core_relationship_ui.module - Implements hook_menu().
File
- modules/
crm_core_relationship_ui/ crm_core_relationship_ui.admin.inc, line 78
Code
function crm_core_relationship_ui_type_form($form, &$form_state, $relation_type = array(), $op = 'edit') {
empty($relation_type) ? drupal_set_title(t('Add New Relationship type')) : drupal_set_title(t('Edit Relationship Type'));
_crm_core_relationship_ui_type_set_breadcrumb();
$form['#write_record_keys'] = array();
if ($relation_type) {
$relation_type = (object) $relation_type;
if ($relation_type) {
$form['#write_record_keys'][] = 'relation_type';
}
}
else {
$relation_type = (object) array(
'relation_type' => '',
'label' => '',
'reverse_label' => '',
'bundles' => array(),
'directional' => FALSE,
'transitive' => FALSE,
'r_unique' => FALSE,
'min_arity' => 2,
'max_arity' => 2,
'source_bundles' => array(),
'target_bundles' => array(),
);
}
$form['name'] = array(
// use 'name' for /misc/machine-name.js
'#type' => 'textfield',
'#title' => t('Label'),
'#description' => t('Display name of the relationship type. This is also used as the predicate in natural language formatters (ie. if A is related to B, you get "A [label] B")'),
'#default_value' => $relation_type->label,
'#required' => TRUE,
);
$form['relation_type'] = array(
'#type' => 'machine_name',
'#default_value' => $relation_type->relation_type,
'#maxlength' => 32,
'#disabled' => $relation_type->relation_type,
'#machine_name' => array(
'exists' => '\\Drupal\\relation\\Entity\\RelationType::load',
),
);
$form['directional'] = array(
'#type' => 'checkbox',
'#title' => 'Directional',
'#description' => t('A directional relationship is one that does not imply the reverse relationship. For example, a "likes" relationship is directional (A likes B does not neccesarily mean B likes A), whereas a "similar to" relationship is non-directional (A similar to B implies B similar to A. Non-directional relationship are also known as symmetric relationship.'),
'#default_value' => $relation_type->directional,
);
$form['reverse_label'] = array(
'#type' => 'textfield',
'#title' => t('Reverse label'),
'#description' => t('Reverse label of the relation type. This is used as the predicate by formatters of directional relations, when you need to display the reverse direction (ie. from the target entity to the source entity). If this is not supplied, the forward label is used.'),
'#default_value' => $relation_type->reverse_label,
'#states' => array(
'visible' => array(
// action to take.
':input[name="directional"]' => array(
'checked' => TRUE,
),
),
),
);
// override from original form
$form['transitive'] = array(
'#type' => 'value',
'#default_value' => 0,
);
$form['r_unique'] = array(
'#type' => 'checkbox',
'#title' => t('Unique'),
'#description' => t('Whether relations of this type are unique (ie. they can not contain exactly the same end points as other relations of this type).'),
'#default_value' => $relation_type->r_unique,
);
// these should probably be changed to numerical (validated) textfields.
$options = array(
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'8' => '8',
);
$form['min_arity'] = array(
'#type' => 'value',
'#default_value' => 2,
);
$options = array(
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'8' => '8',
'0' => t('Infinite'),
);
$form['max_arity'] = array(
'#type' => 'value',
'#default_value' => 2,
);
$counter = 0;
foreach (entity_get_info() as $entity_type => $entity) {
$bundles[$entity['label']]["{$entity_type}:*"] = 'all ' . $entity['label'] . ' bundles';
$counter += 2;
if (isset($entity['bundles'])) {
foreach ($entity['bundles'] as $bundle_id => $bundle) {
$bundles[$entity['label']]["{$entity_type}:{$bundle_id}"] = $bundle['label'];
$counter++;
}
}
}
$contact_types = ContactType::loadMultiple();
$options = array(
'crm_core_contact:*' => t('Any'),
);
foreach ($contact_types as $contact_type) {
$options['crm_core_contact:' . $contact_type->type] = t($contact_type->name);
}
$form['source_bundles'] = array(
'#type' => 'select',
'#title' => 'Source contact types',
'#options' => $options,
'#size' => count($options),
'#default_value' => $relation_type->source_bundles,
'#multiple' => TRUE,
'#description' => 'Contact types that are not selected will not be available as sources for directional, or end points of non-directional relations relations. Ctrl+click to select multiple. Note that selecting all bundles also include bundles not yet created for that entity type.',
);
$form['target_bundles'] = array(
'#type' => 'select',
'#title' => 'Destination contact types',
'#options' => $options,
'#size' => count($options),
'#default_value' => $relation_type->target_bundles,
'#multiple' => TRUE,
'#description' => 'Contact types that are not selected will not be available as targets for directional relations. Ctrl+click to select multiple.',
'#states' => array(
'!visible' => array(
// action to take.
':input[name="directional"]' => array(
'checked' => FALSE,
),
),
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
return $form;
}