Problem/Motivation
During implementing a MediaType for https://www.drupal.org/project/riddle_marketplace, i discovered two problems in these if clause:
if ($this->hasField($destination_field) && $this->{$destination_field}->isEmpty() && ($value = $this->getType()->getField($this, $source_field))) {
$this->set($destination_field, $value);
}
Riddle gives me a publishing status, so i wanted to map that to the media status field. First problem is, that it seems that base fields are never empty at this point. So it's not possible to map any base fields.
Second problem, the publishing status is a boolean. So if my riddle is unpublished the $value becomes FALSE and that means i am not able to set the field value, too.
Proposed resolution
1. problem: I took a look at the media core patch and found the sourceFieldChanged() method. I would like to implement it here, but return TRUE when there is no $original variable.
2. problem: Checking if $value is !== NULL
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | field_mapping_not-2855630-2.patch | 746 bytes | chr.fritsch |
Comments
Comment #2
chr.fritschWe decided not to introduce the new sourceFieldChanged() method, because we don't want to change the current behavior. Instead of that i now check if the entity isNew
Comment #3
berdirThis mapping stuff also came up in the core issue and we added a method for it on the plugins I think, lets make sure use cases like this can be supported in core too :)
Comment #4
slashrsm commentedThis is more of a feature request. This part was designed to work this was and it seems that we've hit its limits.
As @berdir already mentioned it is currently our priority to make #2831274: Bring Media entity module to core as Media module happen and we should make sure that all problems that we know about are addressed there.
#2 breaks BC in my opinion which we can't do in the current state of the contrib media entity.
Comment #5
chr.fritschCould you explain why it breaks BC?
Comment #6
slashrsm commented#2862467: Add complex field mapping to media module should fix this in core. Thoughts?