class MenuItemExtrasUninstallValidator in Menu Item Extras 8.2
Same name in this branch
- 8.2 src/MenuItemExtrasUninstallValidator.php \Drupal\menu_item_extras\MenuItemExtrasUninstallValidator
- 8.2 src/ProxyClass/MenuItemExtrasUninstallValidator.php \Drupal\menu_item_extras\ProxyClass\MenuItemExtrasUninstallValidator
Prevents uninstall menu item extras module if there are extra data.
Hierarchy
- class \Drupal\menu_item_extras\MenuItemExtrasUninstallValidator implements ModuleUninstallValidatorInterface uses StringTranslationTrait
Expanded class hierarchy of MenuItemExtrasUninstallValidator
1 string reference to 'MenuItemExtrasUninstallValidator'
1 service uses MenuItemExtrasUninstallValidator
File
- src/
MenuItemExtrasUninstallValidator.php, line 14
Namespace
Drupal\menu_item_extrasView source
class MenuItemExtrasUninstallValidator implements ModuleUninstallValidatorInterface {
use StringTranslationTrait;
/**
* The current database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $connection;
/**
* Constructs a new MenuItemExtrasUninstallValidator.
*
* @param \Drupal\Core\Database\Connection $connection
* The current database connection.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The string translation service.
*/
public function __construct(Connection $connection, TranslationInterface $string_translation) {
$this->connection = $connection;
$this->stringTranslation = $string_translation;
}
/**
* {@inheritdoc}
*/
public function validate($module) {
if ($module === 'menu_item_extras' && $this
->hasExtraData()) {
$reasons = [];
$reasons[] = $this
->t('There are extra data for menus. <a href=":url">Remove extra data</a>.', [
':url' => Url::fromRoute('menu_item_extras.clear_all_extra_data')
->toString(),
]);
return $reasons;
}
}
/**
* Determines if there is any extra data for menu or not.
*
* @return bool
* TRUE if there are extra data for menus, FALSE otherwise.
*/
protected function hasExtraData() {
$results = $this->connection
->select('menu_link_content_data', 'mlcd')
->fields('mlcd', [
'view_mode',
])
->isNotNull('view_mode')
->execute()
->fetchAll();
return !empty($results);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MenuItemExtrasUninstallValidator:: |
protected | property | The current database connection. | |
MenuItemExtrasUninstallValidator:: |
protected | function | Determines if there is any extra data for menu or not. | |
MenuItemExtrasUninstallValidator:: |
public | function |
Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface:: |
|
MenuItemExtrasUninstallValidator:: |
public | function | Constructs a new MenuItemExtrasUninstallValidator. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |