2

I have created a custom fieldable entity. Now I want to inject the field data into the entity and render the complete entity with the fields.

The following code is working for text fields and taxonmy reference fields, but when I want to inject image field data, the image have no uri.

My field data, I want to inject:

[type] => paragraph
    [configuration] => Array
        (
            [field_body] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [value] => Lalelu
                                )

                        )

                )

            [field_image] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [fid] => 17
                                    [display] => 1
                                    [width] => 60
                                    [height] => 60
                                    [description] => 
                                    [upload_button] => Upload
                                    [remove_button] => Remove
                                    [upload] => 
                                    [alt] => 
                                    [title] => 
                                )

                        )

                )

            [field_tags] => Array
                (
                    [und] => Array
                        (
                            [0] => Array
                                (
                                    [tid] => 1
                                    [vid] => 1
                                    [name] => Term 1
                                    ...

                                )

                        )

                )

        )

This are the lines, that work for the field_body (textfield) and field_tags (taxonomy). The form is getting rendered, even the image field.

  // Append field data from storage.
  form_set_value($element['chunk']['edit'], $vars['edit'], $form_state);

  // Append fields from chunk entity to the form.
  field_attach_submit('chunk', $chunk, $element['chunk']['edit'], $form_state);

  // render entity form
  field_attach_form('chunk', $chunk, $element['chunk']['edit'], $form_state);

But when I try to render the entity, all fields get rendered, but the image field.

  // Append field data from storage.
  form_set_value($element['chunk']['preview'], $vars['edit'], $form_state);

  // Append fields from chunk entity to the form.
  field_attach_submit('chunk', $chunk, $element['chunk']['preview'], $form_state);

  // render chunk entity
  $element['chunk']['preview'] += entity_view('chunk', array($chunk), 'preview');

I get the error:

  Notice: Undefined index: uri in theme_image_formatter() (line 605 of /xxx/modules/image/image.field.inc).

I think I'm missing any kind of image view preprocessing, where the uri from the managed field is loaded form the database.

Do you have any idea, what's my problem? Or do you have any other solution to get the entity rendered?

Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.