From 4b663fdf0bcba2bbb4d83c1dbf872297c90857e6 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 11 Jul 2011 13:04:22 -0700 Subject: [PATCH] Override new in Form plugins that set their options, so the options are always available. Fixes bug #12190. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Form/AdSpace.pm | 28 ++++++--------------- lib/WebGUI/Form/ContentType.pm | 40 ++++++++++++++++-------------- lib/WebGUI/Form/Country.pm | 14 +++++------ lib/WebGUI/Form/DatabaseLink.pm | 11 ++++---- lib/WebGUI/Form/FilterContent.pm | 29 +++++++++++----------- lib/WebGUI/Form/Group.pm | 25 +++++-------------- lib/WebGUI/Form/LdapLink.pm | 25 +++++-------------- lib/WebGUI/Form/MatrixCompare.pm | 24 ++++++------------ lib/WebGUI/Form/MatrixFieldType.pm | 22 ++++++++-------- lib/WebGUI/Form/MimeType.pm | 36 ++++++++++++++++++--------- lib/WebGUI/Form/TimeZone.pm | 18 +------------- lib/WebGUI/Form/Vendor.pm | 25 +++++-------------- lib/WebGUI/Form/Workflow.pm | 11 ++++---- 14 files changed, 124 insertions(+), 185 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 046801b9b..d3c7623df 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -9,6 +9,7 @@ - fixed #12188: Thingy broken after upgrade to 7.9.32-stable - fixed #12184: Apache error in modperl.error.log (William McKee, Knowmad Technologies) - fixed #12186: keywords template variable not working properly in Article + - fixed #12190: List type form plugins that do not override getOptions show no value when getValueAsHtml is called 7.10.19 - fixed #12169: extras uploads symlink export diff --git a/lib/WebGUI/Form/AdSpace.pm b/lib/WebGUI/Form/AdSpace.pm index dfc6a45c2..472e0ae91 100644 --- a/lib/WebGUI/Form/AdSpace.pm +++ b/lib/WebGUI/Form/AdSpace.pm @@ -17,6 +17,7 @@ package WebGUI::Form::AdSpace; use strict; use base 'WebGUI::Form::SelectBox'; use WebGUI::International; +use WebGUI::AdSpace; =head1 NAME @@ -137,34 +138,19 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Returns a group pull-down field. A group pull down provides a select list that provides name value pairs for all the groups in the WebGUI system. +Extend the base "new" to set options and the default value. =cut -sub toHtml { - my $self = shift; +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); my $options = { map { $_->getId => $_->get('name') } ( @{ WebGUI::AdSpace->getAdSpaces($self->session) } ) }; $self->set('defaultValue', ( keys %{$options} )[0] ); $self->set('options', $options ); - return $self->SUPER::toHtml(); -} - -#------------------------------------------------------------------- - -=head2 toHtmlAsHidden ( ) - -Creates a series of hidden fields representing the data in the list. - -=cut - -sub toHtmlAsHidden { - my $self = shift; - my $options = { map { $_->getId => $_->get('name') } ( @{ WebGUI::AdSpace->getAdSpaces($self->session) } ) }; - $self->set('defaultValue', ( keys %{$options} )[0] ); - $self->set('options', $options ); - return $self->SUPER::toHtmlAsHidden(); + return $self; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/ContentType.pm b/lib/WebGUI/Form/ContentType.pm index aaaa3d37b..677ac61c0 100644 --- a/lib/WebGUI/Form/ContentType.pm +++ b/lib/WebGUI/Form/ContentType.pm @@ -118,29 +118,33 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Renders a select list form control. +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; - my %types; - my $i18n = WebGUI::International->new($self->session); - foreach my $type (@{ $self->get('types') }) { - if ($type eq "text") { - $types{text} = $i18n->get(1010); - } elsif ($type eq "mixed") { - $types{mixed} = $i18n->get(1008); - } elsif ($type eq "code") { - $types{code} = $i18n->get(1011); - } elsif ($type eq "html") { - $types{html} = $i18n->get(1009); - } +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); + my %types; + my $i18n = WebGUI::International->new($self->session); + foreach my $type (@{ $self->get('types') }) { + if ($type eq "text") { + $types{text} = $i18n->get(1010); } - $self->set("options", \%types); - return $self->SUPER::toHtml(); + elsif ($type eq "mixed") { + $types{mixed} = $i18n->get(1008); + } + elsif ($type eq "code") { + $types{code} = $i18n->get(1011); + } + elsif ($type eq "html") { + $types{html} = $i18n->get(1009); + } + } + $self->set("options", \%types); + return $self; } 1; diff --git a/lib/WebGUI/Form/Country.pm b/lib/WebGUI/Form/Country.pm index a71f54aca..679b0222c 100644 --- a/lib/WebGUI/Form/Country.pm +++ b/lib/WebGUI/Form/Country.pm @@ -245,20 +245,20 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Renders a country picker control. +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; - +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); my %countries; tie %countries, 'Tie::IxHash'; %countries = map {$_ => $_} getCountries(); - $self->set("options", \%countries); - return $self->SUPER::toHtml(); + $self->set('options', \%countries); + return $self; } 1; diff --git a/lib/WebGUI/Form/DatabaseLink.pm b/lib/WebGUI/Form/DatabaseLink.pm index 1a4a841eb..57fb79550 100644 --- a/lib/WebGUI/Form/DatabaseLink.pm +++ b/lib/WebGUI/Form/DatabaseLink.pm @@ -145,16 +145,17 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Renders a database connection picker control. +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); $self->set("options", WebGUI::DatabaseLink->getList($self->session)); - return $self->SUPER::toHtml(); + return $self; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/FilterContent.pm b/lib/WebGUI/Form/FilterContent.pm index c5e620b1c..7c80bb78f 100644 --- a/lib/WebGUI/Form/FilterContent.pm +++ b/lib/WebGUI/Form/FilterContent.pm @@ -144,26 +144,27 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Returns a select list containing the content filter options. This is for use with WebGUI::HTML::filter(). +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); my $i18n = WebGUI::International->new($self->session); - my %filter; - tie %filter, 'Tie::IxHash'; - %filter = ( - 'none'=>$i18n->get(420), - 'macros'=>$i18n->get(891), - 'javascript'=>$i18n->get(526), - 'most'=>$i18n->get(421), - 'all'=>$i18n->get(419) - ); + my %filter; + tie %filter, 'Tie::IxHash'; + %filter = ( + 'none' => $i18n->get(420), + 'macros' => $i18n->get(891), + 'javascript' => $i18n->get(526), + 'most' => $i18n->get(421), + 'all' => $i18n->get(419), + ); $self->set("options", \%filter); - return $self->SUPER::toHtml(); + return $self; } 1; diff --git a/lib/WebGUI/Form/Group.pm b/lib/WebGUI/Form/Group.pm index c662cd722..e4eb48a55 100644 --- a/lib/WebGUI/Form/Group.pm +++ b/lib/WebGUI/Form/Group.pm @@ -186,34 +186,21 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Returns a group pull-down field. A group pull down provides a select list that provides name value pairs for all the groups in the WebGUI system. +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); my $where = ''; if (($self->get('excludeGroups')->[0]||'') ne "") { $where = "and groupId not in (".$self->session->db->quoteAndJoin($self->get("excludeGroups")).")"; } $self->set('options', $self->session->db->buildHashRef("select groupId,groupName from groups where showInForms=1 $where order by groupName")); - return $self->SUPER::toHtml(); -} - -#------------------------------------------------------------------- - -=head2 toHtmlAsHidden ( ) - -Creates a series of hidden fields representing the data in the list. - -=cut - -sub toHtmlAsHidden { - my $self = shift; - $self->set("options", $self->session->db->buildHashRef("select groupId,groupName from groups")); - return $self->SUPER::toHtmlAsHidden(); + return $self; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/LdapLink.pm b/lib/WebGUI/Form/LdapLink.pm index 8adf4b531..553a8b586 100644 --- a/lib/WebGUI/Form/LdapLink.pm +++ b/lib/WebGUI/Form/LdapLink.pm @@ -152,30 +152,17 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Renders a database connection picker control. +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); $self->set("options", WebGUI::LDAPLink->getList($self->session)); - return $self->SUPER::toHtml(); -} - -#------------------------------------------------------------------- - -=head2 toHtmlAsHidden ( ) - -Creates a series of hidden fields representing the data in the list. - -=cut - -sub toHtmlAsHidden { - my $self = shift; - $self->set("options", WebGUI::LDAPLink->getList($self->session)); - return $self->SUPER::toHtmlAsHidden(); + return $self; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/MatrixCompare.pm b/lib/WebGUI/Form/MatrixCompare.pm index e117c8824..e3b697e5a 100644 --- a/lib/WebGUI/Form/MatrixCompare.pm +++ b/lib/WebGUI/Form/MatrixCompare.pm @@ -123,15 +123,7 @@ Shows either Yes or No. sub getValueAsHtml { my $self = shift; - my $i18n = WebGUI::International->new($self->session,'Form_MatrixCompare'); - my %options = ( - 0 => $i18n->get('no'), - 1 => $i18n->get('limited'), - 2 => $i18n->get('costs extra'), - 3 => $i18n->get('free add on'), - 4 => $i18n->get('yes'), - ); - return $options{$self->getOriginalValue}; + return $self->get('options')->{$self->getOriginalValue}; } #------------------------------------------------------------------- @@ -148,14 +140,15 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Renders a fieldType selector. +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); my $i18n = WebGUI::International->new($self->session,'Form_MatrixCompare'); my %options; tie %options, "Tie::IxHash"; @@ -168,10 +161,7 @@ sub toHtml { ); $self->set('options', \%options); $self->set('defaultValue',0); - return $self->SUPER::toHtml(); + return $self; } - - 1; - diff --git a/lib/WebGUI/Form/MatrixFieldType.pm b/lib/WebGUI/Form/MatrixFieldType.pm index 6da045d9e..918992ba4 100644 --- a/lib/WebGUI/Form/MatrixFieldType.pm +++ b/lib/WebGUI/Form/MatrixFieldType.pm @@ -127,27 +127,25 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Renders a fieldType selector. +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; - my %options; - tie %options, "Tie::IxHash"; +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); + my %options; + tie %options, "Tie::IxHash"; %options = ( MatrixCompare => WebGUI::Pluggable::instanciate('WebGUI::Form::MatrixCompare', 'getName',[$self->session]), - SelectBox => WebGUI::Pluggable::instanciate('WebGUI::Form::SelectBox', 'getName',[$self->session]), - Combo => WebGUI::Pluggable::instanciate('WebGUI::Form::Combo', 'getName',[$self->session]), + SelectBox => WebGUI::Pluggable::instanciate('WebGUI::Form::SelectBox', 'getName',[$self->session]), + Combo => WebGUI::Pluggable::instanciate('WebGUI::Form::Combo', 'getName',[$self->session]), ); $self->set('options', \%options); $self->set('defaultValue','MatrixCompare'); - return $self->SUPER::toHtml(); + return $self; } - - 1; - diff --git a/lib/WebGUI/Form/MimeType.pm b/lib/WebGUI/Form/MimeType.pm index ae58397d4..7d47afc9b 100644 --- a/lib/WebGUI/Form/MimeType.pm +++ b/lib/WebGUI/Form/MimeType.pm @@ -38,6 +38,18 @@ The following methods are specifically available from this class. Check the supe #------------------------------------------------------------------- +=head2 areOptionsSettable ( ) + +Returns 0. + +=cut + +sub areOptionsSettable { + return 0; +} + +#------------------------------------------------------------------- + =head2 definition ( [ additionalTerms ] ) See the super class for additional details. @@ -92,24 +104,24 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Renders a database connection picker control. +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; - my $mimeTypes; - foreach ('text/html','text/css','text/javascript','text/plain','text/xml','application/xml') { - $mimeTypes->{$_}=$_; - } +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); + my $mimeTypes; + foreach ('text/html','text/css','text/javascript','text/plain','text/xml','application/xml') { + $mimeTypes->{$_}=$_; + } + ##Handle the combo box my $value = $self->getOriginalValue(); $mimeTypes->{$value} = $value; - $self->set("options", $mimeTypes); - return $self->SUPER::toHtml(); + $self->set("options", $mimeTypes); + return $self; } - 1; - diff --git a/lib/WebGUI/Form/TimeZone.pm b/lib/WebGUI/Form/TimeZone.pm index 2c98a315b..4a56619c3 100644 --- a/lib/WebGUI/Form/TimeZone.pm +++ b/lib/WebGUI/Form/TimeZone.pm @@ -110,24 +110,8 @@ sub new { my $defaultValue = $self->get('defaultValue'); $defaultValue =~ tr/ /_/; $self->set('defaultValue', $defaultValue); + $self->set("options", $self->session->datetime->getTimeZones()); return $self; } -#------------------------------------------------------------------- - -=head2 toHtml ( ) - -Renders a database connection picker control. - -=cut - -sub toHtml { - my $self = shift; - $self->set("options", $self->session->datetime->getTimeZones()); - return $self->SUPER::toHtml(); -} - - - 1; - diff --git a/lib/WebGUI/Form/Vendor.pm b/lib/WebGUI/Form/Vendor.pm index 367268cbe..e8d67d8dd 100644 --- a/lib/WebGUI/Form/Vendor.pm +++ b/lib/WebGUI/Form/Vendor.pm @@ -141,30 +141,17 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Returns a group pull-down field. A group pull down provides a select list that provides name value pairs for all the vendors in the WebGUI system. +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); $self->set('options', WebGUI::Shop::Vendor->getVendors($self->session, {asHashRef=>1})); - return $self->SUPER::toHtml(); -} - -#------------------------------------------------------------------- - -=head2 toHtmlAsHidden ( ) - -Creates a series of hidden fields representing the data in the list. - -=cut - -sub toHtmlAsHidden { - my $self = shift; - $self->set("options", WebGUI::Shop::Vendor->getVendors($self->session, {asHashRef=>1})); - return $self->SUPER::toHtmlAsHidden(); + return $self; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Form/Workflow.pm b/lib/WebGUI/Form/Workflow.pm index 5c9f63707..d5b55a115 100644 --- a/lib/WebGUI/Form/Workflow.pm +++ b/lib/WebGUI/Form/Workflow.pm @@ -141,14 +141,15 @@ sub isDynamicCompatible { #------------------------------------------------------------------- -=head2 toHtml ( ) +=head2 new ( ) -Renders a template picker control. +Extend the base "new" to set options. =cut -sub toHtml { - my $self = shift; +sub new { + my $class = shift; + my $self = $class->SUPER::new(@_); my $workflowList = WebGUI::Workflow->getList($self->session, $self->get("type")); if ( $self->get("none") ) { @@ -157,7 +158,7 @@ sub toHtml { } $self->set("options", $workflowList); - return $self->SUPER::toHtml(); + return $self; } #-------------------------------------------------------------------