Skip to content

Instantly share code, notes, and snippets.

@nikunjkotecha
Created October 6, 2017 05:39
Show Gist options
  • Select an option

  • Save nikunjkotecha/1484f2be23b7a5e4a92a7ec71bb25fed to your computer and use it in GitHub Desktop.

Select an option

Save nikunjkotecha/1484f2be23b7a5e4a92a7ec71bb25fed to your computer and use it in GitHub Desktop.
Example to demonstrate how to update field config in update hooks.
<?php
/**
* @file
* Contains install, update, uninstall hooks for module.
*/
use Drupal\field\Entity\FieldConfig;
/**
* Implements hook_update_N().
*
* Enable translation for field_x field in vocabulary.
*/
function module_update_8001() {
$config = \Drupal::configFactory()->getEditable('field.field.taxonomy_term.vocabulary.field_x');
$config->set('translatable', TRUE);
$config->save();
$field = FieldConfig::loadByName('taxonomy_term', 'vocabulary', 'field_x');
$field->setTranslatable(TRUE);
$field->save();
}
@nikunjkotecha

Copy link
Copy Markdown
Author

Yep, thanks @purushotamrai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment