- First commit to issue fork.
The method label()
of entities is abstract and does not (necessarily) correspond to one specific field. Some entity types have implemented a specific version of that method while taxonomy terms do have a corresponding field (name
) by default. Which is why those three expressions are basically identical:
$term->get('name')->value
$term->getName()
$term->label()
Please correct me if I'm wrong but I think that the method label()
is not supposed to change any actual functionality. It is there to show a string representation of that entity. Nothing else.
In a project I needed that string representation to be different for taxonomy terms, so I changed the method label()
(by using my own class for taxonomy terms). Now here is what happened. As soon as I saved a taxonomy term, the field name
was lost and instead the output of the label()
method was saved in that field.
After debugging this for a bit, I found that the method getName()
was using the method label()
instead of fetching the content of the field name
directly. I assume that the method getName()
is used when a term is saved to fetch the current value of the name
field, but I don't think that we should rely on the label()
method returning that field. If we do, why even have a label()
method in the first place? As soon as we change it, the name field is not usable anymore. At least not manually. It will always hold a copy of the label()
result.
label()
for your taxonomy terms
label()
name
has changedI don't think that the method getName()
should be using the method label()
. Instead it should return the name of the taxonomy term, just as the method name suggests: return this->get('name')->value;
.
I would like to hear your thoughts and please correct me if I misunderstood anything.
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.