Add region to ambassador user profile

Add ambassador region to user profile and display next to
user name on ambassador page.

Change-Id: I6dded1fdba5548101682a5156e434940569c1bf2
This commit is contained in:
Marton Kiss 2015-08-24 08:46:14 +02:00
parent 235949830f
commit 53bcf3fc53
6 changed files with 105 additions and 0 deletions

View File

@ -10,6 +10,37 @@
function groups_user_profile_field_default_field_bases() {
$field_bases = array();
// Exported field_base: 'field_ambassador_region'
$field_bases['field_ambassador_region'] = array(
'active' => 1,
'cardinality' => 1,
'deleted' => 0,
'entity_types' => array(),
'field_name' => 'field_ambassador_region',
'indexes' => array(
'value' => array(
0 => 'value',
),
),
'locked' => 0,
'module' => 'list',
'settings' => array(
'allowed_values' => array(
'AF' => 'Africa',
'AS' => 'Asia/Pacific',
'EU' => 'Europe',
'NA' => 'North America',
'SA' => 'South America',
'OC' => 'Oceania',
'AN' => 'Antarctica',
'ME' => 'Middle East',
),
'allowed_values_function' => '',
),
'translatable' => 0,
'type' => 'list_text',
);
// Exported field_base: 'field_weibo_url'
$field_bases['field_weibo_url'] = array(
'active' => 1,

View File

@ -10,6 +10,44 @@
function groups_user_profile_field_default_field_instances() {
$field_instances = array();
// Exported field_instance: 'user-user-field_ambassador_region'
$field_instances['user-user-field_ambassador_region'] = array(
'bundle' => 'user',
'default_value' => NULL,
'deleted' => 0,
'description' => '',
'display' => array(
'default' => array(
'label' => 'above',
'module' => 'list',
'settings' => array(),
'type' => 'list_default',
'weight' => 11,
),
'profile_teaser' => array(
'label' => 'above',
'settings' => array(),
'type' => 'hidden',
'weight' => 0,
),
),
'display_in_partial_form' => 0,
'entity_type' => 'user',
'field_name' => 'field_ambassador_region',
'label' => 'Ambassador region',
'required' => 0,
'settings' => array(
'user_register_form' => 0,
),
'widget' => array(
'active' => 1,
'module' => 'options',
'settings' => array(),
'type' => 'options_buttons',
'weight' => 12,
),
);
// Exported field_instance: 'user-user-field_weibo_url'
$field_instances['user-user-field_weibo_url'] = array(
'bundle' => 'user',
@ -73,6 +111,7 @@ function groups_user_profile_field_default_field_instances() {
// Translatables
// Included for use with string extractors like potx.
t('Ambassador region');
t('Weibo URL');
return $field_instances;

View File

@ -8,7 +8,11 @@ dependencies[] = features
dependencies[] = groups_social_link
dependencies[] = image
dependencies[] = link
dependencies[] = list
dependencies[] = options
features[features_api][] = api:2
features[field_base][] = field_ambassador_region
features[field_base][] = field_weibo_url
features[field_instance][] = user-user-field_ambassador_region
features[field_instance][] = user-user-field_weibo_url
features[image][] = 300x300_avatar

View File

@ -26,3 +26,18 @@ function groups_user_profile_field_default_field_instances_alter(&$fields) {
);
}
}
/**
* Implements hook_form_user_profile_form_alter()
*
* Override ambassador-region field visibility.
*/
function groups_user_profile_form_user_profile_form_alter(&$form, &$form_state,
$form_id) {
$current_user = user_uid_optional_load();
$roles = array('ambassador', 'community_manager', 'administrator');
$check = array_intersect($roles, array_values($current_user->roles));
if (empty($check)) {
$form['field_ambassador_region']['#access'] = FALSE;
}
}

View File

@ -62,6 +62,7 @@
h3 {
margin-top: 10px;
margin-bottom: 5px;
line-height: 30px;
a {
color: #FFFFFF;
font-family: "Open Sans",Helvetica,Arial,sans-serif;
@ -69,6 +70,9 @@
font-size: 18.2px;
line-height: 20px;
}
.ambassador-region {
font-size: 12px;
}
}
.social-link {
i {

View File

@ -257,6 +257,18 @@ function openstack_bootstrap_preprocess_views_view(&$variables) {
function openstack_bootstrap_preprocess_user_profile(&$variables) {
global $user;
$account = $variables['elements']['#account'];
if ($variables['elements']['#view_mode'] == 'profile_teaser') {
$node_wrapper = entity_metadata_wrapper('user', $account);
$region_value = $node_wrapper->field_ambassador_region->value();
if (isset($region_value)) {
module_load_include('inc', 'field_group_location', 'field_group_lookup');
$continents = _continent_get_predefined_list();
$variables['user_profile']['name'][0] = array(
'#markup' => '<h3><a href="">'.$account->name.
' <span class="ambassador-region">// '.$continents[$region_value].'</span></a></h3>',
);
}
}
if (in_array('ambassador', $account->roles)) {
$variables['user_profile']['role_ambassador'] = array(
'#prefix' => '<span class="label label-info">',