Jump to content

Copy content of image field within repeater field via API


alexcapes
 Share

Recommended Posts

Hi,

I've created a module to copy across field content from one page to another page, which is working well for all fieldtypes, except for repeater fields.

This is my current code for repeater fields:

          // Repeater
          if(count($page->article_list)) {
            $translation->of(false);
            $translation->article_list->removeAll();

            foreach($page->article_list as $item) {
              $translation->article_list->import($item);
            }
            $translation->save();
          }

It copies across the repeaters and the fields within them fine (there are two fields, a textarea and image field).

However only the content of the the textarea field is copied - the image field remains blank.

(Just for reference it is a single image field).

Can anyone help me out in how I might copy the image (and the description) across please?

Thanks!

Link to comment
Share on other sites

Not quite sure why but this is now working and copy across all field content (including images)...

          // Repeater
          if(count($page->article_list)) {
            $translation->of(false);
            $translation->article_list->removeAll();
            $lists = $page->article_list;
            foreach($lists as $item) {
              $translation->article_list->import($item);
              $translation->save("article_list");
            }
          }
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...