Hi,
I wanted to add some custom text actions via PHP. Which means, read values from a text field of a node to which the image is attached. I'm trying to access the field data via this code proposed in the readme.txt of the module:
<?php
$entity_type = 'node';
$field_name = 'my_field';
$entity = $image_context['entity'];
$field = field_get_items($entity_type, $entity, $field_name);
?>
This code is working for me in so far as I'm able to access the text field and the correct text is applied to the image.
BUT: On the edit page of the image style I'm getting the error
EntityMalformedException: Fehlende Paketeigenschaft auf einem Element des Types node. in entity_extract_ids() (Zeile 7663 von [...]/includes/common.inc).
(Which is: EntityMalformedException: Missing bundle property on entity of type node. in entity_extract_ids())
Using Drupal 7.22
The edit page isn't displayed at all because of this error - which means I can't edit my actions anymore or add even more actions - but need to add some more actions as I would like to apply the content of 2 or more text fields of the node to the image.
The error only appears using $field = field_get_items($entity_type, $entity, $field_name);, even replacing $entity_type with 'node'.
Calling the node, everything works fine ... maybe there's an issue with this piece of code shile not being on a node or an entity in general?
I've seen that other people experience this error as well using other modules but their solutions, if there are any, don't help me with the issue I have with this module.
Thanks for your help!
Sonja
Comments
Comment #1
fietserwinThanks for reporting. I updated the code sample in the documentation to test for the existence of an entity. I also changed the default PHP code to the code sample, to give users a head start.