I have a module that's making custom RSS feeds for me.
In a content type, I have my tags stored in "field_tags" entity reference field.
My goal is to get the names of all the tags, and ultimately put them into an array, so they can go into a markupless RSS field.
When I'm pulling the data, I get it with this:
foreach ($this->dbh->selectVideos(self::RPP) as $nid) {
$node = $this->entityMgr->getStorage('node')->load($nid);
if (!empty($node)) {
$data->nodes[] = [
'title' => $this->filterTxt($node->title->value),
'body' => $this->filterTxt($node->get('field_paragraph')->value),
'body2' => $this->filterTxt($node->get('field_paragraph')->value),
'created' => date('D, d M Y H:i:s', $node->created->value) . ' GMT',
'guid' => $node->id(),
'img' => $this->getImgUrl($node, self::IMG_FIELD),
'keywords' => $this->filterTxt($node->get('field_tags')->value),
'video' => $node->get('field_vid_url')->getString(),
];
}
}
return $this->render($data, 'nameoffeed');
}
The problem is that 'field_tags' is an entity reference field, so it's turning up blank.
I had partial success with this:
if ($node->hasField('field_tags')){
$entity_ref = $node->get('field_tags');
if ($entity_ref->count() > 0){
$tagoutput = entity_view($entity_ref->entity, 'default');
}
Then setting 'keywords' to equal $tagoutput. This grabs the first tag, which isn't great as I need them all, and then along with it comes a whole html layout enclosure that won't work for an RSS feed.
I'm confused what the correct way is to get a proper list of tag names. In D6 I had this list as plain text, which wasn't great because you wouldn't be able to click on one in the page view and be taken to a list of all pages with that tag, but at least the tags worked on the feeds easily.
Any thoughts?