You are here

class PurgeConfigurationsConfirmForm in Easy Install 8.6

Same name and namespace in other branches
  1. 8.9 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm
  2. 8.10 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm
  3. 8.5 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm
  4. 8.7 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm
  5. 8.8 src/Form/PurgeConfigurationsConfirmForm.php \Drupal\easy_install\Form\PurgeConfigurationsConfirmForm

Builds a confirmation form to uninstall selected modules.

Hierarchy

Expanded class hierarchy of PurgeConfigurationsConfirmForm

1 string reference to 'PurgeConfigurationsConfirmForm'
easy_install.routing.yml in ./easy_install.routing.yml
easy_install.routing.yml

File

src/Form/PurgeConfigurationsConfirmForm.php, line 18

Namespace

Drupal\easy_install\Form
View source
class PurgeConfigurationsConfirmForm extends ConfirmFormBase {
  use ConfigDependencyDeleteFormTrait;

  /**
   * The module installer service.
   *
   * @var \Drupal\Core\Extension\ModuleInstallerInterface
   */
  protected $moduleInstaller;

  /**
   * The expirable key value store.
   *
   * @var \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface
   */
  protected $keyValueExpirable;

  /**
   * The configuration manager.
   *
   * @var \Drupal\Core\Config\ConfigManagerInterface
   */
  protected $configManager;

  /**
   * The entity manager.
   *
   * @var \Drupal\Core\Entity\EntityManagerInterface
   */
  protected $entityManager;

  /**
   * An array of modules to uninstall.
   *
   * @var array
   */
  protected $modules = [];

  /**
   * Constructs a ModulesUninstallConfirmForm object.
   *
   * @param \Drupal\Core\Extension\ModuleInstallerInterface $module_installer
   *   The module installer.
   * @param \Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface $key_value_expirable
   *   The key value expirable factory.
   * @param \Drupal\Core\Config\ConfigManagerInterface $config_manager
   *   The configuration manager.
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   */
  public function __construct(ModuleInstallerInterface $module_installer, KeyValueStoreExpirableInterface $key_value_expirable, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager) {
    $this->moduleInstaller = $module_installer;
    $this->keyValueExpirable = $key_value_expirable;
    $this->configManager = $config_manager;
    $this->entityManager = $entity_manager;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('module_installer'), $container
      ->get('keyvalue.expirable')
      ->get('easy_install_purgeconfigs'), $container
      ->get('config.manager'), $container
      ->get('entity.manager'));
  }

  /**
   * {@inheritdoc}
   */
  public function getQuestion() {
    return $this
      ->t('Confirm Purge Configurations');
  }

  /**
   * {@inheritdoc}
   */
  public function getConfirmText() {
    return $this
      ->t('Purge Configurations');
  }

  /**
   * {@inheritdoc}
   */
  public function getCancelUrl() {
    return new Url('easy_install.purge_configurations');
  }

  /**
   * {@inheritdoc}
   */
  public function getDescription() {
    return $this
      ->t('Would you like to continue with purge the above?');
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'purge_configuration_confirm_form';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {

    // Retrieve the list of modules from the key value store.
    $account = $this
      ->currentUser()
      ->id();
    $this->modules = $this->keyValueExpirable
      ->get($account);

    // Prevent this page from showing when the module list is empty.
    if (empty($this->modules['install'])) {
      drupal_set_message($this
        ->t('The selected modules could not be Purged, either due to a website problem or due to the uninstall confirmation form timing out. Please try again.'), 'error');
      return $this
        ->redirect('easy_install.purge_configurations');
    }
    $data = system_rebuild_module_data();
    $form['text']['#markup'] = '<p>' . $this
      ->t('Select the following configurations, selected configs will be completely deleted from your site!') . '</p>';
    $form['modules'] = [
      '#theme' => 'item_list',
      '#items' => $this->modules['install'],
    ];
    foreach ($this->modules['install'] as $module => $module_name) {
      $install_dir = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY;
      $details = file_scan_directory($install_dir, "/\\.(yml)\$/");
      if (!empty($details)) {
        $form['modules_config'][$module] = [
          '#type' => 'details',
          '#title' => t('@name', [
            '@name' => $module,
          ]),
          '#description' => t('We found that @description module have configurations with it, if you like to delete it Please select the checkbox', [
            '@description' => $module,
          ]),
          '#weight' => 0,
          '#validated' => TRUE,
          '#open' => TRUE,
        ];
        $details = file_scan_directory($install_dir, "/\\.(yml)\$/");
        $options = [];
        foreach ($details as $config_value) {
          $options[$config_value->name] = $config_value->name;
        }
        $form['modules_config'][$module]['configs'] = [
          '#type' => 'checkboxes',
          '#label' => $config_value->name,
          '#title' => t('Select the configurations to be deleted'),
          '#options' => $options,
          '#validated' => TRUE,
        ];
      }
    }
    $form['all_configs'] = [
      '#type' => 'checkbox',
      '#label' => t('Delete all the listed configurations'),
      '#title' => t('Delete all the listed configurations'),
      '#validated' => TRUE,
    ];
    return parent::buildForm($form, $form_state);
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {

    // Clear the key value store entry.
    $account = $this
      ->currentUser()
      ->id();
    if ($form_state
      ->getValue('all_configs')) {
      foreach ($form_state
        ->getValues('configs') as $key => $value) {
        \Drupal::configFactory()
          ->getEditable($key)
          ->delete();
      }
    }
    else {
      foreach ($form_state
        ->getValues('configs') as $key => $values) {
        if ($values) {
          \Drupal::configFactory()
            ->getEditable($key)
            ->delete();
        }
      }
    }
    $this->keyValueExpirable
      ->delete($account);
    drupal_set_message($this
      ->t('The selected configurations have
      been deleted.'));
    $form_state
      ->setRedirectUrl($this
      ->getCancelUrl());
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigDependencyDeleteFormTrait::addDependencyListsToForm protected function Adds form elements to list affected configuration entities.
ConfigDependencyDeleteFormTrait::t abstract protected function Translates a string to the current language or to a given language.
ConfirmFormBase::getCancelText public function Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface::getCancelText 1
ConfirmFormBase::getFormName public function Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface::getFormName
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
PurgeConfigurationsConfirmForm::$configManager protected property The configuration manager.
PurgeConfigurationsConfirmForm::$entityManager protected property The entity manager.
PurgeConfigurationsConfirmForm::$keyValueExpirable protected property The expirable key value store.
PurgeConfigurationsConfirmForm::$moduleInstaller protected property The module installer service.
PurgeConfigurationsConfirmForm::$modules protected property An array of modules to uninstall.
PurgeConfigurationsConfirmForm::buildForm public function Form constructor. Overrides ConfirmFormBase::buildForm
PurgeConfigurationsConfirmForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
PurgeConfigurationsConfirmForm::getCancelUrl public function Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface::getCancelUrl
PurgeConfigurationsConfirmForm::getConfirmText public function Returns a caption for the button that confirms the action. Overrides ConfirmFormBase::getConfirmText
PurgeConfigurationsConfirmForm::getDescription public function Returns additional text to display as a description. Overrides ConfirmFormBase::getDescription
PurgeConfigurationsConfirmForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
PurgeConfigurationsConfirmForm::getQuestion public function Returns the question to ask the user. Overrides ConfirmFormInterface::getQuestion
PurgeConfigurationsConfirmForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
PurgeConfigurationsConfirmForm::__construct public function Constructs a ModulesUninstallConfirmForm object.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.