We need to check if the entity is set within the entity_ui_get_page_title function. So we don't result in getting a PHP fatal error "Call to a member function label() on a non-object".

Files: 
CommentFileSizeAuthor
#6 entity-entity_ui_get_page_title-1777110-6.patch1.47 KBpachabhaiya
PASSED: [[SimpleTest]]: [MySQL] 630 pass(es).
[ View ]
#5 entity-entity_ui_get_page_title-1777110-4.patch773 bytessachin_hj
#3 entity-entity_ui_get_page_title-1777110-3.patch1.83 KBlevelos
PASSED: [[SimpleTest]]: [MySQL] 409 pass(es).
[ View ]
#1 entity_ui_get_page_title_needs_to_check_if_entity_is_null.1777110-1.patch1.46 KBdroath
PASSED: [[SimpleTest]]: [MySQL] 374 pass(es).
[ View ]

Comments

droath’s picture

Status:Active» Needs review
StatusFileSize
new1.46 KB
PASSED: [[SimpleTest]]: [MySQL] 374 pass(es).
[ View ]
eojthebrave’s picture

I think that I'm encountering this issue as well. I've got a hook_entity_info() implementation with the following in it.

    'admin ui' => array(
      'path' => 'admin/memberships',
      'file' => 'membership_entity.pages.inc',
      'controller class' => 'EntityDefaultUIController',
      'menu wildcard' => '%membership_entity',
    ),

And this works fine in terms of regular expected usage and managing entities. However if you navigate to a page like 'admin/membership/asdf/fdsa' which isn't a valid menu path it gets the closest match which is 'admin/memberships', and then ends up calling entity_ui_get_page_title() with $entity = 'asdf' which results in a fatal error.

I think a check like what is in the above test is in the right direction but should probably do an is_object($entity) check instead of an isset($entity) since $entity could be just set to whatever string is in the path.

levelos’s picture

StatusFileSize
new1.83 KB
PASSED: [[SimpleTest]]: [MySQL] 409 pass(es).
[ View ]

Updated patch against head.

zeta ζ’s picture

Status:Needs review» Needs work

The last line of code needs to be inside the test as it uses $bundle, which is set by list() inside the test.

<?php
  
if (isset($entity)) {
       ...
     list(, ,
$bundle) = entity_extract_ids($entity_type, $entity);
   }
   return
entity_ui_get_action_title($op, $entity_type, $bundle);
?>

We then need to decide what to return if the test fails.

sachin_hj’s picture

Issue summary:View changes
StatusFileSize
new773 bytes

Hey your patch works fine but there is a mismatch in the line number so i have updated it.

[For Your Reference Error Message what i got was
Notice: Undefined variable: bundle in entity_ui_get_page_title() (line 749 of /Project Name/sites/all/modules/contrib/entity/includes/entity.ui.inc).]

pachabhaiya’s picture

Status:Needs work» Needs review
StatusFileSize
new1.47 KB
PASSED: [[SimpleTest]]: [MySQL] 630 pass(es).
[ View ]

Patch #3 looks good to me.
It applied successfully in my entity-7.x-1.3 version and solved the issue as mentioned in the issue description.

Patch #3 does not apply cleanly in the latest 7.x-1.x-dev version.
I'm re-rolling this patch and submitting it here so that it applies cleanly in the latest 7.x-1.x-dev version.

@zeta ζ
The line of code that you have mentioned does not necessarily have to be inside the 'if (isset($entity))' condition.
The value of $bundle will be NULL is the condition does not satisfy.

Changing status to Needs review.