Problem/Motivation
Entity View Mode stores everything in a single variable. This makes exporting very difficult.
Proposed resolution
Move everything into a table that matches the structure of Display Suite. This way, DS can rely on Entity View Mode.
Remaining tasks
Add the schema and updates for the new db backend.
Make the UI work with the new db backend.
Make the hook api work with any changes that where needed to make this change.
Make sure the tests still pass.
Features exporting is being handled in another issue, however, this should be committed after features exporting is done. #1425620: Features Module Support
User interface changes
None.
API changes
None. Unless, a module is attempting to read from the variable table directly.
Data model changes
Moving data storage from a single serialized variable to a custom table.
Original Post
It would be great if this module could become a standalone building block of Display Suite, rather than the two competing on functionality.
Would it suffice as a first step to move this module to using the {ds_view_modes} table to store view modes rather than a single variable?
Having them in a table would help with exportability too: #1425620: Features Module Support.
| Comment | File | Size | Author |
|---|---|---|---|
| #60 | Screen Shot 2017-04-20 at 2.34.09 PM.png | 40.58 KB | epophoto |
| #60 | Screen Shot 2017-04-20 at 2.33.40 PM.png | 49.38 KB | epophoto |
| #56 | entity_view_mode-change_save_to_db-1702530-54.patch | 12.02 KB | denix |
| #49 | entity_view_mode-change_save_to_db-1702530-49.patch | 12.04 KB | dobe |
| #44 | entity_view_mode-change_save_to_db-1702530-42.patch | 11.75 KB | dobe |
Comments
Comment #1
gagarine commentedI think using the same table can be quiet a problem with installation/desinstallion/update. But using a new table with the same structure is a first step. DS can after add this module as a dependency.
Comment #2
dave reidAs great as it would be, there are huge red flags with depending on another module's schema without actually declaring yourself as a dependency, so I'm not ready to take that risk yet.
Comment #3
joachim commentedIn that case, how about we move to a table {entity_view_mode} and when we're ready with that we can talk to DS about them changing to depend on us?
Comment #4
lpalgarvio commentedi agree with a {entity_view_mode} table
Comment #5
dave reidRe-titling for better visibility.
Comment #6
dave reidIf we used a table we possibly couldn't use ctools exportables as we possibly cannot rely on things that need database schemas in hook_entity_info(). We'd have to manually maintain that code for the UI and export/import handling, which is not ideal at all. Unless it can be proven that it would be ok to use ctools exportables and schema in hook_entity_info() for Drupal 7, I'm very tenative on this solution.
Comment #7
damienmckennaIs there a specific reason why using variables is not acceptable? Most sites would only need a few variables.
Comment #8
damienmckennaPut another way, could DS be updated to use the same variables?
Comment #9
joachim commented> as we possibly cannot rely on things that need database schemas in hook_entity_info()
That's not the case -- node_entity_info() relies on the database to define node types.
Comment #10
joachim commented> Is there a specific reason why using variables is not acceptable? Most sites would only need a few variables.
Currently, all the user-defined view modes are stored in a single variable. This is really bad for exportability: consider if you want one feature for your site's news system, another for your site events, and so on.
That could be addressed by splitting up the variable into one variable per entity type. But then you'd still have the problem that the node view mode 'News scroll' is intended for article nodes, and should be in the 'news system' feature, while the 'event calendar pop-up' view mode is intended for to event nodes, and should be in the 'event calendar' feature. So you'd need one variable per view mode, which is getting silly!
There is also a small performance consideration. The only time that Drupal core gets told about our custom view modes is during a hook_entity_info() cache rebuild (and our own admin UI). The rest of the time, it doesn't talk to us at all. Therefore, if we use the variable system, we're keeping our list of view modes in memory twice: once for our variable, and once inside the entity info array.
Using a database table may seem heavier at first, but it would be a table that Drupal totally ignores unless it's rebuilding hook_entity_info() cache.
Comment #11
joachim commentedHere's a patch that converts the storage to being in a table, and upgrades the existing variable.
The next step would be to enable this table for CTools exportables.
However, there are a number of problems:
- view mode machine names are not unique, because different entity types can use the same name. CTools requires all exportables to have a unique machine name. So here we might have to fake it, and add an object key field to our database table made up of, say "$entity_type-$view_mode_name". (Assuming CTools doesn't mind the hyphen!)
- CTools exportables returns objects, but the view mode data we pass around in the module is an array.
- Furthermore, CTools expects a default hook to return objects, and to have them in a flat array. So we can't use hook_entity_view_mode_info(), which is keyed by entity name then view mode. So we'd end up with *two* hooks to specify view modes in code: hook_entity_view_mode_info(), and the CTools one.
Comment #13
damienmckennaTwo comments:
Comment #14
joachim commented> Shouldn't the view modes be stored per entity bundle?
View modes aren't per entity bundle. In hook_entity_info() they are per entity type. The ticky boxes in this module's UI for entity bundles appear to be a fiction that passes something on to Field API to do with the 'custom settings' option. I didn't investigate much further than that!
> Shouldn't the separator be two underlines?
Quite possibly. I'm not sure which is safest to use!
Comment #15
dobe commentedPatch failed because we need to delete the old record when changing machine_name.
Comment #16
dobe commentedComment #17
frobI wasn't able to apply the patch, git reported fatal: unrecognized input
However, just looking at the patch, it doesn't add a .install file to update existing view modes to use the db, it doesn't add a schema to add the new table. So I don't think it does what it is supposed to do.
Comment #18
dobe commentedSry about that. Try this one. As for the unrecognized input likely an issue with line endings. Should be fixed.
Comment #19
dobe commentedComment #20
socialnicheguru commentedI can't use the patch:
patch -p1 < 1702530-17.entity_view_mode.table-storage.patch
patch unexpectedly ends in middle of line
patch: **** Only garbage was found in the patch input.
Comment #21
dobe commentedLOL I have such a hard time with windows providing good patches.... Here is an updated. It applied cleanly on my linux box. I should have known with the difference in filesize.
Comment #22
dobe commentedComment #24
frobI can confirm that the patch applies cleanly.
Comment #25
dobe commentedThe last failing test is due to a test that checks if the functionality still works when a manual variable_set() is used to update entity_view_mode. I replaced it with a direct db update test. Not sure if we want this or not but let see if it works!
Comment #27
dobe commentedComment #28
dobe commentedComment #30
dobe commentedHmm. This is my last attempt at blindly swinging before I need to setup a testing environment on this box.
Comment #32
dobe commentedMaybe simpletest doesn't like drupal_write_record? Give this a quick try.
Comment #34
dobe commentedI am not sure what is failing here. I will have to check into it when I get in a testing environment.
Comment #35
frobIt looks like the variable_set call and the db_update call are not the same. You can see there is 'taxonomy_term' being set with an empty array in the variable set. I am not sure what that is doing, but it might be why these are not working.
Comment #36
frobThis is what I get for commenting, before I read the testbot fail message. The labels don't match.
The patch doesn't label things consistently.
Comment #37
frobBefore I start changing these test, I want to make sure this is working. So I will begin some manual testing to confirm the test is wrong.
I was just about to make the mistake of assuming that the test was wrong, so just change the test.
Comment #38
frobI think I found it.
There is a problem somewhere with the custom settings. It likely has to do with "custom_settings" vs "custom settings"
What I have noticed is the custom settings being shown don't reflect what they are for custom db view modes.
Comment #39
frobSo I worked on this a bit, it still needs more work.
The module is no longer updating the field settings when the view mode is updated and visa versa. So more work to be done.
I have attached an interdiff so you can see what I changed. We have enough patches that we should start to do interdiffs.
Comment #40
frobUpdated the summary.
Comment #41
dobe commentedHmm. I don't believe #39 is correct. I believe entity_get_info() returns "custom settings" not "custom_settings" however we have to store the data in the database with the underline. I think your patch may actually cause issues on the admin page. As you are setting "custom_settings" to a value that doesn't exist.
Comment #42
joachim commented> It likely has to do with "custom_settings" vs "custom settings"
I filed an issue and a patch for that issue: #2508313: hook_entity_view_mode_info() 'custom_settings' property is not being respected.
Comment #43
frob@dobe #39 was meant to address the admin pages being broken with the patch from #32.
The patch mentioned in #42 should fix the test issues, However, the admin will still be broken with the previous patch. This is because the module used to store everything with no underscore (this is how core field api needs it). When saving the module would change custom_settings into "custom settings"
My patch isn't right. that is why the issue is still marked as needs work. We need to figure out what we are going to do to keep everything in sync. I am thinking we need to leave the admin ui clean with custom_settings as it is in the DB and add some mapping from custom_settings into "custom settings" in the field_entity_view_mode_* functions. Keep the core specific conversions in the core portion and leave everything else as it is. Maybe we should just add a couple to/from mapping functions.
Comment #44
dobe commentedThis patch should pass tests. I removed the test to check the hooks after variable_set since we are not using it anymore and I don't really believe we need to test if the functionality works by modifying the database directly (not even sure simpletest supports this type of test).
This patch may also address https://www.drupal.org/node/2508313 by setting "custom settings" when we load from the db. I feel doing it here may be better as it makes sure that if someone uses those functions they shouldn't' have to do the conversion in there code. We also call one of the load functions in entity_view_mode_entity_info_alter().
This also solves the issue on the admin pages without modifying the admin file.
Comment #45
frobThe test that was set for testing after a variable set was testing view modes that where created in the ui. Otherwise, all that is being tested is the hook_implemented view modes. We need to still test the view modes that are created with the ui. I don't see how this could address #2508313: hook_entity_view_mode_info() 'custom_settings' property is not being respected.
Have you done any manual tests to make sure this patch works?
Comment #46
dobe commentedThe test that was removed has NOTHING to do with view modes created through the UI. Those tests are passing, they all happen in: function testEntityViewModes() which I did not have to modify (the first 58 tests, test the UI). I modified testInfoHooks() which most of the tests are still there. I only removed the one test that was used to test that the info hooks still worked after variable_set().
I have done manual tests. Everything seems functional. But that is also where the community comes in.
The current patch does what #2508313 does in entity_view_mode_load() and entity_view_mode_load_all() now instead of entity_view_mode_entity_info_alter().
Comment #47
frobtesting with new patch from #44
Comment #48
frobThe admin UI is broken.
From admin/config/system/entity-view-modes the user cannot set the view mode custom settings.
Also, the admin table column for showing if the Display mode has custom settings doesn't reflect the settings that are in the DB.
These are the things that I fixed in #39. I will not be submitting another patch any time soon, but I can still review your patches if you fix these bugs.
I updated the issue summary with things that are done and need to be done.
Comment #49
dobe commentedHmm. For some reason the unset in the save function showed back up which the first patch in this que removed... Not sure how that happened.
Comment #54
denix commentedThis fix the admin UI
Comment #56
denix commentedComment #57
denix commentedComment #59
frobI queued a new test of #56. For some reason the last patch tested was an old one I wrote in #39.
Comment #60
epophoto commentedI installed #56 locally and tested it adding a custom view mode, and looking at the presence of it in the database. I verified the view modes functionality within the content type structure interface, and deleted it.
Comment #61
denix commentedIs this going to be included in a next release?