What is the proper way to override field type config stored in database?
Created 7 years ago by mattcdavis1

Specifically, i am trying to override the related config value for the file and files field types. Initially i though i could do this via addon:publish anomaly.field_type.files but it appears as though the related value is coming from the database config field. Is there a way to override this apart from modifying the database value? What is the proper approach for this? The specific area of code that i want to override is below (I want to use my file model which extends anomaly file model):

     * Get the relation.
     * @return BelongsToMany
    public function getRelation()
        $entry = $this->getEntry();

        return $entry->belongsToMany(
            array_get($this->config, 'related', 'Anomaly\FilesModule\File\FileModel'),
        )->orderBy($this->getPivotTableName() . '.sort_order', 'ASC');
fryiee  —  7 years ago

Is this a field you are creating in the GUI or through a stream migration? Or do you mean replacing it completely when it is used in the files module?

If it's a stream migration you can just set a related key in the field type config and it should pick it up. If that doesn't work then it looks like you'll need to open a PR on that to replace the raw $this->config call with $this->getConfig(). In terms of replacing it completely, you may have to come up with some way to bind your FileModel to the existing one.

mattcdavis1  —  7 years ago

@fryiee - the field was created via the Streams Module rather than a migration. Looking at the existing config, it doesn't appear as though any of those values are getting picked up but i can still check and see if it picks up my value on a new assignment. I'll post back if that works.