I have a use case where I'm attaching taxonomy terms to file entities. And I would like to display the entity count. Would you be willing to accept a patch to support such a thing. I think it shouldn't be all that hard to adapt the shs_node_count submodule to have another one that also supports entities. That module would be dependant on the Taxonomy Entity Index module.

One caveat is that the maintainer of that module has vouched to port the module to 8.x. But looks like he hasn't started the process yet. So I guess this submodule feature will be stuck in your 7.x version until @brantwynn get's to it.

Hope to hear your thoughts on this. I will be starting to write a patch anyway. So if it doesn't get accepted I'll just make myself a custom one for production. But ofcourse I hope you're interested.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexverb created an issue. See original summary.

stBorchert’s picture

As far as I can remember (and tell from the code), SHS: node count already integrates with Taxonomy entity index.
Since the functionality is not added to SHS 8.x (and won't be added at any time) there is no problem with being stuck in 7.x ;)

If there is an error with shs_node_count while using terms on files (i.e. it should work but it doesn't) feel free to post a patch. Otherwise I would recommend creating a custom module based on shs_node_count.

thanks,

Stefan

alexverb’s picture

Thanks for the quick reply. Yeah just saw it supports taxonomy_entity_index. The problem is that you cannot select which entity types shs should be counting. It just counts all. And it feels kind of dubious to put such functionality in a module called shs_node_count. But I understand if you wouldn't want to add an shs_entity_count to the module. I'll post my patch anyways so you can have a look at it.

alexverb’s picture

Allright, here's a first draft. Seems like it's all working properly. There's only one bug left on the field_ui_field_edit_form.

There is also one task left in this module. It's very expensive to execute these queries. The count should definitely be cached. I might need some help with that. And it requires for the shs main module to send it's reset variable in the alter_options.

If you are okey with taking up this module you should think about removing the shs_node_count module because it is obsolete then.

Let me know what you think.
Grtz.

alexverb’s picture

Yezzz, fixed the bug and also got some caching implemented.

But cache invalidation is another story. For that I should know when items are added, changed or removed from the taxonomy_entity_index. Best thing would be if they brought a hook into play where I could check if something has changed.

If you could tell me if you're interested in picking up this module I will try to convince taxonomy_entity_index to provide a hook for us. Otherwise, again I will choose a custom solution above contribution.

Anywayz, here's a second patch for you.

alexverb’s picture

Status: Active » Needs review
stBorchert’s picture

Hey.
I'm sorry to say this, but I do not want to add this to SHS.

Let me explain, why: counting nodes (or other entities) is a nightmare when it comes to caching and to invalidate this cache. You'll have to reset the cache every time the association between the entity and the term is changed and (nearly) every time the term is modified (i.e. moved to another parent).
This and some other related things got me a lot of headaches (and issues here on d.o. ;) ) so I finally decided to remove this "feature" completely from SHS core.
I left SHS: node count as a submodule to show other developers a way to use this or how to extend/alter the results of SHS.

Maybe I should add a readme to SHS: node count, explaining its purpose (and linking to this issue and to your patch) ...

As much as a I appreciate your work I couldn't add this to SHS :/

charos’s picture

Maybe I am missing something,but I don't think SHS: node count integrates with Taxonomy entity. At least not to the UI as far as I can see for my Views. I see that the module says "Add "a"node_count" setting to a shs widgets" ,but I can't see such effect anywhere!

So the purpose of this sub-module is for developers mostly?

alexverb’s picture

Yes the submodule is just there as an example to developers. I made a contrib after it called SHS Entity count. It does have caching implemented so the expensive queries aren't run every time.

alexverb’s picture

So for solving the following issue #2723787: Views support I need some alter hooks in place to allow for the shs_entity_count module to add settings to the shs widget in views exposed filters. I hope you are willing to support this, since you support the alteration of children too.

My proposal is this patch. I will also post my patch on previously mentioned issue so you can see how shs_entity_count implements these alterations.

If this can get in the shs_entity_count module will be able to display the entity count on views exposed filters.

stBorchert’s picture

Uhm, why don't you simply add a custom handler to your module extending shs_handler_filter_term_node_tid? Altering the options of a views handler is a very uncommon way to modifiy the options.

alexverb’s picture

But what if multiple modules extend your handler and people want to combine for example the shs_entity_count handler with an other modules handler that extends yours? I can't expect them to write a custom handler then? I'm just thinking out loud here, you can stop me if I'm sounding stupid...

alexverb’s picture

Okey, writing my own handlers probably makes more sense indeed. I need them for all entities and not just nodes.

I still might need the $element_settings part of previous patch to allow for extra shs settings...

alexverb’s picture

Allright, here is the patch I need in order for shs_entity_count to get #2723787: Views support

The changes have already been committed on my side. So if you want to test the functionality you don't have to patch shs_entity_count.

  • stBorchert committed 8e6cef7 on 7.x-1.x authored by alexverb
    Issue #2715031 by alexverb: Support for Taxonomy Entity Index (Entity...
stBorchert’s picture

Status: Needs review » Fixed

I've committed a slightly modified version of your last patch so existing values are merged with settings from other modules instead of overridden.

alexverb’s picture

Thx! Yup I overlooked that.

Maybe now you could list SHS Entity count on your project page where you reference the removed functionality?

"With SHS 7.x-1.7 (and development versions later than 2016-03-01) displaying the number of nodes associated to a term is not part of the module anymore. This "feature" has been moved to a sub-module."

I will update my module to only be compatible with shs versions from 1.7 and onwards.

stBorchert’s picture

Done ;)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.