Skip to content

Commit 3d2e773

Browse files
committed
Issue #12: Display profile data on layouts
Fixes #12
1 parent 447945c commit 3d2e773

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

profile.block.inc

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
/**
4+
* ProfileBlock extends Block
5+
*
6+
* This class allows us to create Profile blocks.
7+
*/
8+
class ProfileBlock extends Block {
9+
10+
/**
11+
* Sets title text on draggable block panel in Layout builder.
12+
*/
13+
function getAdminTitle() {
14+
if (!empty($this->settings['admin_label'])) {
15+
return check_plain($this->settings['admin_label']);
16+
}
17+
18+
$children = $this->getChildren();
19+
$title = $children[$this->childDelta]['info'];
20+
return strlen($this->settings['title']) ? check_plain($this->settings['title']) : $title; }
21+
22+
/**
23+
* Sets block subject on block view.
24+
*/
25+
function getTitle() {
26+
return isset($this->settings['title']) ? check_plain($this->settings['title']) : '';
27+
}
28+
29+
/**
30+
* Returns the rendered content of this block.
31+
*
32+
* @return string
33+
*/
34+
function getContent() {
35+
$type = $this->childDelta;
36+
$profile_type = profile_get_types($type);
37+
$account = $this->contexts['user']->data;
38+
if ($profile_type->userview && $profile = profile_load_by_user($account, $type)) {
39+
if (profile_access('view', $profile)) {
40+
$build['profile_' . $type] = array(
41+
'#type' => 'item',
42+
'#title' => $profile_type->label,
43+
'#prefix' => '<a class="profile-' . $profile->type . '"></a>',
44+
);
45+
$render = $profile->view();
46+
$build['profile_' . $type]['#markup'] = render($render);
47+
return $build;
48+
}
49+
}
50+
}
51+
52+
/**
53+
* {@inheritdoc}
54+
*/
55+
function getChildren() {
56+
foreach (profile_get_types() as $type => $profile_type) {
57+
$blocks[$type] = array(
58+
'info' => t('Profile !label block', array('!label' => $profile_type->label)),
59+
'description' => t('Provides Profile data as blocks.'),
60+
);
61+
}
62+
63+
return $blocks;
64+
}
65+
}

profile.module

+15
Original file line numberDiff line numberDiff line change
@@ -1051,6 +1051,7 @@ function profile_user_get_properties($account, array $options, $name) {
10511051
function profile_autoload_info() {
10521052
return array(
10531053
'Profile' => 'profile.entity.inc',
1054+
'ProfileBlock' => 'profile.block.inc',
10541055
);
10551056
}
10561057

@@ -1133,3 +1134,17 @@ function profile_views_api() {
11331134
'path' => backdrop_get_path('module', 'profile').'/views',
11341135
);
11351136
}
1137+
1138+
/**
1139+
* Implements hook_block_info().
1140+
*/
1141+
function profile_block_info() {
1142+
$blocks['profile'] = array(
1143+
'info' => t('Profile block'),
1144+
'description' => t('Provides Profile data as blocks.'),
1145+
'class' => 'ProfileBlock',
1146+
'required contexts' => array('user' => 'user'),
1147+
);
1148+
1149+
return $blocks;
1150+
}

0 commit comments

Comments
 (0)