Timeline for Reassign $view_mode using entity field passed to hook_entity_view_mode_alter()
Current License: CC BY-SA 4.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 29, 2018 at 14:02 | comment | added | J W | I did make an update after reading your answer. Removing the entity save corrected this issue. I was able to get the correct view mode using your code above. Thanks again for taking time out of your day to help. | |
Sep 29, 2018 at 13:50 | comment | added | sonfd |
To clarify a little, you were setting $entity->view_mode and then saving the entity rather than just setting the $view_mode var that this hook uses. I'm not sure if you've updated that after reading my answer, but that's just wrong, you shouldn't change the entity and save it here.
|
|
Sep 29, 2018 at 13:37 | comment | added | sonfd | I reckon that error is caused by your code you use to create the field and not the code you posted above. My best guess is that Drupal don't know which formatter it can use for your custom field (change_view). If you comment this entire hook, you still get the error, right? | |
Sep 29, 2018 at 3:29 | comment | added | J W | Thanks for looking at this with me. Even if I remove the intermediary assignment to $change_to_view_mode, I get the same WSOD with the same issue . I do see that $view_mode is now set to standard prior to the drupal_set_messages. Which is fine, I was just adding the intermediate variable to see if my code was executing. However, there is still something hinky going on which presents itself in the error log as if there is an array/single value issue but I'm still thinking its a cache issue somehow. | |
Sep 29, 2018 at 3:20 | history | answered | sonfd | CC BY-SA 4.0 |