Add a method to get, store and cache the current Entry, since it's needed when creating the form data.

This commit is contained in:
Colin Kuskie 2010-09-17 13:50:11 -07:00
parent 2609e06a44
commit 4d0ef740d8

View file

@ -278,20 +278,16 @@ sub _createForm {
#-------------------------------------------------------------------
=head2 _getFormFields ($entry)
=head2 _getFormFields ( )
Return a list of form fields for this DataForm.
=head3 $entry
A WebGUI::AssetCollateral::DataForm::Entry collateral object, with data for an entry in the DataForm.
=cut
sub _getFormFields {
my $self = shift;
my $session = $self->session;
my $entry = shift;
my $entry = $self->entry;
my @orderedFields = map { $self->getFieldConfig($_) } @{ $self->getFieldOrder };
my $func = $session->form->process('func');
my $ignoreForm = $func eq 'editSave' || $func eq 'editFieldSave';
@ -471,6 +467,31 @@ override getContentLastModified => sub {
#-------------------------------------------------------------------
=head2 entry ( [ $entry ] )
Returns a DataForm Entry object. If one is cached in the object, it will return it.
If the current request object has an entryId, then it will fetch the Entry from the database.
Otherwise, it will return an empty DataForm Entry object.
=head3 $entry
A DataForm Entry object. If passed, it will set the cache in this object. This takes precedence
over any other option.
=cut
sub entry {
my $self = shift;
my $entry = shift;
$self->{_entry} = $entry if defined $entry;
return $self->{_entry} if $self->{_entry};
my $entryId = $self->session->form->process("entryId");
$self->{_entry} = $self->entryClass->new($self, ($entryId && $self->canEdit) ? $entryId : ());
return $self->{_entry};
}
#-------------------------------------------------------------------
=head2 hasCaptcha
Returns true if the DataForm uses a captcha as one of the fields.
@ -1314,8 +1335,7 @@ sub viewForm {
my $entry = shift;
my $var = $self->getTemplateVars;
if (!$entry) {
my $entryId = $self->session->form->process("entryId");
$entry = $self->entryClass->new($self, ($entryId && $self->canEdit) ? $entryId : ());
$entry = $self->entry;
}
$var = $passedVars || $self->getRecordTemplateVars($var, $entry);
if ($self->hasCaptcha) {
@ -2132,8 +2152,7 @@ sub www_process {
unless $self->canView;
my $session = $self->session;
my $i18n = WebGUI::International->new($session,"Asset_DataForm");
my $entryId = $session->form->process('entryId');
my $entry = $self->entryClass->new($self, ( $entryId ? $entryId : () ) );
my $entry = $self->entry;
my $var = $self->getTemplateVars;
@ -2191,7 +2210,7 @@ sub www_process {
}
# Send email
if ($self->mailData && !$entryId) {
if ($self->mailData && !$entry->entryId) {
$self->sendEmail($var, $entry);
}