HI all,
I'm working on an input format filter that should work as following. I have a content-type called glossary, the user can fill in a word (title) and description (body). Then there is a content-type article. When a word in the article matches a word in the glossary it should wrap that word with a span. Something like word. I already did a quick and dirty tryout and that worked fine. I already did a speed test and it worked out fine only a delay of 0.2s max. But now I try to make it as it should and I got stuck.
The way I think this could work is to have an array with all words and descriptions from the glossary content-type in a array. And then search through the text.
So I created a Plugin/Filter/Filtername.php file. In this file I try to load all node from the glossary content-type (as advised) via dependency injection.
What I found is a way to get all nids, via this code added in to my filter class:
class FilterName extends FilterBase {
public function __construct(QueryFactory $entity_query)
{
$this->entity_query = $entity_query;
}
public static function create(ContainerInterface $container){
return new static(
$container->get('entity.query')
);
}
public function process(){
$query = $this->entity_query
$query->condition('bundle','woordenlijst');
$nids = $query->execute();
}
}
So this should give me all nids of the node I'm looking for but how do I get these node loaded to get there title and body text? I found this lesson about entity loading. Which is usefull but there are some deprecated functions used and I have no idea how to combine these to to get een array of titles and body texts.
So what is currently the best method to load nodes and how can I combine this with the code I already have? And am I even on the right path or not, or is there a better/easier way to do this?
Thanks in advance.
Comments
Wy can't you use the Glossary
Why can't you use the Glossary feature in a view and either highlight the text using JQuery or one of the pre-render view hooks?
Hi dotmundo, to be honest I'm
Hi dotmundo, to be honest I'm not familiar with the Glossary feature so I started to build my own module. How does this feature work and is it available for drupal 8?
To be clear, there really isn
To be clear, there really isn't a fixed Glossary feature but instead you can configure a view to present itself as a glossary. Regardless what version of Drupal, this video tutorial should help https://www.ostraining.com/blog/drupal/glossary/
I a not clear about the rest of your requirements but it does feel you are still going to need to write a module to highlight the text you need. For that you should look at any of the Views hooks, particular those that of the pre-render variety.
O, if that is what you mean
O, if that is what you mean the solution I have in mind is a bit cleaner and simpeler, I think. And I got it figured out already via stack exchange: http://drupal.stackexchange.com/questions/221109/load-all-titles-and-bod...
Thanks for helping out.