Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Drupal 8: Update allowed values of a select field
<?php
/**
* Update allowed values of background color field.
*/
function MODULENAME_update_8001(&$sandbox) {
// Load the field.
$field_config = FieldStorageConfig::loadByName('node', 'field_card_view_background_color');
// Update the allowed values on it.
$field_config->setSetting('allowed_values', [
['value' => 'teal', 'label' => 'Teal'],
['value' => 'orange', 'label' => 'Orange'],
['value' => 'blue-light', 'label' => 'Light Blue'],
['value' => 'purple', 'label' => 'Purple'],
]);
// Re-save it.
$field_config->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment