socialbase.theme in Open Social 8.9
Same filename and directory in other branches
- 8 themes/socialbase/socialbase.theme
- 8.2 themes/socialbase/socialbase.theme
- 8.3 themes/socialbase/socialbase.theme
- 8.4 themes/socialbase/socialbase.theme
- 8.5 themes/socialbase/socialbase.theme
- 8.6 themes/socialbase/socialbase.theme
- 8.7 themes/socialbase/socialbase.theme
- 8.8 themes/socialbase/socialbase.theme
The primary PHP file for the Social base theme.
File
themes/socialbase/socialbase.themeView source
<?php
/**
* @file
* The primary PHP file for the Social base theme.
*/
use Drupal\Component\Utility\Html as HtmlUtility;
use Drupal\Core\Language\LanguageInterface;
use Drupal\Core\Session\AnonymousUserSession;
use Drupal\node\NodeInterface;
// Include all files from the includes directory.
$includes_path = dirname(__FILE__) . '/includes/*.inc';
foreach (glob($includes_path) as $filename) {
require_once dirname(__FILE__) . '/includes/' . basename($filename);
}
/**
* Implements hook_library_info_alter().
*/
function socialbase_library_info_alter(&$libraries, $extension) {
// When the social_comment_upload module is enabled we want to load the
// photoswipe styling with the comment styling.
if ($extension === 'socialbase' && isset($libraries['comment']) && \Drupal::moduleHandler()
->moduleExists('social_comment_upload')) {
$libraries['comment']['dependencies'][] = 'socialbase/photoswipe-gallery';
$libraries['comment']['dependencies'][] = 'socialbase/photoswipe.image';
}
}
/**
* Prepare group link when an event or topic belongs to one group.
*/
function socialbase_group_link($node) {
$group = _social_group_get_current_group($node);
$group_link = NULL;
// Exclude nodes without ids (Preview).
if (!empty($node
->id()) && !empty($group)) {
$group_content = \Drupal::entityTypeManager()
->getStorage('group_content')
->loadByProperties([
'entity_id' => $node
->id(),
]);
if (!empty($group_content)) {
$curr_langcode = \Drupal::languageManager()
->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)
->getId();
if ($group
->isTranslatable() && $group
->hasTranslation($curr_langcode)) {
$group = $group
->getTranslation($curr_langcode);
}
$group_link = $group
->link();
}
}
return $group_link;
}
/**
* Helper function to retrieve the icon string for a visibility title.
*
* @param string $title
* The title for the icon.
*
* @return string
* The icon connected to the title.
*/
function _socialbase_get_visibility_icon($title) {
// Set the materialize icon.
switch ($title) {
case 'Community':
$icon = 'community';
break;
case 'Recipient':
$icon = 'community';
break;
case 'Group members':
$icon = 'lock';
break;
default:
$icon = strtolower(HtmlUtility::escape($title));
}
return $icon;
}
/**
* Get comment count for a node.
*/
function _socialbase_node_get_comment_count(NodeInterface $node) {
$comment_count =& drupal_static(__FUNCTION__ . $node
->id());
// Calculate the comment_count for this page request.
if (is_null($comment_count)) {
$count = 0;
$comment_storage = \Drupal::entityTypeManager()
->getStorage('comment');
$current_user = \Drupal::currentUser();
$cids = $comment_storage
->getQuery()
->condition('entity_id', $node
->id())
->condition('entity_type', 'node')
->sort('cid', 'DESC')
->execute();
$pid_query = $comment_field_data_query = \Drupal::database()
->select('comment_field_data', 'cfd');
foreach ($cids as $cid) {
// Published main comments or published replies on published main comments
// are counted for users without 'administer comments' permission.
$query = $comment_storage
->getQuery()
->condition('cid', $cid)
->condition('status', TRUE);
// Check if comment is published.
if (!empty($query
->execute())) {
$comment_field_data_query
->addField('cfd', 'pid');
$comment_field_data_query
->condition('cid', $cid);
$pid = $comment_field_data_query
->execute()
->fetchField();
// Check if comment has parent comment.
if ($pid === '0' || $pid_query
->condition('cid', $pid)
->condition('status', TRUE)) {
$count++;
}
elseif ($current_user
->hasPermission('administer comments')) {
// User with 'administer comments' permission can also see the comment
// as being unpublished, so let's count it.
$count++;
}
}
elseif ($current_user
->hasPermission('administer comments')) {
// User with 'administer comments' permission can also see the comment
// as being unpublished, so let's count it.
$count++;
}
}
// Make sure our static cache knows it doesnt have to recalculate it this
// request.
$comment_count = $count;
}
return $comment_count;
}
/**
* Get like count for a node.
*/
function _socialbase_node_get_like_count($type, $id) {
$count = 0;
// The result function service needs entity type and entity id in order
// to get proper results.
if (!empty($type) && !empty($id)) {
$manager = Drupal::service('plugin.manager.votingapi.resultfunction');
$results = $manager
->getResults($type, $id);
// Lets see if our results carry the sum of all votes.
if (!empty($results['like']['vote_sum'])) {
$count = $results['like']['vote_sum'];
}
}
return $count;
}
/**
* Implements theme_preprocess_username().
*/
function socialbase_preprocess_username(&$variables) {
$account = $variables['account'] ?: new AnonymousUserSession();
// Override the default drupal truncate function for all user names,
// so the whole name will be displayed.
$variables['name'] = $account
->getDisplayName();
}
/**
* Implements hook_theme().
*/
function socialbase_theme($existing, $type, $theme, $path) {
return [
'invite_email_preview' => [
'variables' => [
'title' => NULL,
'logo' => NULL,
'subject' => NULL,
'body' => NULL,
'helper' => NULL,
],
],
];
}
Functions
Name | Description |
---|---|
socialbase_group_link | Prepare group link when an event or topic belongs to one group. |
socialbase_library_info_alter | Implements hook_library_info_alter(). |
socialbase_preprocess_username | Implements theme_preprocess_username(). |
socialbase_theme | Implements hook_theme(). |
_socialbase_get_visibility_icon | Helper function to retrieve the icon string for a visibility title. |
_socialbase_node_get_comment_count | Get comment count for a node. |
_socialbase_node_get_like_count | Get like count for a node. |