You are here

function external_link_popup_update_8105 in External Link Pop-up 8

Update domains list format.

File

./external_link_popup.install, line 44
Contains external_link_popup installation and upgrade actions.

Code

function external_link_popup_update_8105() {
  $config = \Drupal::configFactory()
    ->getEditable('external_link_popup.settings');
  if ($whitelist = $config
    ->get('whitelist')) {
    $chunks = preg_split('/\\s*,\\s*|\\s+/', trim($whitelist));
    $config
      ->set('whitelist', implode("\n", $chunks))
      ->save();
  }
  $entities = \Drupal::entityTypeManager()
    ->getStorage('external_link_popup')
    ->loadMultiple();

  /* @var $entity \Drupal\external_link_popup\Entity\ExternalLinkPopup */
  foreach ($entities as $entity) {
    if ($domains = $entity
      ->getDomains()) {
      $chunks = preg_split('/\\s*,\\s*|\\s+/', trim($domains));
      $entity
        ->setDomains(implode("\n", $chunks))
        ->save();
    }
  }
}