1

I see the following in BaseRelationField:

public function settingsAttributes(): array
{
    $attributes = parent::settingsAttributes();
    $attributes[] = 'sources';
    $attributes[] = 'source';
    $attributes[] = 'targetSiteId';
    $attributes[] = 'viewMode';
    $attributes[] = 'limit';
    $attributes[] = 'selectionLabel';
    $attributes[] = 'localizeRelations';

    return $attributes;
}

The comments for the properties say:

   /**
     * @var string|string[]|null The source keys that this field can relate elements from (used if [[allowMultipleSources]] is set to true)
     */
    public $sources = '*';

    /**
     * @var string|null The source key that this field can relate elements from (used if [[allowMultipleSources]] is set to false)
     */
    public $source;

In the case of the single source. What would that string look like? What is that string referring to? A table name? In ID in a particular table?

Looks like the BaseRelationField is extended by Entries field and Users field and the sources are Entry structures and Administration groups respectively. If I wanted to set one as s static value what would that be?

1

In case of the element type Asset sources are the available volumes. In case of Category the available sources are the different groups. Sources for Entry are your sections, Tag have the different sets/groups as well.

It contains an array or the type section, folder, group and the ID of the corresponding model, separated with an :

You can just do

$field = Craft::$app->getFields()->getFieldById(>>your field id<<);
Craft::dd($field->sources);

to get to know how it looks like. It could be like this:

array(1) {
  [0]=> string(10) "section:16"
  [1]=> string(10) "section:18"
}

or for an Asset

array(1) {
  [0]=> string(8) "folder:1"
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.