I've got Panelizer working for a custom entity by copying and adapting the provided plugin for node entities. But, Panelizer fails with the following error...

Notice: Undefined index: #my_entity in panelizer_entity_view_alter() (line 206 of [...]/panelizer/panelizer.module).
EntityMalformedException: Missing bundle property on entity of type my_entity. in entity_extract_ids() (line 7563 of [...]/includes/common.inc).

It looks to me like the entity is in $build['#entity'] not in $build['#entity_type']. Patch in comment...

Comments

darrenmothersele’s picture

StatusFileSize
new503 bytes

patch attached.

merlinofchaos’s picture

There is simply no consistent way that the entity can be found in hook_entity_view. In core, it's usually '#' . $entity_type, except for $user and except for $term.

Now, your custom entity is doing it yet another different way. The answer is NOT to hardcode your custom way into the system.

From looking at this, I think what we really should be doing is creating a method on the handler so that each individual plugin can tell us where the entity will be located. So something like this:

$entity = $handler->get_entity_view_entity($build)

Then the default can use '#' . $entity_type as it does now, and then all the exceptions that are currently in that code can move to their entity. Your entity type can define that to match the location that you're using.

It's worth noting that if Panelizer can't find it using '#' . $entity_type, other modules that do things with hook_entity_view won't be able to either. The initial code that Panelizer got for this is from display suite, for example, but it's not the only place I've seen code like this.

merlinofchaos’s picture

Status: Active » Needs review
StatusFileSize
new3 KB

Here's a quick, completely untested patch to test out this concept.

merlinofchaos’s picture

StatusFileSize
new3.09 KB

This one will protect against notices in case the entity is somehow unfindable.

darrenmothersele’s picture

This custom entity was created by simple extension from the Entity API, so I guess there would be plenty of other custom entities around where the entity is found in ['#entity']. Having a method for this on the handler does seem like a better solution, thanks.

Patch in #4 is working for me.

merlinofchaos’s picture

Status: Needs review » Fixed

Committed and pushed!

betz’s picture

Status: Fixed » Active

I have running latest dev, and i only see node, taxonomy and user as entities.
I have custom entities created with the entity construction kit.

merlinofchaos’s picture

Status: Active » Fixed

This patch doesn't automatically panelize any entity you might have; entities still need some code to be panelized. Entity Construction Kit would need to provide a panel plugin in order to have its custom entities panelized.

Reverting to proper status.

Status: Fixed » Closed (fixed)

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