Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Bricolage: users

Moving a subelement from one story to another

 

 

Bricolage users RSS feed   Index | Next | Previous | View Threaded


acaul at rand

Sep 4, 2009, 12:23 PM

Post #1 of 4 (849 views)
Permalink
Moving a subelement from one story to another

Hi. I am looking to insert a subelement from one story into another
story. I have this so far:


<%perl>
# $from_story and $to_story are definitely defined and populated.

my $from_subel = $from_story->get_container("subel");

if ($from_subel) {
my $to_subel = $to_story->add_container($from_subel);
$to_story->save();
if ($to_subel) {
print "{" . $to_subel->get_data("headline") . "}<br>\n";
} # end if
} # end if
</%perl>

When I preview the handler story I get

Can't locate object method "get_field_types" via package
"Bric::Biz::Element::Container"


I have done this successfully with fields but never with containers.
Thanks for any suggestions.

__________________________________________________________________________

This email message is for the sole use of the intended recipient(s) and
may contain confidential information. Any unauthorized review, use,
disclosure or distribution is prohibited. If you are not the intended
recipient, please contact the sender by reply email and destroy all copies
of the original message.


adrian at gossamer-threads

Sep 5, 2009, 2:29 PM

Post #2 of 4 (779 views)
Permalink
Re: Moving a subelement from one story to another [In reply to]

Hi,

If you search the archives and check out my github repo, you can see my
copy/paste code that i did for WHO (where it does containers).

http://github.com/brewt/bricolage/tree/master

Unfortunately, its been a while since I looked at the code and have forgotten
where everything is.

Adrian

On Fri, 4 Sep 2009 15:23:41 -0400
Ashlee Caul <acaul [at] rand> wrote:
> Hi. I am looking to insert a subelement from one story into another
> story. I have this so far:
>
>
> <%perl>
> # $from_story and $to_story are definitely defined and populated.
>
> my $from_subel = $from_story->get_container("subel");
>
> if ($from_subel) {
> my $to_subel = $to_story->add_container($from_subel);
> $to_story->save();
> if ($to_subel) {
> print "{" . $to_subel->get_data("headline") . "}<br>\n";
> } # end if
> } # end if
> </%perl>
>
> When I preview the handler story I get
>
> Can't locate object method "get_field_types" via package
> "Bric::Biz::Element::Container"
>
>
> I have done this successfully with fields but never with containers.
> Thanks for any suggestions.
>
> __________________________________________________________________________
>
> This email message is for the sole use of the intended recipient(s) and
> may contain confidential information. Any unauthorized review, use,
> disclosure or distribution is prohibited. If you are not the intended
> recipient, please contact the sender by reply email and destroy all copies
> of the original message.


david at kineticode

Sep 8, 2009, 2:30 PM

Post #3 of 4 (767 views)
Permalink
Re: Moving a subelement from one story to another [In reply to]

On Sep 4, 2009, at 12:23 PM, Ashlee Caul wrote:

> # $from_story and $to_story are definitely defined and populated.
>
> my $from_subel = $from_story->get_container("subel");
>
> if ($from_subel) {
> my $to_subel = $to_story->add_container($from_subel);

This won't work. You pass an element type to add_container, not a
container. Pass it to add_element(), instead. But clone it first:

use CLONE;
if (my $from_subel = $from_story->get_container("subel")) {
$to_story->add_element( CLONE::clone($from_subel)-
>prepare_clone );
$to_story->save;
}

You have to use CLONE::clone() because prepare_clone changes the
element in-place (basically just sets the ID to `undef`), and you
don't want to mess it up in $from_story.

HTH,

David


david at kineticode

Sep 8, 2009, 2:32 PM

Post #4 of 4 (767 views)
Permalink
Re: Moving a subelement from one story to another [In reply to]

On Sep 8, 2009, at 2:30 PM, David E. Wheeler wrote:

> This won't work. You pass an element type to add_container, not a
> container. Pass it to add_element(), instead. But clone it first:
>
> use CLONE;
> if (my $from_subel = $from_story->get_container("subel")) {
> $to_story->add_element( CLONE::clone($from_subel)-
> >prepare_clone );
> $to_story->save;
> }
>
> You have to use CLONE::clone() because prepare_clone changes the
> element in-place (basically just sets the ID to `undef`), and you
> don't want to mess it up in $from_story.

Sorry, make that:

$to_story->get_element->add_element( CLONE::clone($from_subel)-
>prepare_clone );

Best,

David

Bricolage users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.