
david at kineticode
Jul 29, 2008, 9:48 AM
Post #6 of 10
(295 views)
Permalink
|
|
Re: Programmatic Container Element Creation
[In reply to]
|
|
On Jul 28, 2008, at 05:56, Trevor Smith wrote: > This is the error I am getting back: > Can't locate object method "get_field_types" via package > "Bric::Biz::Element::Container" Please always include a stack trace when you post stuff like this, otherwise we have no idea where the error occurred or what triggered it. > I assume this applies to this line: > % $curuidstory->get_fields('uid')->set_value($uid); > > What I'm trying to do there is store the UID stored in the variable > $uid into the field 'uid' within my newly created container element. > Each container element only consists of a non-repeating UID text input > field and then a related story. I rewrote things so that I could better understand what you were doing. You're pretty close, I think; I added code to add the UID field if it doesn't already exist. If it's a required field, it should exist, but who knows? Anyway, give this a try; I'm assuming that this is a utility template, hence the `return`. Be sure to use List::Util in PERL_LOADER in bricolage.conf. I've not tested this code, of course, so watch for syntax errors! <%perl>; # $uri == URI to store # Store the returned UID use List::Util 'first'; # Put this in PERL_LOADER. my $uidstory = Bric::Biz::Asset::Business::Story->lookup({ uuid => '595FC2AC-58B9-11DD-800B-39D208E6C7E9', }); # UID INDEX STORY return if first { $uid = $_->get_value('uid') } $uidstory->get_elements('event_uid'); # Add an "event_uid" container element to the UID story. my $elem = $uidstory->get_element; my $etype = Bric::Biz::ElementType->lookup({ key_name => 'event_uid' }); my $euid = $uidstory->add_container($etype); # Make sure that the element has a "uri" field. my $uid_field = $euid->get_field('uid'); unless ($uid_field) { my $et = $uidstory->get_element_type; my $ftype = $et->get_field_types('uid'); $elem->add_field($ftype); $uid_field = $euid->get_field('uid'); } # Set the UID and relate the current story. $uid_field->set_vaule($uid); $elem->set_related_story($story); $elem->save; </%perl> Best, David
|