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

Shmee’s picture

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.

victory17’s picture

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

stoltoguzzi’s picture

same here!

agerson’s picture

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.

stoltoguzzi’s picture

Thanks, this way the error has gone

Shmee’s picture

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

Thanks for your help.

dwalker51’s picture

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.

dwalker51’s picture

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)

victory17’s picture

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

gkazhus’s picture

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?

Starminder’s picture

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

RedTop’s picture

subscribing

avizzino’s picture

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

boonejeeper’s picture

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!

Starminder’s picture

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!

David_Rothstein’s picture

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.

theapi’s picture

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

theapi’s picture

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;
    }
  }
}
David_Rothstein’s picture

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 :)

dartdev’s picture

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.

kifuzzy’s picture

sign

parsingphase’s picture

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

TripX’s picture

subscribe - same here.

flightrisk’s picture

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

Cogito’s picture

Status: Active » Needs review
StatusFileSize
new465 bytes

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.

Cogito’s picture

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

Starminder’s picture

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

Starminder’s picture

Priority: Normal » Critical

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

David_Rothstein’s picture

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.

Starminder’s picture

Priority: Normal » Major
StatusFileSize
new53.97 KB

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.

David_Rothstein’s picture

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.

Starminder’s picture

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!

Starminder’s picture

Status: Needs review » Needs work

Yep, it's filling up the log.

TripX’s picture

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

David_Rothstein’s picture

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 :)

esculcar’s picture

+suscribing

rob c’s picture

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.

chriz001’s picture

subscribe

brodiebrodie’s picture

subscribe

mhamed’s picture

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

dadou351’s picture

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

Hello, i'm the same problem !

Thanks

Joenet-dupe’s picture

same problem.
subscribe.

mcfilms’s picture

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.

Dinesh Kumar Sarangapani’s picture

StatusFileSize
new258.7 KB
new229.02 KB
new275.64 KB

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

Dinesh Kumar Sarangapani’s picture

Status: Reviewed & tested by the community » Active
jgraham’s picture

Version: 7.x-1.0-beta6 » 7.x-1.x-dev
Priority: Major » Normal
Status: Active » Needs review
StatusFileSize
new511 bytes

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.

aftab0000’s picture

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

jgraham’s picture

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.

aftab0000’s picture

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

lsolesen’s picture

Status: Needs work » Needs review
Issue tags: +Beta8-blockers
lsolesen’s picture

Issue tags: -Beta8-blockers +Beta10-blockers

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

Taxoman’s picture

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.

ddarras2012’s picture

Issue summary: View changes
Issue tags: -

Received similar error with Views Field View module in the parent module (child module that had Pager enabled). Disabling pager in child view removed error.

hanksterr7’s picture

Not sure if this is related, but I get these errors when a pager has no contents.

Might only be the case when there is more than one pager on a page. I have a pager in a block in left sidebar.

Example: use the Search tool and search on a search string that returns no results.

I get this error from the pager for the main page contents (i.e. the search results)

To fix, add this check to /includes/pager.inc line 328 in theme_pager() (for drupal v 7.50):

if (!isset($pager_total[$element])) {
	return;
}

The errors will go away, with no ill effects

ivnish’s picture

Status: Needs review » Closed (outdated)