public function InstagramPostsObtainedSubscriber::onInstagramPostsObtained in Instagram Feeds 8
Reacts on posts obtained event.
Parameters
\Drupal\instagram_feeds\Event\InstagramPostsObtainedEvent $event: Instance of InstagramPostsObtainedEvent.
File
- src/
EventSubscriber/ InstagramPostsObtainedSubscriber.php, line 66
Class
- InstagramPostsObtainedSubscriber
- Subscriber to InstagramPostsObtainedEvent event.
Namespace
Drupal\instagram_feeds\EventSubscriberCode
public function onInstagramPostsObtained(InstagramPostsObtainedEvent $event) {
$avatar = !$event->posts ? [] : $this
->getAvatarFromPostPermalink($event);
foreach ($event->posts as &$post) {
$post['avatar'] = $avatar;
$post['date'] = explode('+', $post['timestamp'])[0];
$post['timestamp'] = strtotime($post['timestamp']);
$post['full_name'] = $avatar['alt'] ?? $event
->getAccount()
->label();
// If there is no caption, this field is missed in response.
$post['caption'] = $post['caption'] ?: '';
$post['tags'] = $this
->parseHashTags($post['caption']);
}
// Reverse the order of posts, so older posts start from the beginning.
$event->posts = array_reverse($event->posts);
}