Currently, simplenews maintains it's own category table with additional properties for each newsletter term. This leads to a lot of additional code that is required and can also have quite some issues, for example the bug that I discovered which fails to load the category information in hook_taxonomy_term_delete() because it joins the taxonomy tables.
There are two options I can see to improve this.
- We could keep the custom storage and code, but load the additional properties in http://api.drupal.org/api/drupal/modules--taxonomy--taxonomy.api.php/fun... and attach them always to the term object when it's loaded. This at least allows to drop the custom load code and instead simply forward to the taxonomy_term_load() functions and it also solves the issue that a loaded simplenews term and a simplenews category is not the same thing.
- We could go a step further and drop the category table completely and instead add a number of fields to the taxonomy_term bundle for our vocabulary. Then we can drop all our custom forms and listings and API functions and points users simply to the taxonomy administration pages.
Thoughts?
| Comment | File | Size | Author |
|---|---|---|---|
| #37 | newsletter-entity-1309404-37.patch | 325.99 KB | berdir |
| #35 | newsletter-entity-1309404-35.patch | 325.63 KB | berdir |
| #35 | newsletter-entity-1309404-35-interdiff.txt | 41.29 KB | berdir |
| #33 | newsletter-entity-1309404-33.patch | 320.05 KB | berdir |
| #32 | newsletter-entity-1309404-32.patch | 320.14 KB | berdir |
Comments
Comment #1
simon georges commentedI suppose the second one is the way to go looking at the future.
Comment #2
miro_dietikerPlease check if we stay with that for 7.x-1.x beta/stable or if we decide to switch to a different table / structure or presentation.
Comment #3
miro_dietikerWe might also remove redundant category column completely.
Comment #4
philippejadin commented+1 for solution 2
And also, at installation/upgrade you could create a built-in category called "Simplenews default settings" that would store the default settings.
This way :
- you can get rid of the "default settings" custom forms and code
- the default settings is configured at the same location as the real newsleter categories (simplify UI and admin navigation)
admin/config/simplenews/newsletter is almost == /admin/structure/simplenews/xxx/edit and should be at the same location.
Comment #5
berdirI played around with option 2 a while ago already and it's not that easy.
One problem is that this would add ~10 fields to the default installation which is way heavier than the current additional table, it's more complicated to support conditional options and the set-up code gets quite complicated and long to configure all these fields.
Option 1 however has it's problems too because we have custom conditions and checks in our loading functions e.g. only load non-hidden fields. This would actually be easier with option 2 as we could use EntityFieldQuery.
re #3: the duplication is in simplenews_newsletter, this issue is about the simplenews_category table. We should open a new issue about that duplication.
re #4: As you probably figured out already, we moved admin/structure/simplenews to configuration. Not sure about the default configuration thing, would require special treatment for that pseudo-category everywhere else. E.g. prevent it from showing up in the taxonomy reference field and so on.
Comment #6
miro_dietikerWow... 10 fields is a lot. (topic drupal field scalability issues)
Isn't it possible to add one field that contains one widget that has multiple storage columns / form elements?
Mapping everything on separate fields that make no sense on their own makes absolutely no sense to me and seems to be misdesign.
Is this an option?
Comment #7
berdirWell, re. the number of fields, it maps directly to the simplenews_category table:
Yes, all these fields would be specific to simplenews, but haven't most fields only single, specific purpose? I mean, we're not talking about field *types* here, we can re-use the existing string/list types. And that does have a few advantages, for example built-in integration with views, rules and other modules which rely on entity(_api module).
We could theoretically create a custom field type with all these values as columns but what would we gain with that? That code wouldn't be re-usable in any way either as we're just moving it around (hook_schema to hook_field_schema, custom form to hook_field_widget and so on).
There is actually a third option here and that would be to define a custom entity type for newsletter categories and stop using taxonomy completely. Instead of a taxonomy reference field, we could use entityreference instead.
That option is probably the best one in the long term and given that, we should probably postpone this issue completely.
Comment #8
miro_dietikerYour option (separate entity) is actually the same direction where once some refactoring was initiated by sutharsan.
He even wanted to support other types of lists instead of categories.
This refactoring has ben cancelled due to complexity and additional issues introduced.
As suggested, i also vote to delay this task for a future architecture that focusses deeper on reuse, pluggability, extensibility of simplenews.
Generally making this a cleanly defined entity is what sounds right to me instead of setup/create loose fields under Drupal 7.
Reference to the original issue about refactoring
#536620: Subscriber API: separate subscribers from newsletter management and allow other modules to define subscribers
Cannot find the original issue with the patch of this try. Took some minutes to search for it without success. Anyone who can find it?
Comment #9
berdirComment #10
berdirThis would also allow to use entity access so that custom/other contrib modules could provide implementations for specific permission handling, e.g.:
- #552548: Only send to own created newsletter
- #1140606: Permissions Per-Newsletter: Limit subscription options by role
- #418006: Simplenews in combination with OG
Comment #11
miro_dietikerSee also
http://drupal.org/project/newsletter
The newsletter module is entity based.
#1391354: merge newsletter module, inspect adopt to 7.x-2.x
Comment #12
berdirComment #13
berdirTask to be done:
Initial version:
- Add dependency on entity module
- Define hook_entity_info()
- Update schema, name and description, probably weight as well maybe rename tid to
- Replace current load_multiple() functions with entity_load(), make sure our custom conditions (hidden newsletters) and default sort according to weight is supported (will probably require a custom controller)
- Edit: Upgrade path of existing terms including their fields.
Additional steps, possibly as follow-ups:
- Define entity properties using a metadata controller (see tmgmt_translator as example)
- Make newsletters an exportable entity (again, see tmgmt_translator is an example)
- Use ui controller to replace our custom newsletter list
- Use view controller to provide better views integration.
- Use entity access to control access to newsletters
Comment #14
corvus_ch commentedOne first atempt.
Still need to finish a few things:
This patch can be a foundation for an 7.x-2.x branch.
Comment #15
berdirComment #17
berdirOk, here is a new patch.
- Re-rolled for 7.x-2.x
- All tests should be fixed except i18n integration. Will need to re-think that and probably use entity translation and convert the description to a field but that can be a follow-up, not urgent.
- Fixed and improved upgrade path.
- Added a default view for newsletter/id, including a feed.
- Removed all references of tid/category/categories from the code.
The plan is to commit this asap and then fix bugs as they occur, we won't find them in this issue anyway.
Comment #19
miro_dietikerGreat move. I'd love to see this fixed! :-)
Crazily huge patch. Will take some time to make us review it. Will you fix the tests first?
Comment #20
berdirThe tests pass locally, the testbot just isn't able to cope with the added dependencies. I'll try to commit them separately, maybe that will help.
Comment #21
berdirDid that, updated the patch accordingly. Will not work before the dependencies are rebuilt, which should happen when the dev snapshot for 7.x-2.x is updated.
Comment #22
berdirThe patch.
Comment #24
berdirFixed the test failures and re-rolled. They were caused by the fact that the rssfeed and link to previous issues settings are now only displayed if views.module is enabled.
This should be green.
Comment #27
berdirHm, testbot is behaving differently, can't reproduce locally, time for some debugging.
Comment #29
berdirAnother try.
Comment #30
berdirComment #32
berdirOk, let's try this.
Comment #33
berdirYay!
Removed the debug code again.
Comment #34
berdirweird characters in comment and filtering gone.
list() call can be moved outside of the foreach.
Note to myself: Check if this is statically cached.
Wondering why we're doing this, looks useless.
Those helper functions can be removed now, translations will be broken for a while but that's ok. it won't work anymore anyway.
Yes it is cached. Looks like there is no @param documentation here.
typo.
OverrideS ..:create().
param documentation is not necessary.
fix comment formatting.
Documentation missing.
Should be newsletter/id. Also defaultLabel() is missing.
class documentation missing.
Wondering why this is here.
Wondering why the hook was removed?
Needs to be fixed or parallel runs will break.
looks wrong.
same here.
unrelated formatting change?
same here.
Need to check if this is still necessary.
change to $form_state while it's changed anyway?
missing newline.
messed up defgroup definition.
docblock needs to be fixed.
same.
returning array() might allow to avoid some if checks.
We can remove this wrapper.
This only does something if we either define a i18n string or if it's a field.
I think we can get rid of this stuff.
param documentation wrong.
same.
We might be able to get rid of this, this is provided by entity.module for entity properties.
Comment #35
berdirFixed most of the above points except the token stuff.
Also re-enabled the newsletter issue translation tests and removed the newsletter translation test until that is being re-added and then it will be completely different anyway.
Comment #37
berdirAdded a lock for updating the simplenews sent count and fixed the test fail. I think this is ready.
Comment #38
berdirCommited. We'll deal with bugs in follow-ups.
Comment #40
rogerrogers commentedI recently upgraded a pile of modules on a fairly complex site, one of which was SimpleNews. The taxonomy vocabulary used by SimpleNews had been extended with additional fields, e.g. Header, Banner Image, etc. The ability to add custom fields to SimpleNews categories (taxonomy terms) was nice, because they could then be used in the templates for all newsletters sent for that category.
However, the upgrade appears to done away with vocabulary/terms entirely, thus breaking our theme and providing no clear way to replicate this functionality.
I'm posting here only in case others run into this problem, but also because it probably would have been good to have made clear that the latest version removed the vocabulary, which isn't a small change. I'm also wondering if there is a way to achieve the same custom fields using the new development track? For now, I am going to move back to the older version and attempt to merge/reconstruct the data from my new/old databases.
I hope this post doesn't come across as impolite. I truly appreciate the extensive amount of effort that has been expended on this module and provided to us at no cost! Just wanted to convey my experience and wonder about how this affects others who might need the same features we did.
Cheers!
Comment #41
berdirThe new version is a development release only that is not visible on the project page and the release note says "Do not use this, this is in heavy development mode and probably does not work.". I'd be more worried about that than the missing fields :)
It would be possible to make the new entity fieldable, although that won't be an option in 8.x when it becomes a config entity.
Comment #42
rogerrogers commented@Berdir In fact, I just noticed that the project moved to the 7.x 2.x branch. I typically do a drush dl [module] --dev, which I did in this case. I probably should have looked to see if that moved the project to a major new branch, instead of assuming it remained on the recommended branch. Thank you for your time and clarification!