You are here

function thunder_update_8123 in Thunder 8.2

Remove the old paragraph split text solution.

File

./thunder.install, line 872
Install, update and uninstall functions for the thunder installation profile.

Code

function thunder_update_8123() {

  /** @var \Drupal\update_helper\Updater $updater */
  $updater = \Drupal::service('update_helper.updater');
  $updateLogger = $updater
    ->logger();

  /** @var \Drupal\Core\Config\ConfigFactoryInterface $configFactory */
  $configFactory = \Drupal::configFactory();

  /** @var \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler */
  $moduleHandler = \Drupal::moduleHandler();

  // Flag to keep status of update.
  $successful = TRUE;

  // We are disabling old split text plugin and uninstall split text module
  // since split text feature will be used from paragraphs_features module.
  $config = $configFactory
    ->getEditable('editor.editor.basic_html');
  if ($config) {
    $items = $config
      ->get('settings.toolbar.rows.0');
    if (!empty($items) && is_array($items)) {
      $last_item =& $items[count($items) - 1];
      if (!empty($last_item['name']) && $last_item['name'] === 'Tools' && ($split_text_index = array_search('SplitTextBefore', $last_item['items'])) !== FALSE) {
        array_splice($last_item['items'], $split_text_index, 1);
        $config
          ->set('settings.toolbar.rows.0', $items)
          ->save();
        $updateLogger
          ->info('Split before option is successfully removed from Basic HTML Editor.');
      }
      else {
        $updateLogger
          ->info('Update did not found split before option for Basic HTML Editor.');
      }
    }
    else {
      $updateLogger
        ->info('Update did not found split before option for Basic HTML Editor.');
    }
  }
  else {
    $updateLogger
      ->warning('Basic HTML Editor configuration is not available.');
  }

  // Uninstall paragraph_split_text module.
  if ($moduleHandler
    ->moduleExists('paragraph_split_text')) {

    /** @var \Drupal\Core\Extension\ModuleInstallerInterface $moduleInstaller */
    $moduleInstaller = \Drupal::service('module_installer');
    if ($moduleInstaller
      ->uninstall([
      'paragraph_split_text',
    ])) {
      $updateLogger
        ->info('Module "paragraph_split_text" is successfully removed.');
    }
    else {
      $updateLogger
        ->warning('Module "paragraph_split_text" is not removed.');
      $successful = FALSE;
    }
  }
  else {
    $updateLogger
      ->info('Module "paragraph_split_text" is not installed. Nothing to uninstall.');
  }

  // Update should be marked as successful only if all steps are successful.
  _thunder_mark_update_checklist('thunder__thunder_update_8123', $successful, $updateLogger);

  // Output logged messages to related chanel of update execution.
  return $updateLogger
    ->output();
}