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

CommentFileSizeAuthor
#2 field_mapping_not-2855630-2.patch746 byteschr.fritsch

Comments

chr.fritsch created an issue. See original summary.

chr.fritsch’s picture

Status: Active » Needs review
StatusFileSize
new746 bytes

We 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

berdir’s picture

This 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 :)

slashrsm’s picture

Category: Bug report » Feature request
Status: Needs review » Needs work
Issue tags: +D8Media

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

chr.fritsch’s picture

Could you explain why it breaks BC?

slashrsm’s picture