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:
parent
748ec0c440
commit
b8ad4cc136
1 changed files with 30 additions and 11 deletions
|
|
@ -85,20 +85,16 @@ sub _createForm {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
=head2 _getFormFields ($entry)
|
=head2 _getFormFields ( )
|
||||||
|
|
||||||
Return a list of form fields for this DataForm.
|
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
|
=cut
|
||||||
|
|
||||||
sub _getFormFields {
|
sub _getFormFields {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $entry = shift;
|
my $entry = $self->entry;
|
||||||
my @orderedFields = map { $self->getFieldConfig($_) } @{ $self->getFieldOrder };
|
my @orderedFields = map { $self->getFieldConfig($_) } @{ $self->getFieldOrder };
|
||||||
my $func = $session->form->process('func');
|
my $func = $session->form->process('func');
|
||||||
my $ignoreForm = $func eq 'editSave' || $func eq 'editFieldSave';
|
my $ignoreForm = $func eq 'editSave' || $func eq 'editFieldSave';
|
||||||
|
|
@ -278,6 +274,31 @@ sub getContentLastModified {
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=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
|
=head2 hasCaptcha
|
||||||
|
|
||||||
Returns true if the DataForm uses a captcha as one of the fields.
|
Returns true if the DataForm uses a captcha as one of the fields.
|
||||||
|
|
@ -1317,8 +1338,7 @@ sub viewForm {
|
||||||
my $entry = shift;
|
my $entry = shift;
|
||||||
my $var = $self->getTemplateVars;
|
my $var = $self->getTemplateVars;
|
||||||
if (!$entry) {
|
if (!$entry) {
|
||||||
my $entryId = $self->session->form->process("entryId");
|
$entry = $self->entry;
|
||||||
$entry = $self->entryClass->new($self, ($entryId && $self->canEdit) ? $entryId : ());
|
|
||||||
}
|
}
|
||||||
$var = $passedVars || $self->getRecordTemplateVars($var, $entry);
|
$var = $passedVars || $self->getRecordTemplateVars($var, $entry);
|
||||||
if ($self->hasCaptcha) {
|
if ($self->hasCaptcha) {
|
||||||
|
|
@ -2135,8 +2155,7 @@ sub www_process {
|
||||||
unless $self->canView;
|
unless $self->canView;
|
||||||
my $session = $self->session;
|
my $session = $self->session;
|
||||||
my $i18n = WebGUI::International->new($session,"Asset_DataForm");
|
my $i18n = WebGUI::International->new($session,"Asset_DataForm");
|
||||||
my $entryId = $session->form->process('entryId');
|
my $entry = $self->entry;
|
||||||
my $entry = $self->entryClass->new($self, ( $entryId ? $entryId : () ) );
|
|
||||||
|
|
||||||
my $var = $self->getTemplateVars;
|
my $var = $self->getTemplateVars;
|
||||||
|
|
||||||
|
|
@ -2194,7 +2213,7 @@ sub www_process {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Send email
|
# Send email
|
||||||
if ($self->get("mailData") && !$entryId) {
|
if ($self->get("mailData") && !$entry->entryId) {
|
||||||
$self->sendEmail($var, $entry);
|
$self->sendEmail($var, $entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue