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".

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

droath’s picture

Status: Active » Needs review
FileSize
1.46 KB
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

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.

   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

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
FileSize
1.47 KB

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.

Chris Matthews’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

The 3 year old re-rolled patch in #6 does not apply to the latest entity 7.x-1.x-dev and (if still relevant) needs a reroll, again ;(

Checking patch entity.module...
error: while searching for:
 */
function entity_ui_get_page_title($op, $entity_type, $entity = NULL) {
  module_load_include('inc', 'entity', 'includes/entity.ui');
  $label = entity_label($entity_type, $entity);
  switch ($op) {
    case 'view':
      return $label;
    case 'edit':
      return t('Edit @label', array('@label' => $label));
    case 'clone':
      return t('Clone @label', array('@label' => $label));
    case 'revert':
      return t('Revert @label', array('@label' => $label));
    case 'delete':
      return t('Delete @label', array('@label' => $label));
    case 'export':
      return t('Export @label', array('@label' => $label));
  }
  if (isset($entity)) {
    list(, , $bundle) = entity_extract_ids($entity_type, $entity);
  }
  else {

error: patch failed: entity.module:185
error: entity.module: patch does not apply