taxonomy_ordinal
The module provides a field type that creates a stable index from the hierarchical structure of taxonomy vocabularies. It can be used for sorting in views and creates a unique numbered, stable reference index that can be displayed in multiple configurable lengths and styles. E.g.
- Chapter IV, Section 12.3, Article A
- Ch. IV, Sec. 12.3, Art. A
- IV-12.3, A
It is smart, lightweight and powerful. Entities of any types (e.g. Nodes) can be integrated in this address structure if they refer to taxonomy terms of an enabled vocabulary, just by adding the provided field type.
Use cases:
Structured content collections, which should have stable referencing, e.g. for citation. Such as:
- Contracts (as it is built for the RulesFinder distribution)
- Scientific papers
- Books
- Directories
Features
- Unique index numbers: When you save a term or entity, you won't be able to give the same index number twice.
- Stable index numbers: When you delete a term or entity the subsequent entities do not move up automatically, so the indexing remains stable. (Important for citation references in other texts)
- All automated changes of weight (= ordinal number) is suppressed.
- Full customizable (multi-level) index formats.
- When you change the parent term (of a term or the refering entity) the index is reset to zero (= disabled)
REQUIREMENTS
Cores Taxonomy module
INSTALLATION
Install as you would normally install a contributed Drupal module.
See: https://www.drupal.org/node/895232 for further information.
CONFIGURATION
- If you have no Taxonomy Vocabulary yet, go to
/admin/structure/taxonomyand add a new one. And add some terms in a nested structure to see the effects of the Taxonomy Ordinal module. - If you have enabled the module go to
/admin/config/content/taxonomy-ordinalor in the menu [Configuration => Content authoring => Taxonomy Ordinal] - Enable the taxonomy vocabulary that you want to use to structure your content. And click "Save configuration".
- Clear the cache (full)
- Go to the enabled vocabulary config page: e.g.
/admin/structure/taxonomy/manage/{sections}where{sections}is the id of your vocab. - Here you should see a new section "Taxonomy Ordinal" where you can edit the string formatters. In the string formatters special chars are used:
- Pipe '|' to separate the term (parent/children) levels. (You don't need to configure all levels. When no formatter is present for deeper levels, the ordinal number is appended with a leading dot '.')
- Placeholder '%on' where the ordinal number is injected.
- IMPORTANT: You must save the config at least once, even when you are ok with the default values, because they have not been written into the third party settings of the section.
- Now move to the "Manage display" tab of your vocabulary.
- Move the Field "Ordinal number" (the (formerly hidden) "weight" field) into the visible region. Click the gear to adjust the display style. (Repeat this for every view mode, where you want to display the field.)
- When everything is saved, the taxonomy terms should now display an ordinal structure and you can modify their ordinal number in the terms edit form in the section "Relation".
Now we want to extend the structure upon nodes (or other entities) that refer to the terms.
- Open the "Manage Fields" section of your node type
/admin/structure/types/manage/{article}/fieldswhere{article}is the placeholder for your node bundle. - If you have no entity reference field here, that refers to terms of the vocabulary above, then add one. It should have a cardinality of "1" (not multiple values).
- Add also a new field "Taxonomy Ordinal".
- In the field settings of the new taxonomy_ordinal field you have to select in the setting "taxonomy" the entity_reference field from above, that refers to terms of the vocabulary we enabled above.
- Then configure the formatters as we did for the taxonomy vocabulary above. Good example values are:
- Number format: 'abc'
- Item formatter: '(%on)'
- Short/Medium/Long formatter: ', (%on)' The leading comma is because it will be appended to the taxonomy path.
- Now go the manage display tab of your node type and configure the view modes. For each view mode move ordinal number field to visible and select the formatter options, as we already did for the taxonomy terms.
Now you can walk through all entities and set ordinial numbers. Set ordinal number to 0 to disable/skip numbering for the entity, you will see a hash char '#' instead.
HOW IT WORKS
Only for developers or interested: The taxonomy ordinal field is just a weight field, where a primitive integer is saved. (For taxonomy terms we even used the original weight field and changed the label of the field to "Ordinal number" and limited the range of values to 0 <= w <= 999.) The formatted address is just the output of the field formatter. Whenever the field is called to be displayed (e.g. in an entity view mode) the (referenced) term is looked up and a kind of IP-address is built from its weight and the weight from its parents:
2.3.1 => for terms
2.3.1:4 => for nodes (or other entities)The '2.3.1' part is the term address where
- '2' is the weight from the root term
- '3' the weight from the 2nd level term
- '1' is the weight of the current (referenced) term
- '4' (divided by a colon ':') is the node (or entity) weight and will be handled different.
From here we parse the address through different string formatters, that are stored in the config (for terms in the vocabulary settings, for all other entities in the field settings).
- Number parser: for each term level and each entity field you can select the index format ('123', 'abc', 'ABC', 'iii', 'III' or greek 'αβγ', 'ΑΒΓ')
- Label parser: String formatter to embed the indexes into a readable address format e.g. 'Chap. 2, sec. C, para. I, art. a'. In the formatter you can select between four different (full customizable) display modes:
- item (without taxonomy path, e.g. for lists: e.g. 'article a', or 'para. 2')
- short (e.g. '2.C-I, a')
- medium (e.g. 'Chap. 2, sec. C, para. I, art. a')
- long (e.g. 'Chapter 2, section C, paragraph I, article a')
KNOWN ISSUES
For vocabularies enabled in "Taxonomy Ordinal":
- We overwrite the vocabulary form handler. If another module is doing the same thing there will be a conflict. You might not see the "Taxonomy Ordinal" block for the formatters. (Please write a ticket and inform us about conflicting modules)
- From the taxonomy term LIST, we removed the weight column, the drag&drop behavior and suppressed all changes of the weight field initiated from here, because it destroys the ordinal structure. The weight field can only be edited in the term edit form.