Changeset 413 for branches/Release04x02/lib/TWiki/Form.pm
- Timestamp:
- 11/03/08 13:48:54 (4 years ago)
- File:
-
- 1 edited
-
branches/Release04x02/lib/TWiki/Form.pm (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/Release04x02/lib/TWiki/Form.pm
r21 r413 44 44 =pod 45 45 46 ---++ ClassMethod new ( $session, $web, $form, $def )46 ---++ ClassMethod new ( $session, $web, $form, \@def ) 47 47 48 48 Looks up a form in the session object or, if it hasn't been read yet, 49 49 reads it frm the form definition topic on disc. 50 * $web - default web to recover form from, if $form doesn't specify a web 51 * =$form= - topic name to read form definition from 52 * =$def= - optional. a reference to a list of field definitions. if present, 53 these definitions will be used, rather than those in =$form=. 50 * =$web= - default web to recover form from, if =$form= doesn't 51 specify a web 52 * =$form= - name of the form 53 * =\@def= - optional. A reference to a list of field definitions. 54 If present, these definitions will be used, rather than any read from 55 the form definition topic. Note that this array should not be modified 56 again after being passed into this constructor (it is not copied). 54 57 55 58 May throw TWiki::OopsException … … 81 84 82 85 # Read topic that defines the form 83 unless ( $store->topicExists( $web, $form ) ) { 86 if ( $store->topicExists( $web, $form ) ) { 87 my ( $meta, $text ) = 88 $store->readTopic( $session->{user}, $web, $form, undef ); 89 90 $this->{fields} = _parseFormDefinition( $this, $meta, $text ); 91 } 92 else { 93 delete $session->{forms}->{"$web.$form"}; 84 94 return undef; 85 95 } 86 my ( $meta, $text ) = 87 $store->readTopic( $session->{user}, $web, $form, undef ); 88 89 $this->{fields} = _parseFormDefinition( $this, $meta, $text ); 90 96 } 97 elsif ( ref($def) eq 'ARRAY' ) { 98 $this->{fields} = $def; 91 99 } 92 100 else { 93 101 94 $this->{fields} = $def;95 102 # TWiki::Meta object 103 $this->{fields} = $this->_extractPseudoFieldDefs($def); 96 104 } 97 105 } … … 182 190 $vals =~ s/^\s+//g; 183 191 $vals =~ s/\s+$//g; 184 185 # SMELL: This expansion of $users is undocumented, AFAICT not186 # used, and downright *dangerous* (it won't work with a non-TWiki187 # user mapping for example) so in the interests of good hygiene,188 # I have removed it (CC, 30 Jun 07).189 #if( $vals eq '$users' ) {190 # $vals = $TWiki::cfg{UsersWebName} . '.' .191 # join( ", ${TWiki::cfg{UsersWebName}}.",192 # ( $store->getTopicNames( $TWiki::cfg{UsersWebName} )));193 #}194 192 195 193 $tooltip ||= ''; … … 566 564 } 567 565 566 # extractPseudoFieldDefs( $meta ) -> $fieldDefs 567 # Examine the FIELDs in $meta and reverse-engineer a set of field 568 # definitions that can be used to construct a new "pseudo-form". This 569 # fake form can be used to support editing of topics that have an attached 570 # form that has no definition topic. 571 sub _extractPseudoFieldDefs { 572 my ( $this, $meta ) = @_; 573 my @fields = $meta->find('FIELD'); 574 my @fieldDefs; 575 require TWiki::Form::FieldDefinition; 576 foreach my $field (@fields) { 577 578 # Fields are name, value, title, but there is no other type 579 # information so we have to treat them all as "text" :-( 580 my $fieldDef = new TWiki::Form::FieldDefinition( 581 session => $this->{session}, 582 name => $field->{name}, 583 title => $field->{title} || $field->{name}, 584 attributes => $field->{attributes} || '' 585 ); 586 push( @fieldDefs, $fieldDef ); 587 } 588 return \@fieldDefs; 589 } 590 568 591 1; 569 592
Note: See TracChangeset
for help on using the changeset viewer.
