metatag_entity_info_path() crashes with entities built with ECK.

There's already code to handle something similar through the MetatagEntityMock class.

I extended this class for ECK not to crash.

CommentFileSizeAuthor
#1 2514812-eck-crash.patch867 bytesdavid_garcia
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

david_garcia’s picture

Status: Active » Needs review
FileSize
867 bytes
david_garcia’s picture

Just as a side comment, the approach used in metatag_views_post_render() is quite dangerous.

You could achieve something similar by exploiting the router item definition:

This is a custom override of menu_get_object that searches for the first ocurrence of an entity type in the current router, but could serve as a base idea for an alternative implementation.

public static function menu_get_object($type = 'node') {
    $router_item = menu_get_item(NULL);
    if (!is_array($router_item['load_functions'])) {
      return FALSE;
    }
    foreach ($router_item['load_functions'] as $position => $function) {
      if (!empty($router_item['map'][$position])) {
        $instance = &$router_item['map'][$position];
        // If the entity is provided by EntityAPI it will be wrapped and contain the entityType method.
        $check = is_callable(array($instance,'entityType')) && $instance->entityType() == $type;
        // Some core entities are returned as simple "stdClass" instances, a way to verify the
        // type is to wrap it and try to get the identifier.
        if (!$check && is_a($instance, \stdClass::class)) {
          // Compatiblity with core entities.
          if ($function == "{$type}_load") {
            $check = TRUE;
          }
        }
        if ($check) {
          return $router_item['map'][$position];
        }
      }
    }
    return FALSE;
  }
}
DamienMcKenna’s picture

Out of interest, does the change in #2514878: Ignore admin pages for Views, Panels custom hooks also fix it?

DamienMcKenna’s picture

Note - #2514878 won't fix anything, but it'll stop the faulty logic from executing on admin pages, where meta tags aren't wanted.

DamienMcKenna’s picture

I've committed this fix. Thanks, David.

DamienMcKenna’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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