-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprofile.block.inc
64 lines (59 loc) · 1.73 KB
/
profile.block.inc
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
<?php
/**
* ProfileBlock extends Block
*
* This class allows us to create Profile blocks.
*/
class ProfileBlock extends Block {
/**
* Sets title text on draggable block panel in Layout builder.
*/
function getAdminTitle() {
if (!empty($this->settings['admin_label'])) {
return check_plain($this->settings['admin_label']);
}
$children = $this->getChildren();
$title = $children[$this->childDelta]['info'];
return strlen($this->settings['title']) ? check_plain($this->settings['title']) : $title;
}
/**
* Sets block subject on block view.
*/
function getTitle() {
return isset($this->settings['title']) ? check_plain($this->settings['title']) : '';
}
/**
* Returns the rendered content of this block.
*
* @return string
*/
function getContent() {
$type = $this->childDelta;
$profile_type = profile_get_types($type);
$account = $this->contexts['user']->data;
if ($profile_type->userview && $profile = profile_load_by_user($account, $type)) {
if (profile_access('view', $profile)) {
$build['profile_' . $type] = array(
'#type' => 'item',
'#title' => $profile_type->label,
'#prefix' => '<a class="profile-' . $profile->type . '"></a>',
);
$render = $profile->view();
$build['profile_' . $type]['#markup'] = render($render);
return $build;
}
}
}
/**
* {@inheritdoc}
*/
function getChildren() {
foreach (profile_get_types() as $type => $profile_type) {
$blocks[$type] = array(
'info' => t('Profile !label block', array('!label' => $profile_type->label)),
'description' => t('Provides Profile data as blocks.'),
);
}
return $blocks;
}
}