About Features Downloads Getting Started Documentation Events Support GitHub

Love VuFind®? Consider becoming a financial supporter. Your support helps build a better VuFind®!

Site Tools


Warning: This page has not been updated in over over a year and may be outdated or deprecated.
development:architecture:record_data_formatter

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
development:architecture:record_data_formatter [2018/05/09 13:36] – [Specification Array] demiankatzdevelopment:architecture:record_data_formatter [2020/09/22 14:19] demiankatz
Line 32: Line 32:
 | multiFunction | optional | The callback required when renderType = Multi. Accepts three parameters: 1.) raw input data, 2.) the options array from the spec, 3.) the record driver object. Outputs an array of associative arrays with the following keys: **label**: Label to display; **values**: Values to render; **options**: Rendering options (may include renderType, pos, and any other relevant parameters; they will be applied only to the current grouping of data; any options not set here will be inherited from the spec array). | | multiFunction | optional | The callback required when renderType = Multi. Accepts three parameters: 1.) raw input data, 2.) the options array from the spec, 3.) the record driver object. Outputs an array of associative arrays with the following keys: **label**: Label to display; **values**: Values to render; **options**: Rendering options (may include renderType, pos, and any other relevant parameters; they will be applied only to the current grouping of data; any options not set here will be inherited from the spec array). |
 | multiRenderType | optional | The default type of rendering to apply to each of the sets of values returned by the multiFunction (optional, defaults to Simple, may be overridden by options specified by your multiFunction). | | multiRenderType | optional | The default type of rendering to apply to each of the sets of values returned by the multiFunction (optional, defaults to Simple, may be overridden by options specified by your multiFunction). |
-| prefix | optional | HTML to prepend to the output generated by the view helper. Applies only when RenderType = Simple. |+| itemPrefix | optional | HTML to prepend to each value formatted by the view helper. Use prefix instead if you want to prepend a single value to the whole set of data assembled by the view helper. Applies only when RenderType = Simple. :!: // Introduced in VuFind 7.0. // | 
 +| prefix | optional | HTML to prepend to the output generated by the view helper. This is applied once before the full set of values; use itemPrefix if you want to prepend something to each individual value. Applies only when RenderType = Simple. |
 | recordLink | optional | The type of link (from the Record view helper's getLink method) to associate with each value in the raw field data. Applies only when RenderType = Simple. | | recordLink | optional | The type of link (from the Record view helper's getLink method) to associate with each value in the raw field data. Applies only when RenderType = Simple. |
 | separator | optional (default = <nowiki><br /></nowiki>) | Separator to use between multiple data values. Applies only when RenderType = Simple. | | separator | optional (default = <nowiki><br /></nowiki>) | Separator to use between multiple data values. Applies only when RenderType = Simple. |
-| suffix | optional | HTML to append to the output generated by the view helper. Applies only when RenderType = Simple. |+| itemSuffix | optional | HTML to append to each value formatted by the view helper. Use suffix instead if you want to append a single value to the whole set of data assembled by the view helper. Applies only when RenderType = Simple. :!: // Introduced in VuFind 7.0. // | 
 +| suffix | optional | HTML to append to the output generated by the view helper. This is applied once after the full set of values; use itemSuffix if you want to append something to each individual value. Applies only when RenderType = Simple. |
 | template | optional | The name of the template to render, when renderType = RecordDriverTemplate | | template | optional | The name of the template to render, when renderType = RecordDriverTemplate |
 | translate | optional (default = false) | Should we run raw field data through the translator? Applies only when RenderType = Simple. | | translate | optional (default = false) | Should we run raw field data through the translator? Applies only when RenderType = Simple. |
Line 43: Line 45:
 ===== The Specification Builder ===== ===== The Specification Builder =====
  
-A [[https://github.com/vufind-org/vufind/blob/master/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter/SpecBuilder.php|SpecBuilder]] convenience class has been provided to help generate specification arrays. This handles such functionality as auto-generating useful 'pos' values, reordering/overriding fields, etc.+A [[https://github.com/vufind-org/vufind/blob/dev/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatter/SpecBuilder.php|SpecBuilder]] convenience class has been provided to help generate specification arrays. This handles such functionality as auto-generating useful 'pos' values, reordering/overriding fields, etc.
  
 Useful public methods: Useful public methods:
  
   * setLine($key, $dataMethod, $renderType = null, $options = []) - add a configuration for $key; defaults to 'Simple' $renderType   * setLine($key, $dataMethod, $renderType = null, $options = []) - add a configuration for $key; defaults to 'Simple' $renderType
 +  * setMultiLine($key, $dataMethod, $callback, $options = []) - add a multi-function-based configuration for $key; convenience method wrapped around setLine()
   * setTemplateLine($key, $dataMethod, $template, $options = []) - add a template-based configuration for $key; convenience method wrapped around setLine()   * setTemplateLine($key, $dataMethod, $template, $options = []) - add a template-based configuration for $key; convenience method wrapped around setLine()
   * reorderKeys($orderedKeys, $defaultPos = null) - reorder the items within the configuration based on an ordered array of key names   * reorderKeys($orderedKeys, $defaultPos = null) - reorder the items within the configuration based on an ordered array of key names
Line 56: Line 59:
 ==== Option 1: Override the Factory ==== ==== Option 1: Override the Factory ====
  
-If you want to make global changes to a specification, the easiest solution is to extend [[https://github.com/vufind-org/vufind/blob/master/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatterFactory.php|\VuFind\View\Helper\Root\RecordDataFormatterFactory]] in your own [[development:architecture:customizing_vufind#modules|custom module]] and override getDefaultCoreSpecs() and/or getDefaultDescriptionSpecs() as needed. You can either completely rewrite the spec generation logic, or you can call the parent version of the function and then manipulate the array slightly to add, remove or reorder fields.+If you want to make global changes to a specification, the easiest solution is to extend [[https://github.com/vufind-org/vufind/blob/dev/module/VuFind/src/VuFind/View/Helper/Root/RecordDataFormatterFactory.php|\VuFind\View\Helper\Root\RecordDataFormatterFactory]] in your own [[development:architecture:customizing_vufind#modules|custom module]] and override getDefaultCoreSpecs() and/or getDefaultDescriptionSpecs() as needed. You can either completely rewrite the spec generation logic, or you can call the parent version of the function and then manipulate the array slightly to add, remove or reorder fields.
  
 ==== Option 2: Override the Template ==== ==== Option 2: Override the Template ====
development/architecture/record_data_formatter.txt · Last modified: 2023/12/11 16:11 by dltj