function template_preprocess_socialfeed_facebook_post in Social Feed 8
Preprocess socialfeed_facebook_post.
See also
File
- ./
socialfeed.theme.inc, line 17 - Theme preprocessors.
Code
function template_preprocess_socialfeed_facebook_post(&$variables) {
$facebook_settings = Drupal::config('socialfeed.facebooksettings');
$use_facebook_hashtag = $facebook_settings
->get('hashtag');
$should_display_time = $facebook_settings
->get('time_stamp');
$teaser_text = $facebook_settings
->get('teaser_text');
$post =& $variables['post'];
if (isset($post['message'])) {
$post['message'] = substr($post['message'], 0, $facebook_settings
->get('trim_length'));
}
if (!empty($post['permalink_url'])) {
$post['permalink_url'] = Link::fromTextAndUrl(t('@teaser_text', [
'@teaser_text' => !empty($teaser_text) ? $teaser_text : $post['permalink_url'],
]), Url::fromUri($post['permalink_url'], [
'attributes' => [
'target' => '_blank',
],
]))
->toString();
}
if ($use_facebook_hashtag) {
$post['message'] = preg_replace_callback('/#(\\w+)/', function ($hash) {
return Link::fromTextAndUrl($hash[0], Url::fromUri('https:facebook.com/hashtag/' . $hash[1], [
'attributes' => [
'target' => '_blank',
],
]))
->toString();
}, !empty($post['message']) ? $post['message'] : "");
}
if ($should_display_time) {
$variables['should_display_time'] = $should_display_time;
$formatted_date = new DateTime();
$formatted_date
->setTimestamp($post['created_time']);
$post['created_time'] = $formatted_date
->format($facebook_settings
->get('time_format'));
}
if (isset($post['message'])) {
$post['message'] = [
'#markup' => $post['message'],
];
}
}