ModuleEnabled.php in Varbase Total Control Dashboard 9.0.x
File
src/Plugin/Condition/ModuleEnabled.php
View source
<?php
namespace Drupal\varbase_total_control\Plugin\Condition;
use Drupal\Core\Condition\ConditionPluginBase;
use Drupal\Core\Form\FormStateInterface;
class ModuleEnabled extends ConditionPluginBase {
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['module'] = [
'#type' => 'textfield',
'#title' => $this
->t('Module machine name'),
'#default_value' => $this->configuration['module'],
'#description' => $this
->t('The module’s machine name. Example: <em>page_manager</em>.'),
];
return parent::buildConfigurationForm($form, $form_state);
}
public function defaultConfiguration() {
return [
'module' => '',
] + parent::defaultConfiguration();
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['module'] = $form_state
->getValue('module');
parent::submitConfigurationForm($form, $form_state);
}
public function summary() {
$module = $this->configuration['module'];
if (!empty($this->configuration['negate'])) {
return $this
->t('If the module <b>@module</b> is not installed.', [
'@module' => $module,
]);
}
else {
return $this
->t('If the module <b>@module</b> is installed.', [
'@module' => $module,
]);
}
}
public function evaluate() {
if (!trim($this->configuration['module'])) {
return TRUE;
}
$moduleHandler = \Drupal::service('module_handler');
return (bool) $moduleHandler
->moduleExists($this->configuration['module']);
}
}