Active
Project:
Node read time
Version:
8.x-1.4
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
9 Nov 2021 at 10:29 UTC
Updated:
26 Nov 2021 at 18:33 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
yivanov commentedHi @Nelson, thanks for using the module :) Your idea is great and I would definitely be happy to implement this when I have more free time.
Comment #3
nsalves commentedHey yivanov, thanks for the quick reply.
I went a little deeper in the module and noticed the current implementation makes use of a pseudo-field. I believe this means there's no way (at least that I know) to add a filter plugin for views since the field is not stored in the database. I think a good solution would be to create a new field and store there the calculated read time the modules provides. This way the users could use this new field to filter or sort in views.
The attached patch does just that. The idea is to have a checkbox in the configuration form where the user can choose if he wants to create this new field (this way there's no impact in the current functionality). If the checkbox is selected, a new field (and field storage) is created programmatically in the selected bundles. Additionally, the patch implements an hook_entity_save to calculate the reading time and store it in the newly created fields. If by any chance the user decides that he doesn't want a certain bundle to keep displaying the reading time ( as provided by this module) and uncheck the box then the created fields are automatically deleted.
Edit: I believe the patch only works if the unit time is "minutes". I'll have to check but I'm pretty sure I didn't account for the other cases
Comment #4
nsalves commentedAttaching new patch that fixes an error if the user selected the unit of time "Default (only minute) without text" and a validation in the configuration form to not allow the user to select the create field option with the unit of time "Minute and Second" selected (the field created is of the type integer). Hope all its good now :)
Comment #5
nsalves commentedAttaching new patch that fixes some php notices