- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables
Class ::xowiki::PageInstance
::xowiki::PageInstance create ...
Defined in
Class Relations
::xo::db::CrClass create ::xowiki::PageInstance \ -superclass ::xowiki::PageMethods (to be applied on the object)
get_list_from_form_constraints (scripted)
set spec [::xowiki::PageInstance get_short_spec_from_form_constraints -name $name -form_constraints $form_constraints] set result [list] foreach spec [split $spec ,] { if {[regexp {^([^=]+)=(.*)$} $spec _ attr value]} { lappend result $attr $value } else { :log "can't parse $spec in attribute and value; ignoring" } } return $resultget_short_spec_from_form_constraints (scripted)
# # For the time being we cache the parsed form_constraints. Without # caching, the proc takes 87 microseconds, with chaching, it is # significantly faster. # # via ns_cache {6.153537846215379 microseconds per iteration} # via nsv {3.865795920407959 microseconds per iteration} # set varname ::__xo_[ns_md5 $form_constraints] set dict "" if {![nsv_get parsed_fcs $varname dict]} { # # Not parsed yet # foreach name_and_spec $form_constraints { set p [string first : $name_and_spec] if {$p > -1} { dict set dict [string range $name_and_spec 0 $p-1] [string range $name_and_spec $p+1 end] } else { ad_log warning "get_short_spec_from_form_constraints: name_and_spec <$name_and_spec> is invalid" } } nsv_set parsed_fcs $varname $dict } if {[dict exists $dict $name]} { return [dict get $dict $name] } return ""Methods (to be applied on instances)
adp_subst (scripted)
# initialize template variables (in case, new variables are added to template) # and add extra variables from instance attributes set __ia [dict merge [:template_vars $content] ${:instance_attributes}] foreach var [dict keys $__ia] { #:log "-- set $var [list $__ia($var)]" # TODO: just for the lookup, whether a field is a richt text field, # there should be a more efficient and easier way... if {[string match "richtext*" [:get_field_type $var text]]} { # ignore the text/html info from htmlarea set value [lindex [dict get $__ia $var] 0] } else { set value [dict get $__ia $var] } # the value might not be from the form attributes (e.g. title), don't clear it. if {$value eq "" && [info exists :$var]} continue set :$var [:get_field_label $var $value] } nextcount_usages (scripted)
return [::xowiki::PageTemplate count_usages -package_id $package_id -parent_id $parent_id -item_id ${:item_id} -publish_status $publish_status]create_raw_form_field (scripted)
# # For workflows, we do not want to get the form constraints of the # page itself (i.e. the property of the generic workflow form) but # just the configured properties. Otherwise, we get for a wrong # results for e.g. "{{form-usages -form de:Thread.wf ...}}" which # picks up the label for the _title from the generic Workflow. # So, when we have configured properties, we use it, use the # primitive one just on despair. Not sure, what the best solution # is,... maybe an additional flag. # if { $omit_field_name_spec} { set short_spec "" } else { # # Get for the current page (self) the form-constraints and # return the spec for the specifiled name. # set short_spec [:get_short_spec -form_constraints $form_constraints $name] #:log "$name get_short_spec returns <$short_spec>" } #:log "$name '$name', spec '$spec' short_spec '$short_spec', slot=$slot" set spec_list [list] if {$spec ne ""} {lappend spec_list $spec} if {$short_spec ne ""} {lappend spec_list $short_spec} #:log "$name: composed spec '[join $spec_list ,]'" set f [next -name $name -slot $slot -spec [join $spec_list ,] -configuration $configuration -nls_language $nls_language ] #:log "created form-field '$name' $f [$f info class] validator=[$f validator] p=[$f info precedence]" return $fdemarshall (scripted)
# some older versions do not have anon_instances and no slots if {![info exists :anon_instances]} { set :anon_instances "f" } nextfield_names_from_form_constraints (scripted)
set form_constraints [:get_form_constraints] set result {} foreach name_and_spec $form_constraints { regexp {^([^:]+):} $name_and_spec _ name if {[string range $name 0 0] eq "@"} { # return no aggregated (pseudo) form field names continue } lappend result $name } return $resultget_field_label (scripted)
set short_spec [:get_short_spec $name] if {$short_spec ne ""} { set f [::xowiki::formfield::FormField new -volatile -name $name -spec $short_spec] if {![$f exists show_raw_value]} { set value [$f field_value $value] } } return $valueget_field_type (scripted)
#:log "--w" # get widget spec from folder (highest priority) set spec [:widget_spec_from_folder_object $name [${:page_template} set name]] if {$spec ne ""} { return $spec } # get widget spec from attribute definition set f [:create_raw_form_field -name $name -slot [:find_slot $name]] if {$f ne ""} { return [$f asWidgetSpec] } # use default widget spec return $default_specget_form (scripted)
# get the (HTML) form of the ::xowiki::PageTemplates/::xowiki::Form return [:get_html_from_content [:get_from_template form]]get_form_constraints (scripted)
# PageInstances have no form_constraints return ""get_from_template (scripted, public)
<instance of xowiki::PageInstance> get_from_template var \ [ default ]Get a property from the parent object (template). The parent object might by either an ::xowiki::Form or an ::xowiki::FormPage
- Parameters:
- var (required)
- default (optional)
- Returns:
- either the property value or a default value
- Testcases:
- create_form_with_form_instance
set form_obj [:get_template_object] #:msg "get $var from template form_obj=$form_obj [$form_obj info class]" # The resulting page should be either a Form (PageTemplate) or # a FormPage (PageInstance) # #:msg "parent of self ${:name} is [$form_obj name] type [$form_obj info class]" # # If it is as well a PageInstance, we find the information in the # properties of this page. Note that we cannot distinguish here between # intrinsic (starting with _) and extension variables, since get_from # template does not know about the logic with "_" (just "property" does). # if {[$form_obj istype ::xowiki::PageInstance]} { #:msg "returning property $var from parent formpage $form_obj => '[$form_obj property $var $default]'" return [$form_obj property $var $default] } # # .... otherwise, it should be an instance variable .... # if {[$form_obj exists $var]} { #:msg "returning parent instvar [$form_obj set $var]" return [$form_obj set $var] } # # .... or, we try to resolve it against a local property. # # This case is currently needed in the workflow case, where # e.g. anon_instances is tried to be fetched from the first form, # which might not contain it, if e.g. the first form is a plain # wiki page. # #:msg "resolve local property $var=>[:exists_property $var]" if {[:istype ::xowiki::FormPage] && [:exists_property $var]} { #:msg "returning local property [:property $var]" return [:property $var] } # # if everything fails, return the default. # #:msg "returning the default <$default>, parent is of type [$form_obj info class]" return $defaultget_short_spec (scripted)
# # In case, the form_constraints are provided, get the short-spec # from there, otherwise compute form_constraints via # method "get_form_constraints". # if {$form_constraints eq ""} { set form_constraints [:get_form_constraints] } if {$form_constraints ne ""} { set s [::xowiki::PageInstance get_short_spec_from_form_constraints -name $name -form_constraints $form_constraints] #:msg "get_short_spec $name c=$form_constraints => '$s'" return $s } return ""get_template_object (scripted)
set id ${:page_template} if {![nsf::is object ::$id]} { ::xo::db::CrClass get_instance_from_db -item_id $id } return ::$idinstance_attributes (setter)
mime_type (setter)
page_instance_id (setter)
page_template (setter)
render_content (scripted)
set html [:get_html_from_content [:get_from_template text]] set html [:adp_subst $html] # # Transitional code, should be removed after the release of # OpenACS 5.10: In case we have a folder instances without the # "description" field set, and we use the new folder.form, and the # update script was not yet executed, folders might appear as # empty. In these cases, call child-resources manually. # if {$html eq "" && [:is_folder_page]} { ad_log_deprecated "folder page without a content" "[:item_id] '${:name}'" set html [:include child-resources] } return "<div class='[${:page_template} css_class_name -margin_form false]'>[:substitute_markup $html]</div>"template_vars (scripted)
set result [list] foreach {_ _ v} [regexp -inline -all [template::adp_variable_regexp] $content] { lappend result $v "" } return $resultupdate (scripted)
::xo::dc transaction { next :instvar object_id page_template instance_attributes ::xo::dc dml update_xowiki_page_instance {update xowiki_page_instance set page_template = :page_template,instance_attributes = :instance_attributes where page_instance_id = :object_id } }widget_spec_from_folder_object (scripted)
# get the widget field specifications from the payload of the folder object # for a field with a specified name in a specified page template foreach {s widget_spec} [::${:package_id} get_parameter -check_query_parameter false WidgetSpecs] { lassign [split $s ,] template_name var_name #ns_log notice "--w template_name $template_name, given '$given_template_name' varname=$var_name name=$name" if {([string match $template_name $given_template_name] || $given_template_name eq "") && [string match $var_name $name]} { #ns_log notice "--w using $widget_spec for $name" return $widget_spec } } return ""www-use-template (scripted, public)
<instance of xowiki::PageInstance> www-use-templateThis web-callable method can be used to change the "template" of a PageInstance. The caller provides the "form" as query parameter which should be used in future for handling the instance parameters of the PageInstance. This method can be as well be used for changing the associated workflow of a workflow instance.
- Testcases:
- No testcase defined.
set formName [:query_parameter "form" ""] if {$formName eq ""} { error "no form specified" } ::${:package_id} get_lang_and_name -default_lang [::xo::cc lang] -path $formName lang stripped_url set d [::${:package_id} item_ref -default_lang $lang -parent_id [::${:package_id} folder_id] $formName] set item_id [dict get $d item_id] if {$item_id == 0} { error "cannot lookup page $formName" } ::xo::db::CrClass get_instance_from_db -item_id $item_id if {![nsf::is object ::$item_id] || "::xowiki::PageTemplate" ni [::$item_id info precedence]} { error "OK $formName is not suited to be used as template. Should be a Form!" } if {${:page_template} == $item_id} { :msg "old page_template $item_id is already the same as the new one" } else { set msg "change template_id ${:page_template} to $item_id" :page_template $item_id :save #:msg "ok $msg" } ::${:package_id} returnredirect [ad_return_url]
- Methods: All Methods Documented Methods Hide Methods
- Source: Display Source Hide Source
- Variables: Show Variables Hide Variables