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.

Issue fork drupal-2495191

Command icon 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

MarinkoIg’s picture

Assigned: Unassigned » MarinkoIg
MarinkoIg’s picture

Assigned to me.

MarinkoIg’s picture

I'm not sure that this attached patch is good solution.

phenaproxima’s picture

Status: Active » Needs work
+++ b/core/modules/taxonomy/src/Entity/Vocabulary.php
@@ -125,6 +125,13 @@ public function getDescription() {
+  public function getWeight() {
+    return $this->weight;
+  }

Should be $this->get('weight'), but otherwise looks correct to me.

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new1.16 KB
new1.43 KB

I added some changes..

thenchev’s picture

+  /**
+   * {@inheritdoc}
+   */
+  public function setWeight($weight) {
+    $this->set('weight', $weight);
+    return $this;
   }

As 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

MarinkoIg’s picture

StatusFileSize
new3.11 KB
new3.06 KB

I changed..

Status: Needs review » Needs work

The last submitted patch, 7: 2495191-7.patch, failed testing.

The last submitted patch, 7: 2495191-7.patch, failed testing.

MarinkoIg’s picture

Status: Needs work » Needs review
StatusFileSize
new2.99 KB
new825 bytes
phenaproxima’s picture

Status: Needs review » Reviewed & tested by the community

First-class.

miro_dietiker’s picture

Yeah, looks fine for me too.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 10: 2495191-10.patch, failed testing.

phenaproxima queued 10: 2495191-10.patch for re-testing.

miro_dietiker’s picture

Status: Needs work » Reviewed & tested by the community

Back to original state. The test fail seem to have been random.

alexpott’s picture

Version: 8.0.x-dev » 8.1.x-dev
Status: Reviewed & tested by the community » Postponed
Issue tags: +minor version target

We 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.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

Meanwhile 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

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

jibran made their first commit to this issue’s fork.

jibran’s picture

Status: Needs work » Needs review

I 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 proper getWeight() accessor rather than reaching into ->get('weight') directly.

So created a new MR https://git.drupalcode.org/project/drupal/-/merge_requests/16593.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs subsystem maintainer review, +Needs change record

Left small comments on the MR.