public static function StatusYoutube::parseHashtags in Heartbeat 8
1 call to StatusYoutube::parseHashtags()
- StatusYoutube::processTerms in modules/
statusmessage/ src/ StatusYoutube.php
File
- modules/
statusmessage/ src/ StatusYoutube.php, line 101
Class
Namespace
Drupal\statusmessageCode
public static function parseHashtags($message) {
$tids = array();
$i = 0;
$tagsArray = explode('#', $message);
unset($tagsArray[0]);
$num = count($tagsArray);
foreach ($tagsArray as $hashtag) {
$hashtag = strpos($hashtag, ' ') ? substr($hashtag, 0, strpos($hashtag, ' ')) : $hashtag;
if ($i === $num - 1) {
$lastTagArray = explode(' ', $hashtag);
if (strlen($lastTagArray[1]) > 1) {
$hashtag = trim($lastTagArray[0]);
}
}
$tid = \Drupal::entityQuery("taxonomy_term")
->condition("name", trim($hashtag))
->condition('vid', [
'twitter',
'tags',
], 'IN')
->execute();
if (count($tid) > 0) {
if (\Drupal::moduleHandler()
->moduleExists('heartbeat')) {
Heartbeat::updateTermUsage(array_values($tid)[0], 'tags');
}
$tids[] = array_values($tid)[0];
}
else {
$term = Term::create([
'name' => trim($hashtag),
'vid' => 'tags',
'field_count' => 1,
]);
if ($term
->save()) {
$tids[] = $term
->id();
if (\Drupal::moduleHandler()
->moduleExists('heartbeat')) {
Heartbeat::newTermUsage($term
->id());
}
}
}
$i++;
}
return $tids;
}