You are here

function bootstrap_paragraphs_update_entity_from_yml in Bootstrap Paragraphs 8.2

Update entity from yml.

Some config like form display needs to be updated via config manager.

Parameters

string $ymlFileName: Yml file name.

string $entityType: The entity type for this storage.

mixed $id: The ID of the entity to load.

array $setComponents: Array of components you want to add.

  • The key will be what we are setting.
  • The value is the key that will be used from the new config file (Can have . in string for array).
3 calls to bootstrap_paragraphs_update_entity_from_yml()
bootstrap_paragraphs_update_8202 in ./bootstrap_paragraphs.install
Updates Accordion.
bootstrap_paragraphs_update_8203 in ./bootstrap_paragraphs.install
Updates Accordion View Display.
bootstrap_paragraphs_update_8204 in ./bootstrap_paragraphs.install
Adds Header field to top level bundles.

File

./bootstrap_paragraphs.install, line 75
Install, uninstall and update hooks for Bootstrap Paragraphs module.

Code

function bootstrap_paragraphs_update_entity_from_yml($ymlFileName, $entityType, $id, array $setComponents) {
  $bp_path = drupal_get_path('module', 'bootstrap_paragraphs');
  $yml = Yaml::parse(file_get_contents($bp_path . '/config/optional/' . $ymlFileName . '.yml'));
  $entity = \Drupal::entityTypeManager()
    ->getStorage($entityType)
    ->load($id);
  foreach ($setComponents as $key => $value) {
    $parts = explode('.', $value);
    if (count($parts) == 1) {
      $entity
        ->setComponent($key, $yml[$value]);
    }
    else {
      $value = NestedArray::getValue($yml, $parts);
      $entity
        ->setComponent($key, $value);
    }
  }
  $entity
    ->save();
}