You are here

public function WebformCliService::drush_webform_libraries_remove in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Commands/WebformCliService.php \Drupal\webform\Commands\WebformCliService::drush_webform_libraries_remove()

Implements drush_hook_COMMAND().

Overrides WebformCliServiceInterface::drush_webform_libraries_remove

1 call to WebformCliService::drush_webform_libraries_remove()
WebformCliService::drush_webform_libraries_download in src/Commands/WebformCliService.php
Implements drush_hook_COMMAND().

File

src/Commands/WebformCliService.php, line 794

Class

WebformCliService
Drush version agnostic commands.

Namespace

Drupal\webform\Commands

Code

public function drush_webform_libraries_remove($status = NULL) {
  $status = $status !== FALSE;
  if ($status) {
    $this
      ->drush_print($this
      ->dt('Beginning to remove libraries…'));
  }
  $removed = FALSE;

  /** @var \Drupal\webform\WebformLibrariesManagerInterface $libraries_manager */
  $libraries_manager = \Drupal::service('webform.libraries_manager');
  $libraries = $libraries_manager
    ->getLibraries();

  // Manually add deleted libraries, so that they will always be removed.
  $libraries['jquery.word-and-character-counter'] = 'jquery.word-and-character-counter';
  foreach ($libraries as $library_name => $library) {
    $library_path = '/libraries/' . $library_name;
    $library_exists = file_exists(DRUPAL_ROOT . $library_path) ? TRUE : FALSE;
    if ($library_exists) {
      $this
        ->drush_delete_dir(DRUPAL_ROOT . $library_path, TRUE);
      $removed = TRUE;
      if ($status) {
        $t_args = [
          '@name' => $library_name,
          '@path' => $library_path,
        ];
        $this
          ->drush_print($this
          ->dt('@name removed from @path…', $t_args));
      }
    }
  }
  if ($removed) {
    drupal_flush_all_caches();
  }
  return $removed;
}