Problem/Motivation

The concept of a weight comes up quite often in both config and content entity types.

It would be useful to have an interface & a trait for this, to standardize how this is done and save on boilerplate code.

This would be in the same vein as EntityPublishedInterface/EntityPublishedTrait.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3592384

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

joachim created an issue. See original summary.

Anonymous’s picture

Hey, I am a novice and was looking around to make my first ever open source contribution. Can I pick this one up? Thank you

avinash.jha’s picture

Assigned: Unassigned » avinash.jha

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

joachim’s picture

Looks good.

> public function getWeight(): ?int;

This should always be an int. If it's not set, we return 0 -- and the pattern in existing entities is that there is a default value of 0.

> public function setWeight(?int $weight): static;

No reason to set as NULL.

Docs for EntityWeightTrait should mention the interface and vice versa.

mildertechnologies’s picture

Assigned: avinash.jha » Unassigned

@joachim. will take care of it.. Thanks a lot for such speedy response!

longwave’s picture

Is there a core entity that we could convert here as a proof of concept?

mildertechnologies’s picture

Assigned: Unassigned » mildertechnologies
mildertechnologies’s picture

Hey @joachim 👋🏻
just made my MR and implemented the asked changes
Thank you

joachim’s picture

> Is there a core entity that we could convert here as a proof of concept?

There's taxonomy terms. But it would be good to do both a content and config entity for this.

joachim’s picture

@mildertechnologies are you using an LLM for this?

mildertechnologies’s picture

to understand the syntax and to get the context of the codebase yes. But, the concept and the use case is clear to me as to why this issue arose in the first place. Is there a reason as to why you are asking this?

Are you referring to the previous response of mine in the chat? If that is so.. then no. I typed it out myself.

joachim’s picture

Because of its impact on climate collapse, I refuse to review AI code. I'll happily guide and mentor contributors, especially newcomers, but I don't want anything to do with AI code.

mildertechnologies’s picture

I am more than happy to get the guidance of yours and make contributions to the project. Could you tell me how do we proceed from this point? I have dm'd you on slack too
Really looking forward to this
Thanks

joachim’s picture

I would recommend converting Term for content (shortcut is getting removed) and Block or Role for config.

The trait docs should maybe explain that the base field def is only useful for content entity types.

If there's AI involved in the code for the current MR, I am going to take a step back from this issue now.

kieran.cott made their first commit to this issue’s fork.

joachim’s picture

avpaderno’s picture

Title: add an interface & trait for entities with a weight » Add an interface and a trait for entities with a weight
Assigned: mildertechnologies » Unassigned
Parent issue: » #2980340: [meta] improve DX & documentation for entity type characteristics
avpaderno’s picture

(I apologize: I do not know from where the linked issue comes.)

joachim’s picture