There's no way in hook_ctools_content_subtype_alter() to know a reusable FPP entity's bundle without loading the entity, which of course is problematic once you start having lots of reusable entities.

All we need to do is include the bundle property. Patch coming shortly.

Comments

joelstein created an issue. See original summary.

joelstein’s picture

joelstein’s picture

Status: Active » Needs review

Status: Needs review » Needs work
joelstein’s picture

Status: Needs work » Needs review
StatusFileSize
new439 bytes

Ugh, working too fast and missed a semicolon.

Status: Needs review » Needs work
joelstein’s picture

Actually, the patch above breaks stuff, probably because the bundle property is used for other purposes in FPP.

However, it just occurred to me that the only reason that the bundle property is available is because the FPP entity was loaded, which means it's already available in the request cache. If anyone stumbles on this, you can simply load the entity with fieldable_panels_panes_load_from_subtype_force($subtype['entity_id']);.

Slightly related, it would be worth considering if we can load the reusable entities in a lighter way, in case hundreds (or more) of them need to be loaded...

chris burge’s picture

Status: Needs work » Needs review
StatusFileSize
new443 bytes

I'm also needing the FPP entity bundles while using hook_ctools_content_subtype_alter(). Returning $info['bundle'] does break things (i.e. none of my FPP entities print in panels). If the 'bundle' namespace is already being used, then let's use something else like 'fpp_bundle'.

chris burge’s picture

Status: Needs review » Needs work
StatusFileSize
new1 KB

I think the underlying issue is in fieldable_panels_panes_load_from_subtype():

  // This means we're probably in the process of creating a new one.
  if (isset($subtype_info['bundle'])) {
    return fieldable_panels_panes_create(array('bundle' => $subtype_info['bundle']));
  }

When we set $info['bundle'], fieldable_panels_panes_load_from_subtype() thinks this is a new entity. Instead, let's check if $subtype_info['entity_id'] is set. If it's not set, then we're dealing with a new entity.

  if (!isset($subtype_info['entity_id'])) {
    return fieldable_panels_panes_create(array('bundle' => $subtype_info['bundle']));
  }

With this change, we'll never get to "Finally, try this" because either $subtype_info['entity_id'] is set or it isn't set. One of the IFs will return true before getting to "Finally, try this". I'm not sure about the consequences of this. When would neither $subtype_info['bundle'] nor $subtype_info['entity_id'] be set?

  // This means we're probably in the process of creating a new one.
  if (!isset($subtype_info['entity_id'])) {
    return fieldable_panels_panes_create(array('bundle' => $subtype_info['bundle']));
  }

  // And try it this way.
  if (isset($subtype_info['entity_id'])) {
    return fieldable_panels_panes_load_from_subtype_force($subtype_info['entity_id']);
  }

  // Finally, try this:
  return fieldable_panels_panes_load_from_subtype_force($subtype_name);
chris burge’s picture

Status: Needs work » Needs review

damienmckenna’s picture

Committed. Thank you both!

damienmckenna’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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