Skip to content

Instantly share code, notes, and snippets.

@lkacenja
Created September 21, 2018 14:21
Show Gist options
  • Save lkacenja/94d7587f3f154cc67a170260c8c26b84 to your computer and use it in GitHub Desktop.
Save lkacenja/94d7587f3f154cc67a170260c8c26b84 to your computer and use it in GitHub Desktop.
Update a basefield definition for an existing entity.
<?php
use Drupal\Core\Field\BaseFieldDefinition;
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$field_storage_definition = $definition_manager->getFieldStorageDefinition('alternate_payment', 'spending_request');
// IF THIS IS UPDATING AN EXISTING FIELD
// $definition_manager->uninstallFieldStorageDefinition($field_storage_definition);
$new_field = BaseFieldDefinition::create('integer')
->setLabel(t('Alternate Payment'))
->setDescription(t('Track spending requests that do not have internal payments.'))
->setDisplayOptions('view', [
'label' => 'hidden',
'type' => 'number_integer',
'weight' => 0,
])
->setDisplayOptions('form', [
'type' => 'number',
'weight' => 0,
])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE);
$definition_manager->installFieldStorageDefinition('alternate_payment', 'spending_request', 'spending_request', $new_field );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment