Download & Extend

Undefined offset: 1 in theme_pager() when Media Gallery is used alongside Views

Project:Media Gallery
Version:7.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Issue tags:Beta10-blockers

Issue Summary

Hi everyone

I like the idea of the Media and Media Gallery module but am having a few issues.

I have a fresh install on D7 and I cant add images to the gallery and get this error Undefined offset: 1 in theme_pager(). And

The images are being added to the media module but dont display in the Media Gallery module

Does anyone know what Im doing wrong or what I need to do to get this working?

thanks

Marcel

Comments

#1

I get this too. It seems to happen when there are not any pictures in the gallery. If you put pictures in then it seems to go away, but comes back every now and then.

#2

Version:7.x-1.0-beta3» 7.x-1.0-beta4

Notice: Undefined offset: 1 in theme_pager() (line 332 of /var/www/vhosts/test/includes/pager.inc).
Notice: Undefined offset: 1 in theme_pager_first() (line 460 of /var/www/vhosts/test/includes/pager.inc).
Notice: Undefined offset: 1 in theme_pager_previous() (line 490 of /var/www/vhosts/test/includes/pager.inc).
Notice: Undefined offset: 1 in theme_pager_next() (line 529 of /var/www/vhosts/test/includes/pager.inc).
Notice: Undefined offset: 1 in theme_pager_last() (line 565 of /var/www/vhosts/test/includes/pager.inc).

Getting this error after I enabled the module, any help is appreciated.

Thanks

#3

same here!

#4

Version:7.x-1.0-beta4» 7.x-1.x-dev
Component:User interface» Code

same problem. It has something to do with line 19 in media_gallery.module

define('MEDIA_GALLERY_PAGER_ELEMENT', 1);

Changing it to 0 removes the errors for galleries with only one page.

#5

Thanks, this way the error has gone

#6

Changing line 19 works for me as well. Does this have any consequences I should be looking out for?

Thanks for your help.

#7

I can't add images to a media gallery either, changing this setting allow the pager to appear, but the images still don't show up in the gallery.

#8

I get this message in the logs

Warning: Invalid argument supplied for foreach() in media_gallery_add_images() (line 291 of /var/www/html/noao/sites/all/modules/media_gallery/media_gallery.pages.inc).

Along with the pager message (which did disappear when doing #4)

#9

Made change in #4 got rid of the error message, but now pager shows twice on gallery pages with multiple pages.

#10

I have the same issue but I get advice of (#4) and now error is gone and also is gone pager then I open albume where is multiple images. How can I get pager here?

#11

Getting this in beta5 :/, it prevents saving d&d uploads overlay, the button to save is gone.

#12

subscribing

#13

Agree with #10: #4 does remove the notice but the pager is gone as well.

Media 7.x-1.0-beta4
Media_gallery 7.x-1.0-beta5

#14

After reading this and a few other posts about this issue. I did not edit my code, but instead I disabled the two custom views I had just created. They were set to show on every page, one with most recent blog posts, and one with most recent announcements. I believe it was the links associated with the blog posts that was making the pager stuff in media_gallery act up. I set the two custom views to only show on two of my pages without media galleries, and I no longer get the error.

To clarify, page 1 has a media gallery, page 2 has a media gallery, and page 3 does not. I was getting the error each time I would view either page 1 or page 2, then move on to any another page in my website. None of my galleries have more than one page, and the page that is auto created that has links to all of my galleries would not cause the error, it was only when inside the actual galleries.

Hope this info helps in debugging.

Cheers!

#15

I disabled my custom views (which preferably would show on the front page at least, or really every page) but to no avail. Really wish this could get fixed!

#16

Title:Undefined offset: 1 in theme_pager()» Undefined offset: 1 in theme_pager() (prevents images from being added to the gallery?)
Status:active» postponed (maintainer needs more info)

#14 is interesting. A conflict with Views does seem like a possible culprit, since both these modules play around with the pager a bit.

1. Can anyone reproduce this bug with the Views module totally disabled?

2. Can someone explain if this is one bug or two? - i.e., is everyone experiencing the PHP notice also experiencing an inability to upload images, and if you get rid of the notice temporarily (e.g. via the method in #4), do both problems go away at the same time? It sounds from some of the comments above like these may be separate problems, in which case there should be separate issues filed for them, but I'm not sure.

#17

I'm experiencing the notices but uploading without problem; views enabled, plupload enabled and used.

#18

Since setting MEDIA_GALLERY_PAGER_ELEMENT to 0 stops the pager showing I've left it set to 1 and implemented the following hack in mymodule to simple add 1 to the pager array if it's not already there. Uploading is fine both with and without plupload, the notices are gone and the pager works.

function mymodule_preprocess_node(&$variables) {
  if ($variables['node']->type == 'media_gallery') {
    global $pager_page_array;
    if (!isset($pager_page_array[1])) {
      $pager_page_array[1] = (float) -1;
    }
  }
}

#19

Title:Undefined offset: 1 in theme_pager() (prevents images from being added to the gallery?)» Undefined offset: 1 in theme_pager() when Media Gallery is used alongside Views
Status:postponed (maintainer needs more info)» active

OK, thanks, sounds like the image problems were probably another issue.

I think based on recent feedback we can be pretty sure this is related to Views; I guess the thing to investigate in order to fix this is if it's a Media Gallery bug, a Views bug, or maybe just an unfortunate conflict that isn't either module's fault :)

#20

After implementing #18 pager seems to start not from the first (page=0,0) page, but from some (page=0,-1). Clicking "Next" button leads to the (page=0,0) so you have to click it twice to continue. Really looking forward for fix.

#21

sign

#22

At first glance, "(string) 0" in place of "(float) -1" in PeterC's code fragment above seems to work.

#23

subscribe - same here.

#24

This happens now for me every time I click on "remove" or "edit gallery" or "add media"

#25

Status:active» needs review

Having read a little into the code, it seems that media gallery is using its own paging variable, and more to the point is indexing it from 1. The normal pager uses a 0 based array, and so when the media gallery paging variable is being saved it is off by one. The attached diff simply subtracts one from the value of the custom paging variable when it is stored into the normal paging variable.

diff --git a/media_gallery.module b/media_gallery.module
index 6d1641e..84955f9 100644
--- a/media_gallery.module
+++ b/media_gallery.module
@@ -358,7 +358,7 @@ function media_gallery_view($node, $view_mode) {
if ($full) {
$node->content['media_gallery_pager'] = array(
'#theme' => 'pager',
- '#element' => MEDIA_GALLERY_PAGER_ELEMENT,
+ '#element' => MEDIA_GALLERY_PAGER_ELEMENT - 1,
'#weight' => 2000,
);
}

This needs further testing, however it does seem to solve the initial problems, with minimal changes to the rest of the media gallery code.

AttachmentSize
saveAsZeroBasedIndex.diff 465 bytes

#26

adding a git aware patch, in case someone would rather that.

AttachmentSize
0001-Use-0-based-array-index-when-saving-element.patch 696 bytes

#27

any chance of getting this fixed in a build, ever?

#28

Priority:normal» critical

changing to critical as module is unusable until this is addressed. Is this module actively maintained?

#29

Priority:critical» normal

Why does a PHP notice make the module unusable? It sounds like you may have this confused with some other problem.

The current patch by @Cogito (thanks by the way!) was posted with a note that it "needs further testing", so that's what it needs - in addition to code review - before it can be committed.

I looked quickly at the patch and I'm not totally sure I understand it, because the current media gallery code is using "1" throughout, yet this patch changes it in one place only; doesn't it need to be consistent throughout? Drupal's pager system definitely allows you to use indexes other than "0" for the pager, and it is supposed to work fine (and by all accounts does, except in certain cases when used with Views). So I think we might not fully understand the bug yet; there must be some conflict with how Views is using the pager system.

#30

Priority:normal» major

I am quite familiar with the problem, in that it prevents me from using or even testing the module further. I'd opened up a support request awhile back for the same issue and attached a screen shot. Since the error messages appear at the top of the window where you should drag files to upload, this skews everything enough to where it is impossible to save.

So, if the application cannot be used, isn't that, in effect, critical?

As important as this functionality is to the entire community, I for one am happy to do whatever I can do to help it along. Having said that, I cannot even test it.

AttachmentSize
media_gallery_fubar.png 53.97 KB

#31

Ah, I didn't realize it blocks use of the save button. However, that's an easy problem to fix on your site. Go to admin/config/development/logging and configure the site not to display errors to the screen (they'll still be recorded to the logs). Then the messages won't get in the way of uploading images.

That setting is what you always should use on production websites anyway, since you don't want end users to see these kinds of messages, ever.

#32

oh man, I knew that and completely forgot. That gets me around this one for now, although I'm sure it's going to fill up the logs. Thanks!

#33

Status:needs review» needs work

Yep, it's filling up the log.

#34

Actually, also my anonymous user can see the message. Major is the real status for this issue ;)

#35

Tripx: As described above (in #31), that is a site configuration issue. Go to admin/config/development/logging and fix the setting.

At that point end users will no longer see the messages, though they will still fill up the logs :)

#36

+suscribing

#37

Or, you could disable the views on the media page that use some media related references (context) or fields.

I can not reproduce this error on a media gallery page without enabling the views i have. (rendering a list of nodes that are displayed on media pages) As soon as i enable a view that relates to media (gallery), beng, same errors as #2, other (non media related) views give me no errors, but this could use more testing.

#38

subscribe

#39

subscribe

#40

Ok the same :

Undefined offset: 1 in theme_pager_next()

within the file media_gallery.module

changing the degit to 0 has done out with the error
thanks

#41

Version:7.x-1.x-dev» 7.x-1.0-beta6

Hello, i'm the same problem !

Thanks

#42

same problem.
subscribe.

#43

Status:needs work» reviewed & tested by the community

I can confirm that the fix suggested by Cogito in #25 dies indeed work. I no longer get the errors and the site seems to be functioning normally.

My only outstanding issue with Media Gallery in D7 is for another thread. Any image I click on displays a white box and not the image. See #1293944: Lightbox is appearing when enabled, but all photos show "file not found" when the photo is clicked on and the lightbox displays . I'm just not sure if this is a colorbox error, media gallery error, or pilot error.

#44

Hi,

After adding the patch mentioned in #25, I did't get any errors but i get dummy pagers as shown in the attached screen shot.

Thanks,

Dinesh

AttachmentSize
dummypage-gallery1.png 275.64 KB
dummy-pager-gallery.png 229.02 KB
dummy-pager-gallery2.png 258.7 KB

#45

Status:reviewed & tested by the community» active

#46

Version:7.x-1.0-beta6» 7.x-1.x-dev
Priority:major» normal
Status:active» needs review

Attached is a patch which resolves the issue for us.

In this case we omit trying to add the pager element if there are fewer items in the gallery than the per page setting.

AttachmentSize
media_gallery-1079870-45-fix-warnings-when-no-gallery-items.patch 511 bytes

#47

Version:7.x-1.x-dev» 7.x-1.0-beta7

Dear Jeff,
I have applied the patch and now paging is showing in a gallery along with the custom view. But same error came up when I click to any other page. i.g. Undefined offset: 1 in theme_pager() (line 331 of C:\wamp\www\bancaras.com\includes\pager.inc). And it goes away when I click another page. It happen only when I switch page for first time.

One thing I observed ---
when I goes from http://localhost:8888/MySite/node/8 to http://localhost:8888/MySite/node/8?page=0%2C1 it gives that error
and when I goes from http://localhost:8888/MySite/node/8?page=0%2C1 to http://localhost:8888/MySite/node/8?page=0%2C2 or it doesn't gives error.

Do you have any suggestion?

Thanks,
Aftab

#48

Status:needs review» needs work

Setting to needs work relative to aftab0000's comment 47.

Sounds like the patch in 46 just minimizes the frequency rather than solving the issue.

I'll take another, more in depth, look when I get a chance.

#49

I have investigate this issue and found the problem and its resolution.
First of all I like to summarize the issue.
Issue: Some of the media gallery user having the following warning.
Undefined offset: 1 in theme_pager() (line 332 of /var/www/vhosts/test/includes/pager.inc).
All media gallery user are not getting this warning because only those who have paging in the medial gallery and also have paging in other view will get this warning.
Reason: Media gallery is using Drupal paging system and other view is also using Drupal paging system. That’s why media gallery is setting
MEDIA_GALLERY_PAGER_ELEMENT = 1 to avoid conflict. But the problem is paging system have a global variable $pager_total_items which is overriding by view
(File-views_plugin_pager_full.inc >> line-221>> $pager_page_array = isset($_GET['page']) ? explode(',', $_GET['page']) : array(0);)
If someone is interested to understand more, can read the following article which helps me to understand it.
http://www.angrydonuts.com/modernizing-the-drupal-pager-system
I think the core paging system can be consider to change to avoid this kind of issue in other module.
Resolution 1: If you don’t need it a pager in your custom view then turn off you paging in your custom view. That will resolve the issue. But if you need paging for both media gallery and custom view then try the next resolution.
Resolution 2: Apply the attach patch. In this patch I have rendering the paging before it overriding by view.

I would like to mention that I am very new Drupal so if my understanding is wrong please correct me.
Thanks,
Aftab

AttachmentSize
media_gallery-1079870-45-fix-warnings-when-two-pager-in-a-page.patch 765 bytes

#50

Status:needs work» needs review

#51

This is only experienced by some users of Media Gallery, thus I am moving it to beta10.

#52

Version:7.x-1.0-beta7» 7.x-1.x-dev

Would be great with a confirmation or two whether this problem also occurs on the -dev release (since July 7th), and even with some confirmations whether this does NOT occur for others on the current -dev.
If it occurs for many users, this is "major" and not "normal", IMHO.
Moving tentatively to the -dev queue.