function BaseFieldDefinition::setSettings

Same name in other branches
  1. 9 core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::setSettings()
  2. 10 core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::setSettings()
  3. 11.x core/lib/Drupal/Core/Field/BaseFieldDefinition.php \Drupal\Core\Field\BaseFieldDefinition::setSettings()

Note that the method does not unset existing settings not specified in the incoming $settings array.

For example:

// Given these are the default settings.
$field_definition->getSettings() === [
    'fruit' => 'apple',
    'season' => 'summer',
];
// Change only the 'fruit' setting.
$field_definition->setSettings([
    'fruit' => 'banana',
]);
// The 'season' setting persists unchanged.
$field_definition->getSettings() === [
    'fruit' => 'banana',
    'season' => 'summer',
];

For clarity, it is preferred to use setSetting() if not all available settings are supplied.

Overrides DataDefinition::setSettings

File

core/lib/Drupal/Core/Field/BaseFieldDefinition.php, line 167

Class

BaseFieldDefinition
A class for defining entity fields.

Namespace

Drupal\Core\Field

Code

public function setSettings(array $settings) {
    // Assign settings individually, in order to keep the current values
    // of settings not specified in $settings.
    foreach ($settings as $setting_name => $setting) {
        $this->getItemDefinition()
            ->setSetting($setting_name, $setting);
    }
    return $this;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.