function user_relationship_implications_form_user_relationships_admin_type_edit_alter in User Relationships 7
File
- user_relationship_implications/
user_relationship_implications.module, line 31 - Drupal Module: User Relationship Implications
Code
function user_relationship_implications_form_user_relationships_admin_type_edit_alter(&$form, &$form_state) {
$relationship_type = isset($form['rtid']['#value']) ? user_relationships_type_load($form['rtid']['#value']) : NULL;
$relationship_types = user_relationships_types_load();
$implied_by = array();
$values = array();
if ($relationship_type) {
foreach ($relationship_type->implies as $rtid => $implies) {
$values[$rtid]['strict'] = $implies->strict;
$values[$rtid]['reverse'] = $implies->reverse;
}
foreach ($relationship_type->implied_by as $implied) {
if (!$implied->reverse) {
$implied_by[] = $implied->rtid;
}
}
}
foreach ($relationship_types as $type) {
if (!isset($relationship_type) || $type->rtid != $relationship_type->rtid && !in_array($type->rtid, $implied_by)) {
$imp_name = "implies_{$type->rtid}";
$form['implications']['opts'][$type->rtid][$imp_name] = array(
'#title' => t('@rel_name', user_relationships_type_translations($type)),
'#type' => 'checkbox',
'#return_value' => $type->rtid,
'#default_value' => isset($form['#post'][$imp_name]) || isset($values[$type->rtid]),
);
$strict_name = "implied_{$type->rtid}_strict";
$form['implications']['opts'][$type->rtid][$strict_name] = array(
'#type' => 'checkbox',
'#return_value' => 1,
'#default_value' => isset($form['#post'][$strict_name]) || isset($values[$type->rtid]['strict']) ? $values[$type->rtid]['strict'] : FALSE,
);
$opp_name = "implied_{$type->rtid}_reverse";
$form['implications']['opts'][$type->rtid][$opp_name] = array(
'#type' => 'checkbox',
'#return_value' => 1,
'#default_value' => isset($form['#post'][$opp_name]) || isset($values[$type->rtid]['reverse']) ? $values[$type->rtid]['reverse'] : FALSE,
);
}
}
if (isset($form['implications'])) {
$implications_form = array(
'#title' => t('Implied relationships'),
'#type' => 'fieldset',
'#weight' => 5,
'#tree' => TRUE,
'#theme' => 'user_relationship_implications_form_table',
'#description' => '<p>' . t('Check a relationship type to create an implied relationship. This implied relationship will be created automatically when the primary relationship is created.') . '</p>' . '<p>' . t('By default, removing an implied relationship will not cause the primary relationship to be removed. But if "strict" is checked, then removing the implied relationship will also cause the primary relationship to be removed. Note that an implied one-way relationship, by default, is created in the forward direction ("You to Them"). But if "reverse" is checked, then it is created in the reverse direction ("Them to You").') . '</p>',
'#group' => 'tabs',
);
$form['implications'] = array_merge($form['implications'], $implications_form);
$form['#submit'][] = 'user_relationship_implications_edit_submit';
}
}