I'm working on a patch to provide Views support for the Image assist browser. This is a report on the progress so far.

Completed stuff:

- Created a Views row style plugin which shows nodes as thumbnails, IA style.
- The thumbnail browser in IA is replaced by a view which uses the built-in grid type. (This view can be tweaked by administrators.) This is implemented with the same page callback as before, only now it embeds a view instead of building its own queries etc.
- The view respects the user's choice between My images, All images and taxonomy terms.

Remaining stuff:

- Provide a default view for the image browser (currently I'm using a custom view for testing).
- Add support for choosing custom views that should be used in addition to the default one. This will happen on the settings page.
- Include unpublished images in "My images". (This is the current behaviour in IA.)
- Replace the COUNT queries (used in menu texts like My images (5)) with Views magic. (Not sure how to do this with Views 2.)
- Update the css and remove any styling that has been made redundant.

I'll be back with a patch.

Comments

zoo33’s picture

Another thing: I suggest we remove the setting Maximum number of thumbnails per page since that can be changed in Views now. And I think few people change this anyway.

zoo33’s picture

Status: Active » Needs review
StatusFileSize
new17.75 KB

OK, here we go...

The attached patch does most everything outlined above, except providing the ability to add your own views to the thumbnail browser. I thought it would be best to finish the groundwork first and wait for comments – the rest will be trivial.

A few other things remain:

– Showing unpublished images in My images. This is a little tricky as Views doesn't provide a Node: published argument, only a filter. Can we lose this feature? Do people use it? (If not, I think the solution would be to define two separate displays for the default view.)
– Haven't touched any CSS yet.

A note for people who read the patch: I have changed the path scheme from:

img_assist/thumbs/xxxx

to:

img_assist/thumbs/{view_name}/{arg1}/{argN}

Happy reviewing!

sun’s picture

StatusFileSize
new17.82 KB

I gave this a try as well as a thorough review - works seamlessly, even with pre-existing images from 6.x-1.x, which is even better! :)

Noteworthy changes in attached patch:

  • Added $view->hide_admin_links = TRUE; to prevent admin links from showing up in thumbnail browser. However, this will only work for IA's default view, so we probably need a tweak for other views.
  • Changed default number of rows to 9 (3 x 3) images.
  • Removed unnecessary changes and cleaned-up some comments.

To display also unpublished images, we would just have to remove the whole 'status' array key from the overridden views filters ( - tested). However, I would suggest to rather leave it as is, since I would not expect images to show up (anywhere) if they are unpublished.

Some other thoughts:

  1. img_assist_views_default_views() is pretty large and I wondered, if we really need to define everything what's defined in there.
  2. The default view uses 'node' as base table for images - however, when overriding the default view, users would have much more options if the base table was 'files'.

Please note that I've committed some code/documentation clean-ups to all 2.x branches (shouldn't affect this patch).

sun’s picture

Note for later (and likely another issue):
- Almost all invocations of module_exists() (regarding Image and Views) can be removed - if someone manages to disable one of both or both modules while IA is enabled, that'll be not our fault.
- Current code cries for img_assist.admin.inc and img_assist.popup.inc.

sun’s picture

StatusFileSize
new21.09 KB

- Added views selection in admin settings.
- Added module update to remove img_assist_preview_count variable.

Last patch for tonight.

zoo33’s picture

StatusFileSize
new20.93 KB

Looks good, works great! Made a couple of small changes:
– Views selection showed an empty row if the view title wasn't set. Added a fallback to $view->name.
– Why 3 x 3 images? 6 images (3 x 2) has always been the default, right? Changed back for now.

Thoughts:
– Should we use t() in img_assist.views_default.inc?
– img_assist.views_default.inc is indeed very large, it's a full view export. I'm not sure what parts are required and what can be removed so I would have to remove stuff piece by piece and see if it still works. I noticed that for instance comment.views_default.inc contains a full view export too. Maybe we should leave it as it is.

#3: I think using files as base table would be a little complicated with IA's current connection to Image module, since each image is represented by an arbitrary number of files. Keeping track of different sizes would be tricky too, no?

#4: Agreed. Let's restructure to .inc files after this is done.

zoo33’s picture

StatusFileSize
new981 bytes

Here is a separate patch for img_assist.css – don't want to clutter the main patch with even more changes.

First, let me point out that the IA window looks completely different depending on if you use it with TinyMCE or not. With TinyMCE, we get only TinyMCE's css file and img_assist.css. Without TinyMCE, IA includes all the regular Drupal CSS files including the theme's files – and then img_assist.css. (This is the intended behavior, take a look at theme_img_assist_page().)

In this patch:

– Removed unnecessary declarations.
– Hided .views-admin-links. (This is first and foremost needed with TinyMCE.)
– Added overrides for table styling. Garland for instance adds borders and margins to it's tables which doesn't work well here.
– Centered tables and node forms with margin: auto since we removed <div align="center"> from the markup.

sun’s picture

Let's commit the views patch now. Is there anything else to consider for img_assist_update_6200() ? For example, when someone updates to 2.x, how can we ensure that Views is already installed + enabled? Will Drupal handle this?

sun’s picture

StatusFileSize
new21.62 KB

Attached patch disables IA, if Views module is not enabled during update 6200. Initially I wanted to automatically enable Views if it was available but not enabled, but I think that we are "not allowed" to stuff like that.

Since this was the only change, I'll commit this patch now.

zoo33’s picture

Great stuff!

How about the css patch in #7?

zoo33’s picture

Exposed filters in custom views don't work properly. When you submit the form you get redirected to a Views callback instead of Image assist, hence losing all its specific theming etc. This patch rewrites the #action attribute.

Also snuck in another fix: The Browse select list had an incorrect default value, which meant that most of the time the default would be My images, but it could also be a custom view. However, regardless of this, the bottom frame is always populated by My images by default. (This happens in img_assist.js.) So this patch sets the default to My images.

sun’s picture

Status: Needs review » Fixed

Works, committed!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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