You are here

function _conditional_fields_update_conditional_fields_settings in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 conditional_fields.install \_conditional_fields_update_conditional_fields_settings()

Updates conditional fields entity's settings.

Parameters

\Drupal\Core\Entity\Entity\EntityFormDisplayInterface $entity: Config entity to update.

1 call to _conditional_fields_update_conditional_fields_settings()
conditional_fields_update_8001 in ./conditional_fields.install
Removes unused configuration.

File

./conditional_fields.install, line 43
Conditional fields module's updates.

Code

function _conditional_fields_update_conditional_fields_settings(EntityFormDisplayInterface &$entity) {
  $needs_save = FALSE;
  foreach ($entity
    ->getComponents() as $key => $content) {
    if (empty($content['third_party_settings']['conditional_fields'])) {
      continue;
    }
    foreach ($content['third_party_settings']['conditional_fields'] as $cid => $condition) {
      foreach ($condition['settings'] as $settings_key => $value) {
        if (strpos($settings_key, 'element_') !== FALSE) {
          $needs_save = TRUE;
          unset($content['third_party_settings']['conditional_fields'][$cid]['settings'][$settings_key]);
        }
      }
    }
    $entity
      ->setComponent($key, $content);
  }
  if ($needs_save) {
    $entity
      ->save();
  }
}