Skip to content

Commit

Permalink
Fixed context for Timestamped Textarea and Text Group fields when use…
Browse files Browse the repository at this point in the history
…d with Pages.
  • Loading branch information
danwolfgang committed Feb 15, 2013
1 parent f617a85 commit 177c53f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,34 +324,45 @@ sub _create_tags {
my $tag = $field_def->tag;
# Load the objects (entry, author, whatever) based on the current
# field definition.
my $obj_type = $field_def->obj_type;
my $obj_type = ($field_def->obj_type =~ /(entry|page)/)
? 'entry' # Entry and Page both store as 'entry' in the stash.
: $field_def->obj_type;
my $basename = 'field.' . $field_def->basename;

# Create the actual tag Use the tag name and append "Loop" to it.
$tags->{block}->{$tag . 'Loop'} = sub {
my ( $ctx, $args, $cond ) = @_;

# Use the $obj_type to figure out what context we're in.
my $obj = $ctx->stash($obj_type);

# Then load the saved YAML
my $yaml = YAML::Tiny->read_string( $obj->$basename );

# The $field_name is the custom field basename.
foreach my $field_name ( keys %{$yaml->[0]} ) {
my $field = $yaml->[0]->{$field_name};

# Build the output tag content
my $out = '';
my $vars = $ctx->{__stash}{vars};
my $count = 0;

# The $group_num is the group order/parent of the values.
# Sort it so that they are displayed in the order they
# were saved.
foreach my $group_num ( sort keys %{$field} ) {
local $vars->{'__first__'} = ($count++ == 0);
local $vars->{'__last__'} = ($count == scalar keys %{$field});

# Add the keys and values to the output
foreach my $value ( keys %{$field->{$group_num}} ) {
$vars->{$value} = $field->{$group_num}->{$value};
}

defined( $out .= $ctx->slurp( $args, $cond ) ) or return;
}

return $out;
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ sub _create_tags {

# Load the objects (entry, author, whatever) based on the current
# field definition.
my $obj_type = $field_def->obj_type;
my $obj_type = ($field_def->obj_type =~ /(entry|page)/)
? 'entry' # Entry and Page both store as 'entry' in the stash.
: $field_def->obj_type;
my $basename = 'field.' . $field_def->basename;

# Create the actual tag Use the tag name and append "Loop" to it.
Expand Down

0 comments on commit 177c53f

Please sign in to comment.