function contribute_page_attachments in Contribute 8
Implements hook_page_attachments().
File
- ./
contribute.module, line 11 - Encourages people to join and contribute to the Drupal community.
Code
function contribute_page_attachments(&$page) {
if (\Drupal::routeMatch()
->getRouteName() != 'system.status') {
return;
}
/** @var \Drupal\contribute\ContributeManagerInterface $contribute_manager */
$contribute_manager = \Drupal::service('contribute.manager');
$value = '';
$account = $contribute_manager
->getAccount();
if ($account && !empty($account['image'])) {
$value .= '#contribute-info-account:before {background-image: url(' . $account['image'] . ')}';
}
$membership = $contribute_manager
->getMembership();
if ($membership && !empty($membership['badge'])) {
$value .= '#contribute-info-membership:before {background-image: url(' . $membership['badge'] . ')}';
}
$contribution = $contribute_manager
->getContribution();
if ($contribution && !empty($contribution['status'])) {
$url = base_path() . drupal_get_path('module', 'contribute') . '/images/icons/drupal.svg';
$value .= '#contribute-info-contribution:before {background-image: url(' . $url . ')}';
}
$page['#attached']['html_head'][] = [
[
'#type' => 'html_tag',
'#tag' => 'style',
'#value' => $value,
],
'contribute',
];
}