Skip to content

Instantly share code, notes, and snippets.

@crittermike
Created June 7, 2020 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crittermike/88d94330c8f0f36c5ba323d1bbd72d23 to your computer and use it in GitHub Desktop.
Save crittermike/88d94330c8f0f36c5ba323d1bbd72d23 to your computer and use it in GitHub Desktop.
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