I made 2 custom modules: boutique and paypal. paypal is a dependance of boutique.
I check if paypal is enabled, with the following code.
namespace Drupal\boutique\Form\Multistep;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\paypal\Controller\PaypalController;
abstract class MultistepFormBase extends FormBase {
protected function saveData() {
if (\Drupal::moduleHandler()->moduleExists('paypal')) {
$test = new PaypalController();
$test->setPaiement(10,0,1);
}
$this->deleteStore();
drupal_set_message($this->t('The form has been saved.'));
}
}
All is working good, but use Drupal\paypal\Controller\PaypalController;
is always be here; if the paypal module is not present, does it create problems? How can I conditionally use use Drupal\paypal\Controller\PaypalController;` only when the module is installed?