You are here

class ConfigSplitDeactivateForm in Configuration Split 2.0.x

The form for de-activating a split.

Hierarchy

Expanded class hierarchy of ConfigSplitDeactivateForm

1 string reference to 'ConfigSplitDeactivateForm'
config_split.routing.yml in ./config_split.routing.yml
config_split.routing.yml

File

src/Form/ConfigSplitDeactivateForm.php, line 18

Namespace

Drupal\config_split\Form
View source
class ConfigSplitDeactivateForm extends FormBase {
  use ConfigImportFormTrait;

  /**
   * The active config storage.
   *
   * @var \Drupal\Core\Config\StorageInterface
   */
  protected $activeStorage;

  /**
   * The split manager.
   *
   * @var \Drupal\config_split\ConfigSplitManager
   */
  protected $manager;

  /**
   * The status override service.
   *
   * @var \Drupal\config_split\Config\StatusOverride
   */
  protected $statusOverride;

  /**
   * The constructor.
   *
   * @param \Drupal\Core\Config\StorageInterface $activeStorage
   *   The active config storage.
   * @param \Drupal\config_split\ConfigSplitManager $configSplitManager
   *   The split manager.
   * @param \Drupal\config_split\Config\StatusOverride $statusOverride
   *   The status override service.
   */
  public function __construct(StorageInterface $activeStorage, ConfigSplitManager $configSplitManager, StatusOverride $statusOverride) {
    $this->activeStorage = $activeStorage;
    $this->manager = $configSplitManager;
    $this->statusOverride = $statusOverride;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('config.storage'), $container
      ->get('config_split.manager'), $container
      ->get('config_split.status_override'));
  }

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

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $split = $this
      ->getSplit();
    $comparer = new StorageComparer($this->manager
      ->singleDeactivate($split, FALSE), $this->activeStorage);
    $options = [
      'route' => [
        'config_split' => $split
          ->getName(),
        'operation' => 'deactivate',
      ],
      'operation label' => $this
        ->t('Import all'),
    ];
    $form = $this
      ->buildFormWithStorageComparer($form, $form_state, $comparer, $options);
    $locallyActivated = $this->statusOverride
      ->getSplitOverride($split
      ->getName()) === TRUE;
    $form['deactivate_local_only'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Deactivate locally only'),
      '#description' => $this
        ->t('If this is set, the split config will not be made inactive by default but instead it will be locally overwritten to be inactive.'),
      '#default_value' => !$locallyActivated,
    ];
    if ($locallyActivated) {
      $form['deactivation_notice'] = [
        '#type' => 'markup',
        '#markup' => $this
          ->t('The local activation state override will be removed'),
      ];
    }
    $entity = $this->manager
      ->getSplitEntity($split
      ->getName());
    $form['export_before'] = [
      '#type' => 'checkbox',
      '#title' => $this
        ->t('Export the config before deactivating.'),
      '#description' => $this
        ->t('To manually export and see what is exported check <a href="@export-page">the export page</a>.', [
        '@export-page' => $entity
          ->toUrl('export')
          ->toString(),
      ]),
      '#default_value' => !$locallyActivated,
    ];
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $split = $this
      ->getSplit();
    $override = FALSE;
    if ($form_state
      ->getValue('deactivate_local_only')) {
      $this->statusOverride
        ->setSplitOverride($split
        ->getName(), FALSE);
      $override = TRUE;
    }
    else {
      $this->statusOverride
        ->setSplitOverride($split
        ->getName(), NULL);
    }
    $comparer = new StorageComparer($this->manager
      ->singleDeactivate($split, $form_state
      ->getValue('export_before'), $override), $this->activeStorage);
    $this
      ->launchImport($comparer);
  }

  /**
   * Checks access for a specific request.
   *
   * @param \Drupal\Core\Session\AccountInterface $account
   *   Run access checks for this account.
   *
   * @return \Drupal\Core\Access\AccessResultInterface
   *   The access result.
   */
  public function access(AccountInterface $account) {
    $split = $this
      ->getSplit();
    return AccessResult::allowedIfHasPermission($account, 'administer configuration split')
      ->andIf(AccessResult::allowedIf($split
      ->get('status')))
      ->addCacheableDependency($split);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ConfigImporterTrait::getConfigImporterFromComparer protected function Get a config importer from a storage comparer.
ConfigImporterTrait::getConfigImporterFromStorage protected function Get a config importer from a storage to sync import.
ConfigImportFormTrait::buildFormWithStorageComparer protected function
ConfigImportFormTrait::finishImportBatch public static function
ConfigImportFormTrait::getSplit protected function Get a split from the route.
ConfigImportFormTrait::launchImport protected function
ConfigSplitDeactivateForm::$activeStorage protected property The active config storage.
ConfigSplitDeactivateForm::$manager protected property The split manager. Overrides ConfigImportFormTrait::$manager
ConfigSplitDeactivateForm::$statusOverride protected property The status override service.
ConfigSplitDeactivateForm::access public function Checks access for a specific request.
ConfigSplitDeactivateForm::buildForm public function Form constructor. Overrides FormInterface::buildForm
ConfigSplitDeactivateForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
ConfigSplitDeactivateForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
ConfigSplitDeactivateForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
ConfigSplitDeactivateForm::__construct public function The constructor.
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 3
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. 3
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.
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 72
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. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
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. 4
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
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.