When creating a new item and finally saving the item, neither the alias attributes nor the combined values attributes get generated.
The item gets initialized with $arrData = [] meaning we have to initialize all attributes so that they are present in the data array. This is related to #894 and 588eddf respectively.
When $arrData is empty, isAttributeSet() returns false which results in no attributes get notified about a model change.
Using the API
$item = new Item($metaModel, null);
$item->set('name', 'Test');
$item->save();
// neither alias nor combined values have been generated now
Using the Frontend Editing. Neither alias nor combined values are generated on creation.
MetaModels 2.0 as well 2.1 are affected.
We might want to add a getEmptyValue() to the IAttribute.
@authors in touched PHP files@baumannsven has had the same idea.
na dann... ;-)
@richardhj Please add author
@richardhj If this pull request merged can I remove the step 2 by the create handler from DCG. Can you test it, and give me information about this?
The problem I see with this is, now it is implicitly mandatory for all attributes to accept null as valid value where as it was simply "not there" before.
I wonder if this might cause problems.
For your addition of getEmptyValue() to the attributes, I'd rather not bloat the interfaces more but introduce a new interface for these cases. We also want to split up the monolithic attribute classes and interfaces on our route to 3.0, where adding new features to the current (and then deprecated) interfaces would do more harm than benefit.
The problem I see with this is, now it is implicitly mandatory for all attributes to accept null as valid value where as it was simply "not there" before.
Wow, didn't know there is something more null than null :-D
But I get your point. Because they now get triggered to process null whereas they might not have been called.
I wonder if this might cause problems.
Just now, e.g. the valueToWidget() method of the select attribute does not check for empty value. This is what you ment, right?
For your addition of getEmptyValue() to the attributes, I'd rather not bloat the interfaces more but introduce a new interface for these cases. We also want to split up the monolithic attribute classes and interfaces on our route to 3.0, where adding new features to the current (and then deprecated) interfaces would do more harm than benefit.
Yes, we should discuss the desired interfaces somewhen.
On the other hand, using $item->set('name', null); have been a valid way to unset a value.
@baumannsven The Two-step-save can be reverted. See contao-community-alliance/dc-general#425.
I reverted the two-step save and applied these changes. The alias/combinedvalues are working.