/
tl_hacks.module
104 lines (92 loc) · 3.16 KB
/
tl_hacks.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
////////////////////////////////////////////////////////////////////////////////
// LOGIN FORM
////////////////////////////////////////////////////////////////////////////////
/**
* Modification de l'ordre des éléments du formulaire de login
* @param array $form
*/
function tl_hacks_form_user_login_block_alter(&$form) {
$form['name']['#weight'] = 1;
$form['pass']['#weight'] = 2;
$form['actions']['#weight'] = 3;
$form['links']['#weight'] = 4;
}
////////////////////////////////////////////////////////////////////////////////
// ACTUALITES
////////////////////////////////////////////////////////////////////////////////
/**
* Implements hook_field_formatter_info().
*/
function tl_hacks_field_formatter_info() {
return array(
'tl_hacks_list_icons' => array(
'label' => t('Universes icons'),
'field types' => array('group'),
),
);
}
/**
* Implements hook_field_formatter_view().
*/
function tl_hacks_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, $items, $display) {
$element = array();
if ($field['field_name'] == OG_AUDIENCE_FIELD && !empty($items[0])) {
foreach ($items as $delta => $item) {
if ($group = og_get_group('group', $item['gid'])) {
if ($group->access()) {
$label = og_label($group->gid);
$entity = entity_load($group->entity_type, array($group->etid));
$entity = current($entity);
$flang = field_language('node', $entity, 'field_group_type');
if ($entity->field_group_type[$flang][0]['value'] != 'univers') continue;
// Get the entity type of the group entity.
$uri = entity_uri($group->entity_type, $entity);
$flang = field_language('node', $entity, 'field_icon');
$imageData = array(
'style_name' => 'universe_icon',
'path' => !empty($entity->field_icon) ? $entity->field_icon[$flang][0]['filename'] : _tl_hacks_get_default_icon_uri(),
'alt' => check_plain($entity->title),
'title' => check_plain($entity->title),
);
$element[$delta] = array(
'#type' => 'link',
'#title' => theme('image_style', $imageData),
'#href' => $uri['path'],
'#options' => array('html' => TRUE,),
);
}
else {
// No need to show private groups several times, so remember if it was
// already added.
$added = &drupal_static(__FUNCTION__, FALSE);
if (!$added) {
$added = TRUE;
$element[$delta] = array(
'#markup' => '- ' . t('Private group') . ' -',
);
}
}
}
}
}
return $element;
}
/**
* Get default icon uri
*/
function _tl_hacks_get_default_icon_uri() {
$uri = &drupal_static(__FUNCTION__);
if (empty($uri)) {
$field = field_info_field('field_icon');
$file = file_load($field['settings']['default_image']);
$uri = $file->uri;
}
return $uri;
}
/**
* Implements hook_views_data_alter().
*/
function tl_hacks_views_data_alter(&$data) {
$data['og_membership']['group']['filter']['handler'] = 'og_handler_filter_group_audience_gid_tl';
}