Jump to content

multilingual image tags


fruid
 Share

Recommended Posts

I'm using image tags in combination with UIKIT filters. So the image tags (predefined or user-entered) serve as filters. My site is in two languages though, is there an easy way to have this field in two languages? 

Link to comment
Share on other sites

  • 5 months later...

For a different project, I'm using this module https://processwire.com/blog/posts/pw-3.0.142/ to have a HTML caption for a specific images-field. But I need a CKEditor instead, which is not allowed…

I get an error right where the field renders in the admin that type InputfieldCKEditor is not supported.

Do you know of any alternatives to this module?

Link to comment
Share on other sites

Thanks for your suggestion, but I don't think I like that one, reminds me of WordPress and the way it handles media. I don't need new pages or separate IDs for each image, just an editor in the caption field. What I had in place was almost perfect. I tried with TinyMCE which throws no errors and renders in the image field, but it doesn't work, I cannot type.

I might just add an images-array-field to upload all images for the page and add a repeater field width CKEditor that also includes a Hannacode somehow.

Link to comment
Share on other sites

OK Hannacode ist cool and I think to know how to use it, however, it doesn't really solve the issue here.

Basically I have a pool of images and each image has exactly one HTML-caption preferably created with a CKEditor field.

If I use a repeater field for the bodies, I shouldn't have any problem doing a one-by-one loop of images and bodies (i.e. image - body - image - body - …) in order of appearance. 

There is no benefit in using Hannacode for this at all. My concern is rather, that the "caption" is not really assigned to the image in regards to the database structure. If I ever want to return the same on a different page, or search it, there would be no API call for that.

Is it clear what I mean?

Link to comment
Share on other sites

I was thinking: "Ideally you would be able to drop all images in a repeater field, and it would a repeater page for each image, and upload each of them to a predefined field in that repeater"... then I just decided to google for it, and found this https://processwire.com/modules/repeater-images/

I'm surprised that I never came across this module by @Robin S, but it looks just awesome ?

  • Like 1
Link to comment
Share on other sites

actually, this module is pretty cOoL, does what it promises, thank you.

But, let's suppose I want to import over 3000 pages, a couple of images each. I tried to use @adrian's Admin Action FTP Files to Page (a process I also managed to automate before (i.e. batch-import for other images-fields)) in combination with @Robin S's repeater-images module to import images to my images field. It imports the images alright, but the repeater-items are not created automatically, I need to save the page manually in admin (an API call $page->save(); doesn't work either). I guess it's a problem with the hooks, one module is waiting for an action that the other module never triggers, so it cannot hook.

And now let's not just suppose but just accept the fact that it is indeed that many pages. Normally, I wouldn't mind saving each page manually, cause it's a one-time-migration, but with that amount, it's undoable.

Thanks for your ideas

Link to comment
Share on other sites

You couldn't use that action anymore, since you're not be adding each file to an image field, but instead you'll be adding a new item to a repeater field AND adding the image to a field in that newly created repeater item. You can copy that action to create a new action that does that. Looking at the code of that action https://github.com/adrianbj/ProcessAdminActions/blob/master/actions/FtpFilesToPage.action.php, in the defineOptions() function, and assuming that the existing 'field' option would hold the repeater field, you'd need to create a new 'image_field' option to hold the image field inside the repeater. Then you'd need to update the code inside the executeAction() function to create the repeater items. In line 78 you'd have something like (written on the knee and not tested):

$newItem = $destinationPage->$fieldName->getNew();  
$newItem->$imageFieldName->add($item->getPathname());
$newItem->save();

 

  • Like 1
Link to comment
Share on other sites

OK great, that actually worked with a few adjustments.

Firstly, I had to add FieldtypeRepeater to the fields selector for it to be a field option in the AdminAction dialogue.

'options' => $this->wire('fields')->find("type=FieldtypeFile|FieldtypeImage|FieldtypeRepeater")->getArray()

Secondly, had to save the newItem before continuing…

$newItem = $destinationPage->$fieldName->getNew();  
$newItem->save(); // << this one
$newItem->post_image->add($item->getPathname());
$newItem->save();

Now that the images are nicely distributed among different repeater items, I need to figure out a way to csv-import the captions. Not sure how to access a subfield of a repeater item and especially how to access them specifically, it seems like all the images of any of those pages are in one table cell and all the captions are in another. 

Thoughts?

Link to comment
Share on other sites

Where do you want to import the captions to? To the description of the image, to a custom field on that image, or to a separate field in that repeater item?

For the first and second you would just add this line before saving the new item: $newItem->post_image->description = "whatever"; or: $newItem->post_image->custom_field_name = "whatever";

For the third you would add something like: $newItem->field_name = "whatever";

  • Like 1
Link to comment
Share on other sites

  • 3 weeks later...

I managed to accomplish all that I mentioned here and what I internded. I can now batch create pages with a csv file and on these pages batch import images and create a new repeater-item for each image and add a html caption for each image.

One more small thing though, more out of curiosity than out of requirement in my case, how can I sort the repeater images according to the image-filename in use?

page when iterating is $p
repeater field is $image_and_caption
image field on that repeater is $post_image

Not sure if anyone else would need an AdminAction like that, if so, I could share it publicly.

cheers

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...