class views_plugin_argument_default_contact_id in CRM Core 8.2
Same name and namespace in other branches
- 7 modules/crm_core_user_sync/views/views_plugin_argument_default_contact_id.inc \views_plugin_argument_default_contact_id
Default argument plugin to extract a user via menu_get_object
Hierarchy
- class \views_plugin_argument_default_contact_id extends \views_plugin_argument_default
Expanded class hierarchy of views_plugin_argument_default_contact_id
1 string reference to 'views_plugin_argument_default_contact_id'
- crm_core_user_sync_views_plugins in modules/
crm_core_user_sync/ views/ crm_core_user_sync.views.inc - Implements hook_views_plugins().
File
- modules/
crm_core_user_sync/ views/ views_plugin_argument_default_contact_id.inc, line 10 - Contains the user from URL argument default plugin.
View source
class views_plugin_argument_default_contact_id extends views_plugin_argument_default {
function option_definition() {
$options = parent::option_definition();
$options['user'] = array(
'default' => '',
'bool' => TRUE,
'translatable' => FALSE,
);
return $options;
}
function options_form(&$form, &$form_state) {
$form['user'] = array(
'#type' => 'checkbox',
'#title' => t('Also look for a node and use the node author'),
'#default_value' => $this->options['user'],
);
}
function convert_options(&$options) {
if (!isset($options['user']) && isset($this->argument->options['default_argument_user'])) {
$options['user'] = $this->argument->options['default_argument_user'];
}
}
function get_argument() {
foreach (range(1, 3) as $i) {
$user = menu_get_object('user', $i);
if (!empty($user)) {
$contact = _crm_core_user_sync_get_related_entity('user', $user->uid, 'crm_core_user_sync');
if (!empty($contact)) {
return $contact->contact_id;
}
}
}
foreach (range(1, 3) as $i) {
$user = menu_get_object('user_uid_optional', $i);
if (!empty($user)) {
$contact = _crm_core_user_sync_get_related_entity('user', $user->uid, 'crm_core_user_sync');
if (!empty($contact)) {
return $contact->contact_id;
}
}
}
if (!empty($this->options['user'])) {
foreach (range(1, 3) as $i) {
$node = menu_get_object('node', $i);
if (!empty($node)) {
$contact = _crm_core_user_sync_get_related_entity('user', $node->uid, 'crm_core_user_sync');
if (!empty($contact)) {
return $contact->contact_id;
}
}
}
}
if (arg(0) == 'user' && is_numeric(arg(1))) {
$uid = arg(1);
$contact = _crm_core_user_sync_get_related_entity('user', $uid, 'crm_core_user_sync');
if (!empty($contact)) {
return $contact->contact_id;
}
}
if (!empty($this->options['user'])) {
if (arg(0) == 'node' && is_numeric(arg(1))) {
$node = node_load(arg(1));
if ($node) {
$contact = _crm_core_user_sync_get_related_entity('user', $node->uid, 'crm_core_user_sync');
if (!empty($contact)) {
return $contact->contact_id;
}
}
}
}
// If the current page is a view that takes uid as an argument, return the uid.
$views_page = views_get_page_view();
if ($views_page && isset($views_page->view->argument['uid'])) {
return $views_page->view->argument['uid']->argument;
}
}
}