Thanks Scott. I'll fool around with it and send a patch
together if I
manage to get it to work.
Cheers,
Bret
Scott Lanning wrote:
> On Thu, 16 Aug 2007, Bret Dawson wrote:
>
>> Is there a straightforward way to give a code
select field access
>> to the current $story element?
>
>
> When the select list in the Story Profile is
generated,
> there isn't a "current $story element"
> because that isn't a template context.
> I get what you mean, though,
> and it's an interesting idea
> to be able to get at the object representing
> the current element or story.
> You might even say it's an obvious idea.
> But I think it's not currently possible....
>
> It would be easy to add that functionality, though.
> In comp/widgets/container_prof/edit.html,
> there's a call to eval_codeselect:
>
> # Set the array of possible values, if necessary.
> if ( my $tmp = $vals-> ) {
> if ($vals-> eq 'codeselect') {
> $vals-> =
eval_codeselect($tmp);
>
> So it takes the text ($tmp) that you've put in the
element type
> and passes that to eval_codeselect (in
lib/Bric/App/Util.pm).
> In edit.html, the variable $dt is the current
element
> (there is a foreach loop over the elements).
> I think it'd be best to pass that to eval_codeselect,
> rather than passing in the element's "owning"
story,
> because someone will eventually come along
> and wonder how to access the current element.
> So
>
> $vals-> = eval_codeselect($dt,
$tmp);
>
> In lib/Bric/App/Util.pm we have
>
> sub eval_codeselect {
> # XXX: This is very unsafe, but they need to be
able
> # to do things like DBI queries; would that work
with Safe?
> local $_;
> my $res = eval shift;
>
> I'm not sure why $_ is localized,
> but maybe it could be changed to this
>
> local $_ = shift;
>
> to set $_ to the current field.
> (Or we could leave $_ undef and set another variable.)
> Then in the code for the codeselect,
> in order to get the story you'd do something like:
>
> my $story =
Bric::Biz::Asset::Business::Story->lookup({
> id => $_->get_object_instance_id
> });
>
> (There might be a better way to get that.
> Remember: $_ would be the current field element.)
>
>
--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret pectopah.com
www.pectopah.com
|