When I create and save an entity reference field for file entity. It prompt below error.

Note: Undefined property: stdClass::$fid in file_entity_access()

Comments

jimmyko’s picture

Issue summary: View changes
jimmyko’s picture

Backtrace record generated by devel module.

14: file_entity_access() (Array, 2 elements)
13: entity_access() (Array, 2 elements)
12: inline_entity_form_settings() (Array, 2 elements)
11: inline_entity_form_get_controller() (Array, 2 elements)
10: inline_entity_form_field_widget_settings_form() (Array, 2 elements)
9: call_user_func_array() (Array, 1 element)
8: module_invoke() (Array, 2 elements)
7: field_ui_field_edit_form() (Array, 2 elements)
6: call_user_func_array() (Array, 1 element)
5: drupal_retrieve_form() (Array, 2 elements)
4: drupal_build_form() (Array, 2 elements)
3: drupal_get_form() (Array, 2 elements)
2: call_user_func_array() (Array, 1 element)
1: menu_execute_active_handler() (Array, 2 elements)
0: main() (Array, 2 elements)

jimmyko’s picture

Details of the last function called:

14: file_entity_access() (Array, 2 elements)

    file (String, 53 characters ) sites/all/modules/file_entity/file_entity.modul...
        sites/all/modules/file_entity/file_entity.module:1629
    args (Array, 4 elements)
        0 (String, 6 characters ) create
        1 (Object) stdClass
            type (String, 12 characters ) project_file
            filename (NULL)
            is_new (Boolean) TRUE
        2 (NULL)
        3 (String, 4 characters ) file | (Callback) file();
jimmyko’s picture

I created a patch for detecting if fid property is existing.

dave reid’s picture

Status: Active » Needs review
StatusFileSize
new802 bytes

Let's try this version.

dave reid’s picture

Version: 7.x-2.0-alpha3 » 7.x-2.x-dev
jimmyko’s picture

Maybe we can just remove it

$cache_id = Null

jimmyko’s picture

StatusFileSize
new725 bytes
mkhamash’s picture

I think this patch helps to solve a lot other issues, especially for modules like media_internet and feeds integration modules since most of them will create a file object using file_uri_to_object() and will not have a fid yet and are trying to validate the file (file type) using file_entity_access().

jimmyko’s picture

Status: Needs review » Reviewed & tested by the community
neograph734’s picture

This also covers an issue when files are uploaded using Services API and its REST submodule. Took us quite a while to figure out this was a function of file_entity and not core...

Would be nice to get this in the next release.

rajab natshah’s picture

+1

rajab natshah’s picture

Tested - still works with 2.0-beta3

jimmyko’s picture

Can any contributor of this module can help to review and confirm this patch?

lessmoreless’s picture

Is there by any chance of editing the module from the backend, instead of accessing the files, I have run into the above error and ive got limited access to the files but just the backend.

sheena_d’s picture

I've run into an issue where a contrib module actually passes an empty new entity to entity_access(). This results in an inaccurate access denied result for users who are allowed to create new file entities.

I'm attaching a patch that supports the instance of a new, empty file entity being passed in to check for creation access.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 16: fix_entity_api_create_access-2312603-16.patch, failed testing.

sheena_d’s picture

Trying my patch again.

alison’s picture

Hi all, I was getting this error when my feeds importer ran (it maps feed items to Event nodes, including images getting mapped to an image field on the Event content type). I applied the patch from #5 and the errors went away -- yay! I have file_entity 7.x-2.2, I just finally updated from 7.x-2.0-beta3 last week -- I'm confident that the errors started after the update, I confirmed on a different environment that they were not happening before.

I'm not sure if the situation described in #16 applies to me, so that's why I held off on trying the later versions of the patch, but I'll keep following this issue. Thanks for all the patchwork ;-)

(in other words, *bump* haha)

joseph.olstad’s picture

Status: Needs work » Needs review
joseph.olstad’s picture

I prefer initializing cache_id for scope, as did Dave Reid
see patch

interdiff is this:
+ $cache_id = NULL;

joseph.olstad’s picture

Hi @alisonjo2786 , can you please back off patch #5 and try out patch #21 instead? Then please report the test results back here.

Thanks

  • Dave Reid authored 27c1b77 on 7.x-2.x
    Issue #2312603 by jimmyko, sheena_d, joseph.olstad, Dave Reid: Undefined...
joseph.olstad’s picture

Status: Needs review » Fixed
alison’s picture

Hi @joseph.olstad -- yeppers!

-- Reversed patch from #5, confirmed that the notices happen at that point ("just in case")
-- Applied patch from #21 -- no more notices
-- (and no side effects on other stuff, AFAIsee -- i.e. files are coming in with my imported feed items and getting mapped/saved on my event nodes just fine)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.