upon upgrading to ogx2, which uses entity references, get these errors when view the panels layout, e.g. /admin/structure/pages/nojs/operation/node_view/handlers/node_view_panel_context/content

Notice: Trying to get property of non-object in flag_entity->applies_to_content_object() (line 1391 of /www/www-staging/drupal.sandbox.sanger.ac.uk/htdocs/sites/all/modules/contrib/flag/flag.inc).

CommentFileSizeAuthor
#11 flag-null_entity-2135865-11.patch612 bytesmaximpodorov
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

Version: 7.x-2.1 » 7.x-2.x-dev
Status: Active » Postponed (maintainer needs more info)

What's ogx2?

Can you debug to find out why Flag doesn't get what it's expecting there?

StephenRobinson’s picture

organic groups v2

StephenRobinson’s picture

tried this

  /**
   * Checks whether the flag applies for the current entity bundle.
   */
  function applies_to_content_object($entity) {
    $entity_info = entity_get_info($this->content_type);
    drupal_set_message('entity_info<pre>'.htmlspecialchars(print_r($entity_info,1)).'</pre>');
    drupal_set_message('entity<pre>'.htmlspecialchars(print_r($entity,1)).'</pre>');
    drupal_set_message('this<pre>'.htmlspecialchars(print_r($this,1)).'</pre>');

and got

entity_info
Array
(
    [label] => Node
    [controller class] => NodeController
    [base table] => node
    [revision table] => node_revision
    [uri callback] => node_uri
    [fieldable] => 1
    [entity keys] => Array
        (
            [id] => nid
            [revision] => vid
            [bundle] => type
            [label] => title
            [language] => language
        )

    [bundle keys] => Array
        (
            [bundle] => type
        )

    [bundles] => Array
        (
            [campus_event] => Array
                (
                    [label] => Campus Event
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/campus-event
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [chitchat] => Array
                (
                    [label] => Chit Chat item
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/chitchat
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [corporate_news] => Array
                (
                    [label] => Corporate News
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/corporate-news
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [domain_book] => Array
                (
                    [label] => Domain Book page
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/domain-book
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [forum_general_topic] => Array
                (
                    [label] => Forum general topic
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/forum-general-topic
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [forum] => Array
                (
                    [label] => Forum topic
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/forum
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [group] => Array
                (
                    [label] => Group
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/group
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [group_event] => Array
                (
                    [label] => Group event
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/group-event
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [book] => Array
                (
                    [label] => Groups Book page
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/book
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [home_feature] => Array
                (
                    [label] => Home Feature
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/home-feature
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [noticeboard] => Array
                (
                    [label] => Notice board item
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/noticeboard
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [page] => Array
                (
                    [label] => Page
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/page
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [panel] => Array
                (
                    [label] => Panel
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/panel
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [poll] => Array
                (
                    [label] => Poll
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/poll
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [post] => Array
                (
                    [label] => Post
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/post
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [red_alert] => Array
                (
                    [label] => Red Alert
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/red-alert
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [service] => Array
                (
                    [label] => Service or Resource
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/service
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [story] => Array
                (
                    [label] => Story
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/story
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [user] => Array
                (
                    [label] => User
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/user
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [webform] => Array
                (
                    [label] => Webform
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/webform
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

        )

    [view modes] => Array
        (
            [full] => Array
                (
                    [label] => Full content
                    [custom settings] => 
                )

            [teaser] => Array
                (
                    [label] => Teaser
                    [custom settings] => 1
                )

            [rss] => Array
                (
                    [label] => RSS
                    [custom settings] => 
                )

            [search_index] => Array
                (
                    [label] => Search index
                    [custom settings] => 
                )

            [search_result] => Array
                (
                    [label] => Search result
                    [custom settings] => 
                )

            [print] => Array
                (
                    [label] => Print
                    [custom settings] => 
                )

            [diff_standard] => Array
                (
                    [label] => Revision comparison
                    [custom settings] => 
                )

            [token] => Array
                (
                    [label] => Tokens
                    [custom settings] => 
                )

        )

    [static cache] => 1
    [field cache] => 1
    [load hook] => node_load
    [translation] => Array
        (
        )

    [schema_fields_sql] => Array
        (
            [base table] => Array
                (
                    [0] => nid
                    [1] => vid
                    [2] => type
                    [3] => language
                    [4] => title
                    [5] => uid
                    [6] => status
                    [7] => created
                    [8] => changed
                    [9] => comment
                    [10] => promote
                    [11] => sticky
                    [12] => tnid
                    [13] => translate
                )

            [revision table] => Array
                (
                    [0] => nid
                    [1] => vid
                    [2] => uid
                    [3] => title
                    [4] => log
                    [5] => timestamp
                    [6] => status
                    [7] => comment
                    [8] => promote
                    [9] => sticky
                )

        )

    [apachesolr] => Array
        (
            [indexable] => 1
            [status callback] => Array
                (
                    [0] => apachesolr_index_node_status_callback
                )

            [document callback] => Array
                (
                    [0] => apachesolr_index_node_solr_document
                )

            [reindex callback] => apachesolr_index_node_solr_reindex
            [bundles changed callback] => apachesolr_index_node_bundles_changed
            [index_table] => apachesolr_index_entities_node
            [cron_check] => apachesolr_index_node_check_table
            [result callback] => apachesolr_search_node_result
        )

    [token type] => node
    [plural label] => Nodes
    [description] => Nodes represent the main site content items.
    [access callback] => entity_metadata_no_hook_node_access
    [creation callback] => entity_metadata_create_node
    [save callback] => node_save
    [deletion callback] => node_delete
    [revision deletion callback] => node_revision_delete
    [form callback] => entity_metadata_form_node
    [view callback] => entity_metadata_view_node
    [configuration] => 
)
entity
this
flag_node Object
(
    [fid] => 1
    [content_type] => node
    [name] => bookmarks
    [title] => Bookmarks
    [global] => 0
    [types] => Array
        (
            [0] => book
            [1] => group
            [2] => forum
            [3] => forum_general_topic
            [4] => domain_book
            [5] => corporate_news
            [6] => campus_event
            [7] => page
            [8] => service
            [9] => story
            [10] => webform
        )

    [flag_short] => Bookmark this
    [flag_long] => Add this post to your bookmarks
    [flag_message] => This item has been added to your bookmarks
    [unflag_short] => Unbookmark this
    [unflag_long] => Remove this item from your bookmarks
    [unflag_message] => This item has been removed from your bookmarks
    [unflag_denied_text] => 
    [link_type] => toggle
    [roles] => Array
        (
            [flag] => Array
                (
                    [0] => 2
                    [1] => 7
                    [2] => 8
                    [3] => 4
                    [4] => 9
                    [5] => 6
                    [6] => 12
                    [7] => 5
                    [8] => 10
                    [9] => 3
                    [10] => 11
                )

            [unflag] => Array
                (
                    [0] => 2
                    [1] => 7
                    [2] => 8
                    [3] => 4
                    [4] => 9
                    [5] => 6
                    [6] => 12
                    [7] => 5
                    [8] => 10
                    [9] => 3
                    [10] => 11
                )

        )

    [weight] => 0
    [show_on_form] => 0
    [access_author] => 
    [show_on_page] => 1
    [show_on_teaser] => 0
    [show_contextual_link] => 
    [i18n] => 0
    [module] => flagsettings
    [locked] => Array
        (
            [name] => name
        )

)
entity_info
Array
(
    [label] => Node
    [controller class] => NodeController
    [base table] => node
    [revision table] => node_revision
    [uri callback] => node_uri
    [fieldable] => 1
    [entity keys] => Array
        (
            [id] => nid
            [revision] => vid
            [bundle] => type
            [label] => title
            [language] => language
        )

    [bundle keys] => Array
        (
            [bundle] => type
        )

    [bundles] => Array
        (
            [campus_event] => Array
                (
                    [label] => Campus Event
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/campus-event
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [chitchat] => Array
                (
                    [label] => Chit Chat item
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/chitchat
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [corporate_news] => Array
                (
                    [label] => Corporate News
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/corporate-news
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [domain_book] => Array
                (
                    [label] => Domain Book page
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/domain-book
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [forum_general_topic] => Array
                (
                    [label] => Forum general topic
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/forum-general-topic
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [forum] => Array
                (
                    [label] => Forum topic
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/forum
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [group] => Array
                (
                    [label] => Group
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/group
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [group_event] => Array
                (
                    [label] => Group event
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/group-event
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [book] => Array
                (
                    [label] => Groups Book page
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/book
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [home_feature] => Array
                (
                    [label] => Home Feature
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/home-feature
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [noticeboard] => Array
                (
                    [label] => Notice board item
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/noticeboard
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [page] => Array
                (
                    [label] => Page
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/page
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [panel] => Array
                (
                    [label] => Panel
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/panel
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [poll] => Array
                (
                    [label] => Poll
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/poll
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [post] => Array
                (
                    [label] => Post
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/post
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [red_alert] => Array
                (
                    [label] => Red Alert
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/red-alert
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [service] => Array
                (
                    [label] => Service or Resource
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/service
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [story] => Array
                (
                    [label] => Story
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/story
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                )

            [user] => Array
                (
                    [label] => User
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/user
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

            [webform] => Array
                (
                    [label] => Webform
                    [admin] => Array
                        (
                            [path] => admin/structure/types/manage/%node_type
                            [real path] => admin/structure/types/manage/webform
                            [bundle argument] => 4
                            [access arguments] => Array
                                (
                                    [0] => administer content types
                                )

                        )

                    [apachesolr] => Array
                        (
                            [index] => 1
                        )

                )

        )

    [view modes] => Array
        (
            [full] => Array
                (
                    [label] => Full content
                    [custom settings] => 
                )

            [teaser] => Array
                (
                    [label] => Teaser
                    [custom settings] => 1
                )

            [rss] => Array
                (
                    [label] => RSS
                    [custom settings] => 
                )

            [search_index] => Array
                (
                    [label] => Search index
                    [custom settings] => 
                )

            [search_result] => Array
                (
                    [label] => Search result
                    [custom settings] => 
                )

            [print] => Array
                (
                    [label] => Print
                    [custom settings] => 
                )

            [diff_standard] => Array
                (
                    [label] => Revision comparison
                    [custom settings] => 
                )

            [token] => Array
                (
                    [label] => Tokens
                    [custom settings] => 
                )

        )

    [static cache] => 1
    [field cache] => 1
    [load hook] => node_load
    [translation] => Array
        (
        )

    [schema_fields_sql] => Array
        (
            [base table] => Array
                (
                    [0] => nid
                    [1] => vid
                    [2] => type
                    [3] => language
                    [4] => title
                    [5] => uid
                    [6] => status
                    [7] => created
                    [8] => changed
                    [9] => comment
                    [10] => promote
                    [11] => sticky
                    [12] => tnid
                    [13] => translate
                )

            [revision table] => Array
                (
                    [0] => nid
                    [1] => vid
                    [2] => uid
                    [3] => title
                    [4] => log
                    [5] => timestamp
                    [6] => status
                    [7] => comment
                    [8] => promote
                    [9] => sticky
                )

        )

    [apachesolr] => Array
        (
            [indexable] => 1
            [status callback] => Array
                (
                    [0] => apachesolr_index_node_status_callback
                )

            [document callback] => Array
                (
                    [0] => apachesolr_index_node_solr_document
                )

            [reindex callback] => apachesolr_index_node_solr_reindex
            [bundles changed callback] => apachesolr_index_node_bundles_changed
            [index_table] => apachesolr_index_entities_node
            [cron_check] => apachesolr_index_node_check_table
            [result callback] => apachesolr_search_node_result
        )

    [token type] => node
    [plural label] => Nodes
    [description] => Nodes represent the main site content items.
    [access callback] => entity_metadata_no_hook_node_access
    [creation callback] => entity_metadata_create_node
    [save callback] => node_save
    [deletion callback] => node_delete
    [revision deletion callback] => node_revision_delete
    [form callback] => entity_metadata_form_node
    [view callback] => entity_metadata_view_node
    [configuration] => 
)
entity
this
flag_node Object
(
    [fid] => 4
    [content_type] => node
    [name] => follow
    [title] => Follow
    [global] => 0
    [types] => Array
        (
            [0] => book
            [1] => group
            [2] => forum
            [3] => forum_general_topic
            [4] => domain_book
            [5] => corporate_news
            [6] => chitchat
            [7] => campus_event
            [8] => noticeboard
            [9] => page
            [10] => service
        )

    [flag_short] => Follow
    [flag_long] => Click this to recieve notification updates when this page changes
    [flag_message] => You are now following "[node:title]"
    [unflag_short] => Stop following
    [unflag_long] => Click this to stop recieving notification updates when this page changes
    [unflag_message] => You are now no longer following "[node:title]"
    [unflag_denied_text] => 
    [link_type] => toggle
    [roles] => Array
        (
            [flag] => Array
                (
                    [0] => 7
                    [1] => 8
                    [2] => 4
                    [3] => 9
                    [4] => 6
                    [5] => 12
                    [6] => 5
                    [7] => 10
                    [8] => 3
                    [9] => 11
                )

            [unflag] => Array
                (
                    [0] => 7
                    [1] => 8
                    [2] => 4
                    [3] => 9
                    [4] => 6
                    [5] => 12
                    [6] => 5
                    [7] => 10
                    [8] => 3
                    [9] => 11
                )

        )

    [weight] => 0
    [show_on_form] => 0
    [access_author] => 
    [show_on_page] => 1
    [show_on_teaser] => 0
    [show_contextual_link] => 
    [i18n] => 0
    [module] => flagsettings
    [locked] => Array
        (
            [name] => name
        )

)
StephenRobinson’s picture

the new organic groups uses the project entityreference?

StephenRobinson’s picture

the this:

  function applies_to_content_object($entity) {
    $entity_info = entity_get_info($this->content_type);
    drupal_set_message('entity_info entity keys bundle='.$entity_info['entity keys']['bundle']);
    drupal_set_message('this types=<pre>'.print_r($this->types,1).'</pre>');
    drupal_set_message('entity_info entity keys bundle='.$entity_info['entity keys']['bundle']);
    drupal_set_message('entity entity_info entity keys bundle='.$entity->{$entity_info['entity keys']['bundle']});

and got

entity_info entity keys bundle=type
this types=
Array
(
    [0] => book
    [1] => group
    [2] => forum
    [3] => forum_general_topic
    [4] => domain_book
    [5] => corporate_news
    [6] => campus_event
    [7] => page
    [8] => service
    [9] => story
    [10] => webform
)
entity_info entity keys bundle=type
entity entity_info entity keys bundle=
entity_info entity keys bundle=type
this types=
Array
(
    [0] => book
    [1] => group
    [2] => forum
    [3] => forum_general_topic
    [4] => domain_book
    [5] => corporate_news
    [6] => chitchat
    [7] => campus_event
    [8] => noticeboard
    [9] => page
    [10] => service
)
entity_info entity keys bundle=type
entity entity_info entity keys bundle=
StephenRobinson’s picture

$entity appears to be null...

StephenRobinson’s picture

  function applies_to_content_object($entity) {
    $entity_info = entity_get_info($this->content_type);
    drupal_set_message('entity=<pre>'.print_r($entity,1).'</pre>');
    ......
  function applies_to_content_id($content_id) {
    drupal_set_message('applies_to_content_id<pre>'.print_r($this,1).'</pre>');
    drupal_set_message('this applies_to_content_object this fetch_content content_id='.$this->applies_to_content_object($this->fetch_content($content_id)));
    return $this->applies_to_content_object($this->fetch_content($content_id));
  }

and got

applies_to_content_id
flag_node Object
(
    [fid] => 1
    [content_type] => node
    [name] => bookmarks
    [title] => Bookmarks
    [global] => 0
    [types] => Array
        (
            [0] => book
            [1] => group
            [2] => forum
            [3] => forum_general_topic
            [4] => domain_book
            [5] => corporate_news
            [6] => campus_event
            [7] => page
            [8] => service
            [9] => story
            [10] => webform
        )

    [flag_short] => Bookmark this
    [flag_long] => Add this post to your bookmarks
    [flag_message] => This item has been added to your bookmarks
    [unflag_short] => Unbookmark this
    [unflag_long] => Remove this item from your bookmarks
    [unflag_message] => This item has been removed from your bookmarks
    [unflag_denied_text] => 
    [link_type] => toggle
    [roles] => Array
        (
            [flag] => Array
                (
                    [0] => 2
                    [1] => 7
                    [2] => 8
                    [3] => 4
                    [4] => 9
                    [5] => 6
                    [6] => 12
                    [7] => 5
                    [8] => 10
                    [9] => 3
                    [10] => 11
                )

            [unflag] => Array
                (
                    [0] => 2
                    [1] => 7
                    [2] => 8
                    [3] => 4
                    [4] => 9
                    [5] => 6
                    [6] => 12
                    [7] => 5
                    [8] => 10
                    [9] => 3
                    [10] => 11
                )

        )

    [weight] => 0
    [show_on_form] => 0
    [access_author] => 
    [show_on_page] => 1
    [show_on_teaser] => 0
    [show_contextual_link] => 
    [i18n] => 0
    [module] => flagsettings
    [locked] => Array
        (
            [name] => name
        )

)
entity=
this applies_to_content_object this fetch_content content_id=
entity=
applies_to_content_id
flag_node Object
(
    [fid] => 4
    [content_type] => node
    [name] => follow
    [title] => Follow
    [global] => 0
    [types] => Array
        (
            [0] => book
            [1] => group
            [2] => forum
            [3] => forum_general_topic
            [4] => domain_book
            [5] => corporate_news
            [6] => chitchat
            [7] => campus_event
            [8] => noticeboard
            [9] => page
            [10] => service
        )

    [flag_short] => Follow
    [flag_long] => Click this to recieve notification updates when this page changes
    [flag_message] => You are now following "[node:title]"
    [unflag_short] => Stop following
    [unflag_long] => Click this to stop recieving notification updates when this page changes
    [unflag_message] => You are now no longer following "[node:title]"
    [unflag_denied_text] => 
    [link_type] => toggle
    [roles] => Array
        (
            [flag] => Array
                (
                    [0] => 7
                    [1] => 8
                    [2] => 4
                    [3] => 9
                    [4] => 6
                    [5] => 12
                    [6] => 5
                    [7] => 10
                    [8] => 3
                    [9] => 11
                )

            [unflag] => Array
                (
                    [0] => 7
                    [1] => 8
                    [2] => 4
                    [3] => 9
                    [4] => 6
                    [5] => 12
                    [6] => 5
                    [7] => 10
                    [8] => 3
                    [9] => 11
                )

        )

    [weight] => 0
    [show_on_form] => 0
    [access_author] => 
    [show_on_page] => 1
    [show_on_teaser] => 0
    [show_contextual_link] => 
    [i18n] => 0
    [module] => flagsettings
    [locked] => Array
        (
            [name] => name
        )

)
entity=
this applies_to_content_object this fetch_content content_id=
entity=
StephenRobinson’s picture

  function applies_to_content_object($entity) {
    $entity_info = entity_get_info($this->content_type);
    drupal_set_message('entity=<pre>'.print_r($entity,1).'</pre>');
    ......
  function applies_to_content_id($content_id) {
    drupal_set_message('content_id='.print_r($content_id,1));
    drupal_set_message('this fetch_content content_id ='.$this->fetch_content($content_id));

and got


content_id=structure
this fetch_content content_id =
entity=
content_id=structure
this fetch_content content_id =
entity=
StephenRobinson’s picture

this seems to fix it without any noticable side effects:

  /**
   * Checks whether the flag applies for the current entity bundle.
   */
  function applies_to_content_object($entity) {
    if(is_object($entity)){ // added
      $entity_info = entity_get_info($this->content_type);
      if (empty($entity_info['entity keys']['bundle']) || in_array($entity->{$entity_info['entity keys']['bundle']}, $this->types)) {
        return TRUE;
      }
    } // added
    return FALSE;
  }
joachim’s picture

$entity should not be NULL. Can you figure out who's calling that improperly?

BTW, very good debugging!
I recommend the use of devel module, as its dpr() and dpm() functions will save you a lot of typing :)

maximpodorov’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
612 bytes

It's Flag module who passes NULL object into entity hooks. This commit
http://drupalcode.org/project/flag.git/commitdiff/ed26347
unconditionally passes $flagging variable into entity_presave hooks. The patch fixes this.

Status: Needs review » Needs work

The last submitted patch, 11: flag-null_entity-2135865-11.patch, failed testing.

maximpodorov’s picture

Sorry, my patch was for 7.x-3.x version. Maybe it should go to e new issue.

joachim’s picture

I don't think your patch is related to this issue.

maximpodorov’s picture

OK? I've created new issue: #2162925: Passing NULL to entity hooks.

joachim’s picture

#2162925: Passing NULL to entity hooks is now fixed, but it's unrelated to this issue because on 2.x flagging records are not entities.

hyside’s picture

I was also running into this issue, attempting to view flagged content of all types in a custom view whenever a user attempted to view that page with no content actually flagged yet. The issue was in flag.inc around line 1391, trying to read a non-object when there were no flagged items, so I added a validity check on $entity prior to attempting to read it.

Moving from this:

function applies_to_content_object($entity) {
    $entity_info = entity_get_info($this->content_type);
    if (empty($entity_info['entity keys']['bundle']) || in_array($entity->{$entity_info['entity keys']['bundle']}, $this->types)) {
      return TRUE;
    }
    return FALSE;
  }

To this:

  function applies_to_content_object($entity) {
    $entity_info = entity_get_info($this->content_type);
    if (empty($entity_info['entity keys']['bundle'])) {
      return TRUE;
    }
    else if ($entity) {
        if (in_array($entity->{$entity_info['entity keys']['bundle']}, $this->types)) {
            return TRUE;
        }
    }
    return FALSE;
  }
joachim’s picture

> I was also running into this issue, attempting to view flagged content of all types in a custom view whenever a user attempted to view that page with no content actually flagged yet.

I don't quite follow your setup. Could you explain in a bit more detail please? It sounds like you're talking about a VBO -- is that the case?

hyside’s picture

I was trying to create a page that showed all content that had been flagged for a given user with links to each of those pieces of flagged content using something like this to create the links

if (isset($_GET['q'])) {
  $current_nid = explode('/',@$_GET['q']);
  $current_nid = empty($current_nid[1]) ? 'tmp' : $current_nid[1];
  print flag_create_link('your_saved_links', $current_nid);
}

Not sure if this helps point you in the right direction?

joachim’s picture

Oh dear me. First off, use Views for something like that.

Second, use arg() instead of $_GET['q'].

Third, you're possibly setting $current_nid to the string 'tmp', which clearly isn't a node ID. It's not surprising that Flag chokes on that!