|
| 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 | +} |
0 commit comments