a-ok Posted September 5, 2016 Share Posted September 5, 2016 I have a standard ckeditor textarea 'article_text' on all pages that use the 'article-detail' template. I am now needing to create a RepeaterMatrix field with one of the types being a ckeditor textarea 'article_content_text'. I now need to find a way to batch move the content of 'article_text' to a RepeaterMatrix row 'article_content_text' on each page. Any ideas with using the API if this is possible? I have over 200 articles so don't fancy manually doing it. Link to comment Share on other sites More sharing options...
a-ok Posted September 5, 2016 Author Share Posted September 5, 2016 I know, via the docs, that we can update a repeater field; but what about a RepeaterMatrix? $building = $page->buildings->getNew(); // I guess here would be a good place to tell it what 'type' to use? $building->title = 'One Atlantic Center'; $building->feet_high = 880; $building->num_floors = 50; $building->year_built = 1997; $building->save(); $page->buildings->add($building); $page->save(); Link to comment Share on other sites More sharing options...
Robin S Posted September 5, 2016 Share Posted September 5, 2016 The Repeater Matrix documentation seems to be lacking in this regard - I have requested some in the Repeater Matrix subforum. Link to comment Share on other sites More sharing options...
a-ok Posted September 6, 2016 Author Share Posted September 6, 2016 9 hours ago, Robin S said: The Repeater Matrix documentation seems to be lacking in this regard - I have requested some in the Repeater Matrix subforum. Great, thanks Robin. If anyone could shed any light on the matter (adding specific rows via the api for a RepeaterMatrix) that would be appreciated. Link to comment Share on other sites More sharing options...
Robin S Posted September 6, 2016 Share Posted September 6, 2016 The bit that I can't work out at the moment is how to set the matrix item type using a friendly name. I'm sure @ryan will have built in a way to do this, but until he responds you can set the matrix type as an integer using "repeater_matrix_type". First you need to find out the integer for the type of row you want to add. You can do this by dumping a repeater item of the right type and checking the repeater_matrix_type value in Tracy. Or you can open the field settings and inspect the source for the type you want to add. For example, in the screenshot below you can see the id of the inputfield for the "body" type is "matrix3_item", therefore the repeater_matrix_type integer is 3. So find out the repeater_matrix_type value (integer) for "article_content_text" and then you would run some code like this... $articles = $pages->find("template=article"); foreach($articles as $article) { $text = $article->article_text; $article->of(false); $new_item = $article->my_matrix_field->getNew(); // replace with the name of your matrix field $new_item->repeater_matrix_type = 3; // replace with the integer of your matrix type $new_item->article_text = $text; // assuming you added the article_text field to this matrix type $new_item->save(); $article->my_matrix_field->add($new_item); $article->save(); } But first test this works for a single article page before you process all the articles. 3 Link to comment Share on other sites More sharing options...
a-ok Posted September 6, 2016 Author Share Posted September 6, 2016 This totally works, Robin. This is great. It looks like the type is just ordered 1, 2, 3 etc based on the position (much like the Options field) so I guess that kind of makes sense but would be good to be able to call the name ('text', for example) rather than the integer. Thanks for the help here. Really appreciated as always. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now