Problem/Motivation
Taxonomy vocabularies have a weight property, but there is no dedicated accessor for it defined in VocabularyInterface. $vocabulary->get('weight') works fine, but the lack of a getWeight() method is kind of jarring considering how virtually all entities have dedicated accessors for important properties.
Proposed Resolution
Add a getWeight() method to VocabularyInterface.
Remaining Tasks
Patch, test, review, commit, much rejoicing.
API Changes
Adds a getWeight() method to taxonomy vocabulary entities.
UI Changes
None.
| Comment | File | Size | Author |
|---|
Issue fork drupal-2495191
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #1
MarinkoIg commentedComment #2
MarinkoIg commentedAssigned to me.
Comment #3
MarinkoIg commentedI'm not sure that this attached patch is good solution.
Comment #4
phenaproximaShould be
$this->get('weight'), but otherwise looks correct to me.Comment #5
MarinkoIg commentedI added some changes..
Comment #6
thenchev commentedAs far as i can tell from the issue description you didn't had to add a setter. Maybe we need one?
Also if you are not sure about that return $this does look at this:
http://stackoverflow.com/questions/5956999/what-does-return-this-mean
It makes it so you can concatenate methods.
The other thing that you should do is you need to look in code in drupal everywhere the
$vocabulary->get('weight') is used and replace it with yours. Ides should have tools to search trough code and find where it its used
Comment #7
MarinkoIg commentedI changed..
Comment #10
MarinkoIg commentedComment #11
phenaproximaFirst-class.
Comment #12
miro_dietikerYeah, looks fine for me too.
Comment #15
miro_dietikerBack to original state. The test fail seem to have been random.
Comment #16
alexpottWe didn't implement methods for properties that had no runtime use-case. If we have a runtime use case then we should at it - atm this patch is only adding test-time usages.
Comment #23
andypostMeanwhile looks that weight of vocabularies are not used at all, so probably instead of interface extension better to remove weight from vocabularies.
In 4 years after conversion there was no reports about removal of sorting #1821274: Add back ability to sort on vocabulary weight and name
The only place where vocabulary weight was used was ordering of terms in term ref field #7684: Order taxonomy terms by vocabulary weight, then term weight
So I filed #3008064: Deprecate vocabulary weight property
Comment #36
jibranI have gone through all three issues: this one, #3008064: Deprecate vocabulary weight property, and #1821274: Add back ability to sort on vocabulary weight and name.
Re #16: At the time, that objection made sense, but now #1821274: Add back ability to sort on vocabulary weight and name is exactly that runtime use case:
TaxonomyIndexTid::valueForm()needs to sort terms by their vocabulary's weight, and doing that cleanly needs a propergetWeight()accessor rather than reaching into->get('weight')directly.So created a new MR https://git.drupalcode.org/project/drupal/-/merge_requests/16593.
Comment #37
smustgrave commentedLeft small comments on the MR.