Ignore:
Timestamp:
11/03/08 13:48:21 (4 years ago)
Author:
CrawfordCurrie
Message:

Item67: a missing form definition would make a topic uneditable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/lib/TWiki/Form.pm

    r411 r412  
    4444=pod 
    4545 
    46 ---++ ClassMethod new ( $session, $web, $form, $def ) 
     46---++ ClassMethod new ( $session, $web, $form, \@def ) 
    4747 
    4848Looks up a form in the session object or, if it hasn't been read yet, 
    4949reads 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). 
    5457 
    5558May throw TWiki::OopsException 
     
    8184 
    8285            # 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"}; 
    8494                return undef; 
    8595            } 
    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; 
    9199        } 
    92100        else { 
    93101 
    94             $this->{fields} = $def; 
    95  
     102            # TWiki::Meta object 
     103            $this->{fields} = $this->_extractPseudoFieldDefs($def); 
    96104        } 
    97105    } 
     
    182190            $vals =~ s/^\s+//g; 
    183191            $vals =~ s/\s+$//g; 
    184  
    185             # SMELL: This expansion of $users is undocumented, AFAICT not 
    186             # used, and downright *dangerous* (it won't work with a non-TWiki 
    187             # 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             #} 
    194192 
    195193            $tooltip ||= ''; 
     
    566564} 
    567565 
     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. 
     571sub _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 
    5685911; 
    569592 
Note: See TracChangeset for help on using the changeset viewer.