Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |
development:architecture:record_data_formatter [2023/11/17 19:11] – [Option 1: Use Configuration] demiankatz | development:architecture:record_data_formatter [2023/12/11 16:11] (current) – [Option 2: Override the Factory] Add example of re-ordering spec array dltj |
---|
==== Option 2: Override the Factory ==== | ==== Option 2: 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/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. | 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. As an example of array manipulation, this code moves the next and previous titles after the "Language" field. |
| |
| <code PHP> |
| class RecordDataFormatterFactory extends \VuFind\View\Helper\Root\RecordDataFormatterFactory |
| { |
| public function getDefaultCoreSpecs() |
| { |
| $spec = new SpecBuilder(parent::getDefaultCoreSpecs()); |
| $specArray = $spec->getArray(); |
| $specArray['New Title']['pos'] = $specArray['Language']['pos'] + 10; |
| $specArray['Previous Title']['pos'] = $specArray['Language']['pos'] + 20; |
| return $specArray; |
| } |
| } |
| </code> |
| |
| In the parent::getDefaultCoreSpecs() code, items are added to the array with 'pos' values automatically assigned in increments of 100 unless explicitly specified. To reorder values or put new fields between existing fields, you can add items with explicit 'pos' values and rely on the re-sorting of the array to display items as desired. |
==== Option 3: Override the Template ==== | ==== Option 3: Override the Template ==== |
| |