You are here

class BootstrapLayoutsUninstallValidator in Bootstrap Layouts 8.5

Same name in this branch
  1. 8.5 src/BootstrapLayoutsUninstallValidator.php \Drupal\bootstrap_layouts\BootstrapLayoutsUninstallValidator
  2. 8.5 src/ProxyClass/BootstrapLayoutsUninstallValidator.php \Drupal\bootstrap_layouts\ProxyClass\BootstrapLayoutsUninstallValidator
Same name and namespace in other branches
  1. 8.4 src/BootstrapLayoutsUninstallValidator.php \Drupal\bootstrap_layouts\BootstrapLayoutsUninstallValidator

Class BootstrapLayoutsUninstallValidator

Hierarchy

Expanded class hierarchy of BootstrapLayoutsUninstallValidator

1 string reference to 'BootstrapLayoutsUninstallValidator'
bootstrap_layouts.services.yml in ./bootstrap_layouts.services.yml
bootstrap_layouts.services.yml
1 service uses BootstrapLayoutsUninstallValidator
bootstrap_layouts_uninstall_validator in ./bootstrap_layouts.services.yml
\Drupal\bootstrap_layouts\BootstrapLayoutsUninstallValidator

File

src/BootstrapLayoutsUninstallValidator.php, line 11

Namespace

Drupal\bootstrap_layouts
View source
class BootstrapLayoutsUninstallValidator implements ModuleUninstallValidatorInterface {
  use StringTranslationTrait;

  /**
   * The BootstrapLayouts manager.
   *
   * @var \Drupal\bootstrap_layouts\BootstrapLayoutsManager
   */
  protected $manager;

  /**
   * Constructs a new ContentUninstallValidator.
   *
   * @param \Drupal\bootstrap_layouts\BootstrapLayoutsManager $manager
   *   The BootstrapLayouts manager.
   */
  public function __construct(BootstrapLayoutsManager $manager) {
    $this->manager = $manager;
  }

  /**
   * {@inheritdoc}
   */
  public function validate($module) {
    $reasons = [];
    if ($module === 'bootstrap_layouts') {
      $layouts = [];
      foreach ($this->manager
        ->getHandlers() as $handler) {
        foreach ($handler
          ->loadInstances() as $storage_id => $layout) {
          if ($layout
            ->isBootstrapLayout()) {
            $layouts[$layout
              ->getId()][] = $handler
              ->getPluginId() . ':' . $storage_id;
          }
        }
      }
      ksort($layouts);
      foreach ($layouts as $layout_id => $storage_ids) {
        sort($storage_ids, SORT_NATURAL);
        $reasons[] = $this
          ->t('Using layout: @layout_id (@storage_ids)', [
          '@layout_id' => $layout_id,
          '@storage_ids' => implode(', ', $storage_ids),
        ]);
      }
    }
    return $reasons;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BootstrapLayoutsUninstallValidator::$manager protected property The BootstrapLayouts manager.
BootstrapLayoutsUninstallValidator::validate public function Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface::validate
BootstrapLayoutsUninstallValidator::__construct public function Constructs a new ContentUninstallValidator.
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
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.