Hello, I had get this error working with

Shadowbox 7.x-4.0-beta4+6-dev ( in 4 modules )

Display suite 7.x-1.5
Fieldgroup 7.x-2.x-dev

File entity 7.x-1.0
Media 7.x-1.0
Media Browser Plus 7.x-1.0-beta3
Media: YouTube 7.x-1.0-beta3

I had searced but none reference to this issue, my languaje is spanish sorry for my bad use of english.

When I add a image or video, then save the form, and get this in the window:

Notice: Undefined property: stdClass::$nid en file_shadowbox_field_formatter_view() (línea 211 de /var/www/vhosts/misite.es/httpdocs/sites/all/modules/shadowbox/file_shadowbox/file_shadowbox.module).

But I can see all render ok in the window, and ig get running open as well.
Thanks.
:) Magnific work.

Comments

5n00py’s picture

Hi! I have same issue with this PHP notice:

Notice: Undefined property: stdClass::$nid в функции shadowbox_field_formatter_view() (строка 444 в файле /home/snoopy/www/domain/dev7.bijugrad.com.ua/htdocs/sites/all/modules/contrib/shadowbox/shadowbox.module).

I make some code review and found this mistake:
Shadowbox have setting for node related gallery, so gallery have id like this: nid-10.
Good, BUT!!!
I have image field attached to commerce product entity. This entity referenced by product-display node type.

$gallery_id = "nid-{$entity->nid}";

In my case there is not nid property in entity.

manfer’s picture

The only thing by now I can think to avoid that notice is to just check on the code that nid exists and if not -as on those entities you refer to- then I don't group the entities into a gallery. To solve the problem on your fields is as easy as not using the 'gallery node' nor the 'gallery field node' on the shadowbox formatter configuration of your field if your entities are not nodes.

If you need for some reason to add several images to an entity which is not a node and you need to group the images as a gallery just use only one field and on that field allow multiple values (multiple images) and then in the shadowbox formatter use 'gallery field page' which groups all the images on a field as a gallery.

5n00py’s picture

#2
You're right!

But we can group images to galleries using id's like:

  • {entity_type}-{id}
  • {entity_bundle}-{id}
  • {entity_type}-{bundle}-{id}

If this is useful, I can create a patch to do this thing.

manfer’s picture

The problem is that not all entity types has ids either if I'm not wrong. At least for what I read there is even a module trying to enhance the core entity API and one that tries to provide a unique entity identifier. If there were a unique identifier for all entities it would be better but sadly seems there isn't.

Anyway what I can do is use id when there is no nid, and if there is no nid, nor id, then don't do the grouping (gallery=""). Unless or until someone finds better solution.

I would need and identifier on entity, not entity_type. Could you find out if your products entities have any kind of identifier? Should be $entity->id and not $entity_type->id.

Or what about the created timestamp or the revision timestamp. Does all entities have one? This should be unique so if all entities have one would be great candidate.

5n00py’s picture

entity_type or bundle name prefix can help to make unique ids.
If we have node with id 3 and taxonomy term also with id 3 we can have gallery ids like:
node-3 and term-3.
This is unique.

Also you can look to field table in database , it have next columns:
entity_type
bundle
entity_id
field_images_fid
...

manfer’s picture

Status: Active » Needs review
StatusFileSize
new1.3 KB

I think I found which is the correct way to do this. Here is the provisional patch and maybe before commiting I change the label from "gallery node" to "gallery entity"

5n00py’s picture

StatusFileSize
new557 bytes

This patch fix notices and handle non-node galleries like term or any other entity.

I already test it in different settings.

manfer’s picture

Lol exactly same time patch. Well at least I see is exactly the same way to do it so probably I can consider it has been reviewed. :)

In my patch I actually do the necessary changes to file_shadowbox too.

So now I think I'm going to change the label and push the patch.

Regards.

manfer’s picture

So here is the new patch that now includes the change of labels from "gallery node" to "gallery entity" and from "gallery field node" to "gallery field entity"

As gallery field node had same issue this new patch includes the changes in that case too.

Done both in image shadowbox and in file shadowbox modules.

I think now it is prepared to be pushed.

manfer’s picture

Still some labels where not updated. New patch to solve that.

manfer’s picture

Status: Needs review » Fixed
5n00py’s picture

Status: Fixed » Needs review
StatusFileSize
new1.67 KB

More friendly ids.
Applicable to the latest changes.
P.S.: Its good idea to get some time for review patches by other people :)

manfer’s picture

Status: Needs review » Fixed

Pushed too. Thanks.

5n00py’s picture

Thanks!

Status: Fixed » Closed (fixed)

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

  • Commit c4e1ff6 on 7.x-4.x, 8.x-1.x:
    Issue #1557702 by 5n00py, manfer: unique entity id in gallery node