Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I found a bug. It only outputs a PHP notice but it could be avoided with an if statement methinks...
Steps to reproduce:
- Install module
- enable module
- configure module
- under Node, click 'Add new view mode'
- Label > 'Teaser 2'
- leave 'Use custom display settings' checked.
- uncheck all but content type, 'Art Gallery'
- click save.
- error displayed:
Notice: Undefined index: teaser_2 in field_entity_view_mode_update() (line 179 of /srv/www/.../.../all/modules/entity_view_mode/entity_view_mode.module).
There's also a similar error on delete of a view mode:
Notice: Undefined index: machine_name in field_entity_view_mode_delete() (line 204 of /home/.../all/modules/entity_view_mode/entity_view_mode.module).
Comment | File | Size | Author |
---|---|---|---|
#13 | 1738644-fix-php-notices.patch | 1.49 KB | Dave Reid |
#9 | entity_view_modes_create_delete_errors-1738644-9.patch | 7.24 KB | ShaunDychko |
#6 | entity-view-modes-create-delete-errors-1738644-6.patch | 15.27 KB | RobW |
#4 | entity_view_mode.zip | 2.94 KB | anandkp |
Comments
Comment #1
RobW CreditAttribution: RobW commentedI get this too, but only on creation of a new view mode. One refresh and it's gone. Maybe a race condition?
Comment #2
RobW CreditAttribution: RobW commentedThere's also a similar error on delete of a view mode:
Notice: Undefined index: machine_name in field_entity_view_mode_delete() (line 204 of /home/.../all/modules/entity_view_mode/entity_view_mode.module).
Added to the issue description.
Comment #3
anandkp CreditAttribution: anandkp commentedThanks and Kudos!!!
Many thanks to Dave Reid for making this module. Being able to add View Modes easily without hand-coding it makes life A LOT easier. I'm using the module to allow for simple, semantic and Drupally customisation of formats using View Modes for the following modules: Field Collections, Media (and through it the File entities) and Panels.
I'm really sorry that I still haven't learned how to make patch files. I'm uploading my version of entity_view_mode/entity_view_mode.module and citing the old/new code below as well.
Notice On Save
Perceived Cause
I believe that the fact that the View Mode is new was not being carried forward to field_entity_view_mode_update() - which is called by both hook_entity_view_mode_insert() as well as hook_entity_view_mode_update() - was causing this problem. After saving the View Mode (new or old - save or update), the module produces a helper message that tries to get the $label of the View Mode for use in the message.
By updating the both hooks - hook_entity_view_mode_insert and hook_entity_view_mode_update - so that they provide an additional argument, $is_new (which is set before they're invoked in entity_view_mode_save()), the boolean can be used to decide where the label is supposed to come from.
Suggested code follows:
ORIGINAL CODE
UPDATED CODE
ORIGINAL CODE
UPDATED CODE
Notice on Delete View Mode
Perceived Cause
I think that the notices mentioned above are due to the non-existence of the "machine_name" array key in the $view_mode variable as it is passed to both field_entity_view_mode_update()and field_entity_view_mode_delete().
The PHP Notices went away when I updated entity_view_mode_load() as follows:
ORIGINAL CODE
UPDATED CODE
One other tiny fix was needed...
I found a variable-name typo in field_entity_view_mode_delete()... $bundle_settings is spelled as $bundles_settings on the line just below it:
ORIGINAL CODE
UPDATED CODE
Comment #4
anandkp CreditAttribution: anandkp commentedSorry, forgot to attach the file in my post above... Here's the modified file:
entity_view_mode.module
Comment #5
anandkp CreditAttribution: anandkp commentedAlso forgot to update the Status of the issue... Sorry!
Comment #6
RobW CreditAttribution: RobW commentedanandps, awesome post and summary. You have the skills to make a patch, for sure! Check out http://drupal.org/node/707484 next time you have an hour to bring your game to the next level.
In the meantime, here's a patch of your changes:
[edit] There are a bunch of changes in there that are just whitespace removal, not in alignment with Drupal coding standards. That makes it harder to review. Something to think about for next time.
Comment #7
anandkp CreditAttribution: anandkp commentedHey there RobW!
Thank you very much for the link, I'll be reading that asap!
Regarding the whitespaces, I use PHPStorm as my IDE and have been trying to make it more Drupal-friendly. I've heard about a module that does a code check for you... a colleague at work had mentioned it once upon a time. I'll be sure to look that up and get my IDE into line!
(If the whitespaces were bad, I guess I shouldn't tell you that I used to use the tab character... :-O )
Once again, thanks for the input!
Comment #8
Dave ReidThere is a lot of unrelated whitespace changes, I cannot commit this patch as is and makes this much harder to review.
Comment #9
ShaunDychko CreditAttribution: ShaunDychko commentedI have updated the patch to show only non-trivial changes. Unfortunately, this introduces a new error message.
When adding a new view mode for files, if you deselect Images, Documents, and Audio, leaving only Video selected, you will get the error message:
The error message does not appear if you leave all media types selected.
Should we open a new issue for this?
Comment #10
hargobind@anandps, great job on these edits, and thank you @ShaunDychko for creating a clean patch. I've tested and verify that it is working.
A little bit of cleanup needs to be done in the merged file -- the capitalization of some of the new comments, spacing fixes on line 113 (
$is_new =...
) and 131 (array('machine_name'...
), and the TRUE/FALSE values at the end of line 112 are unnecessary sinceisset()
returns boolean.Apart from these little details, I think the patch in #9 is good to go to address the original issue.
The issue that Shaun brought up about view modes for files isn't specific to the original topic, but perhaps @DaveReid can make the decision about whether to open a new issue for it.
Comment #11
rooby CreditAttribution: rooby commentedI can confirm that the patch in #9 fixes the bug in the original post.
However I can also confirm the new bug:
Which happens whenever you create a view mode for the file entity.
(I am using file_entity 7.x-2.x-dev as of today).
All other entity types I have tried seem ok (user, node, comment, taxonomy, bean).
Here are some nit-picky code reviews (I have not done a technical review).
Comments should be in sentance case and have full stops.
Lines should also should not be longer than 80 characters.
Comment lines should not be longer than 80 characters and end with full stops.
This is unnecessary and breaks the 80 character comment line rule.
Comment #12
kaizerking CreditAttribution: kaizerking commentedThe test_view_mode Node test_node view mode now uses custom display settings. You might want to configure them. clicking on the configure them redirects to a new page.
it should be on the same page
Comment #13
Dave ReidI'm not seeing a whole lot why the patch in #9 is necessary. It looks like this can be fixed with just a few small things?
Comment #14
Dave ReidThese PHP notices were fixed with #1900686: Write functional tests. I credited people in this issue with that issues' commit message. Marking as fixed.
Comment #16
Summit CreditAttribution: Summit commentedHi, sorry to possible open this closed issue, but using entity_view_mode and DS together I got these errors;
I think they are related with this issue right? Otherwise sorry for reopening issue.
i use latest .dev
greetings, Martijn
Comment #17
Dave ReidI would file an issue in display suite first. None of those errors lead me to believe it's a bug caused by entity_view_mode. But if they can track it down further and trace it back I'd be happy to have a look.
Comment #18
rajmataj CreditAttribution: rajmataj commentedI am getting this error after recently installing entity_view_mode 7.x-1.0-rc1 on a Drupal 7.23 site. I was attempted to create a new view mode for the Media module, to have a custom image size. Note, I do not have Display Suite installed.
Notice: Undefined index: default in _field_ui_add_default_view_mode_settings() (line 1429 of /[...]/[...]/[...]/modules/field_ui/field_ui.admin.inc).
Comment #19
bkosborneAlso received this notice after creating a new view mode. Do not have Display Suite enabled. Noteable modules that I do have enabled are Media (7.x-2.0-alpha2) and File Entity (7.x-2.0-alpha2)
Comment #19.0
bkosborneupdated with on delete error
Comment #20
Jason2014 CreditAttribution: Jason2014 commentedI am having the same issue. I also have the Media 7.x-1.4 and File Entity 7.x-1.4 modules installed. I installed entity_view_mode 7.x-1.0-rc1. Im on a Drupal 7.26 site. When I created a new view. I received the same message:
Notice: Undefined index: default in _field_ui_add_default_view_mode_settings() (line 1429 of /home/xxxxx/public_html/modules/field_ui/field_ui.admin.inc).