Jump to content

Fieldtype for selecting images from another field on same page


Tyssen
 Share

Recommended Posts

Is there a way to select an image from another image field on the page, much the same way as CKEditor fields can when embedding images?

Why not just use an ordinary image field?

Because in my case, I have a repeater for creating a home page carousel for featured news items. Each row in the repeater has an image field. Sometimes you want to be able to use the same image for more than one slide. Currently you have to upload the same image to each row.

And if you need to replace an image but know you'll need to use it again at a future date, you have to leave it attached to the image field but move it away from the first position so any new images can be first instead.

So each row ends up with 5-6 different images that are used frequently for different types of topics, which is a) a bit untidy, and b) means you have to repeatedly upload common images, i.e. duplication of effort.

It would be better if I could have a global images field for the page, and then in each repeating row, a fieldtype that can choose an existing image from that field. I thought about using a CKEditor fieldtype, but that generates all the markup too, and I don't want to do that as the markup will be generated with dynamic image sizes in the template.

I also know of the image manager module that Soma made but that's not really what I'm after either.

Is there any way to accomplish this?

Link to comment
Share on other sites

but I don't think it's possible.

That's very defeatist :)

It's not "currently" possible, but I am sure there is something that can be put together - Marty, I have your thoughts from our conversation filed away for a rainy day, or if someone gets to it before me that would be nice too :)

Link to comment
Share on other sites

can't you put your images under a new parent (eg /data/images) and then reference it via a pagefield in your repeater? do repeaters support pagefields? I'm always using pagetable instead of repeaters :)

of course that would not be very fancy and maybe cumbersome - but maybe it is ok for your case?

Link to comment
Share on other sites

Yeah, not very user-friendly. The site editors would have to add images to a separate entry whereas they already currently add images to the rows in the entry that controls the page. Feels like that would be a step backward usability-wise.

Link to comment
Share on other sites

It does seem like what I'm looking for but I can't get it to work either. I've already got ImagesManager installed and set up and have added a field to my page but all it seems to do is enable you to search for images but doesn't actually save any information about the image once you've found it. The only fields in the fieldtype are for filtering, nothing for saving data.

Actually, on closer inspection I can see the field for saving the data is set to display:none and so is the container for what looks like is supposed to appear after you've selected an image. But I don't see any way of actually selecting the image from within the ImagesManager or the search that then inserts it into the field.

Link to comment
Share on other sites

I tested installIng ImagesManager and then ImagesSelect and works fine.

Note both modules are WIP and proof of concept. I don't support them. They're not in the official modules directory.

ImagesSelect is tailored to a project and while working it isn't meant to be ready to use and has many hard coded assumptions that all is easy to customize if you know what you're doing. So anybody can take it and study it and adapt it. I just shared it for others to see.

  • Like 2
Link to comment
Share on other sites

The ImagesSelect let's you filter and search from the images you create as pages like ImagesManager does. You see a list of results and each has a +add button to add it to the page. It looks like a image field and it copies the description from the source but you can then change it. the image it self is just a reference line a page select. It doesn't copy the real image. So you can't insert it into a RTE On the page. It doesn't support multi language.

The live search is using Selector Inputfield from core.

The image markup inserted is copied from the core image field but isn't meant to function like it. Just the sorting and description field.

Link to comment
Share on other sites

Repeaters are pages themself. So it would'nt be on same page technically.

Since repeaters aren't supported anymore to go any further by Ryan (strangely it's the most used field type it seems fir a reason) cause it causes technical problems. And it showed.

Your best bet would be to use subpages or pagetable instead. PagetabLe and ImagesSelect. And use ImagesManager to create image DB you can select images from. Not all as in a perfect world but there's lots of benefits from going this route. I built ImagesManager to show how it can be done and I'm a little sad some other smart people didn't join in to make it big and improve its implementation.

Btw I'm using this combination on a big news portal www.1815.ch with lots of editors and while it may take an extra step they're pretty happy and love PW now.

There wasn't even a obvious reason to use referenced images and we may even convert it back to on page core image field, but it proved to be pretty stable and flexible while still open to change it quickly.

Image and files in general are a though one especially cause PW is so different. Only time will tell what will happen.

My concept is clear to use native tools fields and pages, to build a media db and then provide helper modules to manage them. And a lot is possible then.

Building proprietary image fields that somehow provide other functionality is critical as when Ryan builds whole new functions and tools into image field that then are missing in other self made image modules. My tools work still and I benefit from updates on the image field cause I use page per image with a core image field. Ok but now I use the new croppable image field and it doesn't let me use new size tools Ryan build cause it uses other or modified markup.

Another benefit is that I can use ListerPro to build a search and edit tool to show the image DB. I don't have to think about if it woud work it just works.

  • Like 2
Link to comment
Share on other sites

I'm testing out a PageTable field with ImagesSelect and can now see the + button but I'm having trouble displaying data on the front end to test the output.

I thought I could do:

foreach($page->pageTableField as $field) :
	echo $field->title . '<br>' . $field->description . '<br>';
endforeach;

But I get no output. If I just do:

echo $page->repeaterField

I get a list of pipe-separated ID numbers. But if I do:

echo $page->pageTableField

I get nothing. I can see in the db that the data for the pageTable field is a single ID corresponding to the new page that's been created.

So am I doing something wrong?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...