class DebuggingReviewForm in Lightweight Directory Access Protocol (LDAP) 8.3
Form to allow for debugging review.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\ldap_help\Form\DebuggingReviewForm
Expanded class hierarchy of DebuggingReviewForm
1 string reference to 'DebuggingReviewForm'
- ldap_help.routing.yml in ldap_help/
ldap_help.routing.yml - ldap_help/ldap_help.routing.yml
File
- ldap_help/
src/ Form/ DebuggingReviewForm.php, line 18
Namespace
Drupal\ldap_help\FormView source
class DebuggingReviewForm extends FormBase {
protected $config;
protected $moduleHandler;
protected $entityTypeManager;
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'ldap_help_debugging_review';
}
/**
* Class constructor.
*/
public function __construct(ConfigFactoryInterface $config_factory, ModuleHandler $module_handler, EntityTypeManagerInterface $entity_type_manager) {
$this->config = $config_factory;
$this->moduleHandler = $module_handler;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('config.factory'), $container
->get('module_handler'), $container
->get('entity_type.manager'));
}
/**
* Returns raw data of configuration.
*
* @param string $configName
* Configuration name.
*
* @return string
* Raw configuration data.
*/
private function printConfig($configName) {
return '<pre>' . Yaml::encode($this
->config($configName)
->getRawData()) . '</pre>';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['title'] = [
'#markup' => '<h1>' . $this
->t('LDAP Debugging Review') . '</h1>',
];
if (!extension_loaded('ldap')) {
drupal_set_message($this
->t('PHP LDAP extension not loaded.'), 'error');
}
else {
$form['heading_modules'] = [
'#markup' => '<h2>' . $this
->t('PHP LDAP module') . '</h2>',
];
$form['modules'] = [
'#markup' => '<pre>' . Yaml::encode($this
->parsePhpModules()['ldap']) . '</pre>',
];
}
$form['heading_ldap'] = [
'#markup' => '<h2>' . $this
->t('Drupal LDAP modules') . '</h2>',
];
if ($this->moduleHandler
->moduleExists('ldap_user')) {
$form['config_users'] = [
'#markup' => '<h3>' . $this
->t('The LDAP user configuration') . '</h3>' . $this
->printConfig('ldap_user.settings'),
];
}
$user_register = $this
->config('user.settings')
->get('register');
$form['config_users_registration'] = [
'#markup' => $this
->t('Currently active Drupal user registration setting: @setting', [
'@setting' => $user_register,
]),
];
if ($this->moduleHandler
->moduleExists('ldap_authentication')) {
$form['config_authentication'] = [
'#markup' => '<h3>' . $this
->t('The LDAP authentication configuration') . '</h3>' . $this
->printConfig('ldap_authentication.settings'),
];
}
if ($this->moduleHandler
->moduleExists('ldap_help')) {
$form['config_help'] = [
'#markup' => '<h3>' . $this
->t('The LDAP help configuration') . '</h3>' . $this
->printConfig('ldap_help.settings'),
];
}
if ($this->moduleHandler
->moduleExists('ldap_servers')) {
$form['heading_servers'] = [
'#markup' => '<h2>' . $this
->t('Drupal LDAP servers') . '</h2>',
];
$servers = new ServerFactory();
foreach ($servers
->getAllServers() as $sid => $server) {
/** @var \Drupal\ldap_servers\Entity\Server $server */
$form['config_server_' . $sid] = [
'#markup' => '<h3>' . $this
->t('Server @name:', [
'@name' => $server
->label(),
]) . '</h3>' . $this
->printConfig('ldap_servers.server.' . $sid),
];
}
}
if ($this->moduleHandler
->moduleExists('authorization') && $this->moduleHandler
->moduleExists('ldap_authorization')) {
$form['heading_profiles'] = [
'#markup' => '<h2>' . $this
->t('Configured authorization profiles') . '</h2>',
];
$profiles = $this->entityTypeManager
->getStorage('authorization_profile')
->getQuery()
->execute();
foreach ($profiles as $profile) {
$form['authorization_profile_' . $profile] = [
'#markup' => '<h3>' . $this
->t('Profile @name:', [
'@name' => $profile,
]) . '</h3>' . $this
->printConfig('authorization.authorization_profile.' . $profile),
];
}
}
if ($this->moduleHandler
->moduleExists('ldap_query')) {
$form['heading_queries'] = [
'#markup' => '<h2>' . $this
->t('Configured LDAP queries') . '</h2>',
];
foreach (QueryController::getAllQueries() as $query) {
/** @var \Drupal\ldap_query\Entity\QueryEntity $query */
$form['query_' . $query
->id()] = [
'#markup' => '<h3>' . $this
->t('Query @name:', [
'@name' => $query
->label(),
]) . '</h3>' . $this
->printConfig('ldap_query.ldap_query_entity.' . $query
->id()),
];
}
}
return $form;
}
/**
* Generates an array of values from phpinfo().
*
* @return array
* Module list.
*/
private function parsePhpModules() {
ob_start();
phpinfo();
$s = ob_get_contents();
ob_end_clean();
$s = strip_tags($s, '<h2><th><td>');
$s = preg_replace('/<th[^>]*>([^<]+)<\\/th>/', "<info>\\1</info>", $s);
$s = preg_replace('/<td[^>]*>([^<]+)<\\/td>/', "<info>\\1</info>", $s);
$vtmp = preg_split('/(<h2>[^<]+<\\/h2>)/', $s, -1, PREG_SPLIT_DELIM_CAPTURE);
$vmodules = [];
for ($i = 1; $i < count($vtmp); $i++) {
if (preg_match('/<h2>([^<]+)<\\/h2>/', $vtmp[$i], $vmat)) {
$vname = trim($vmat[1]);
$vtmp2 = explode("\n", $vtmp[$i + 1]);
foreach ($vtmp2 as $vone) {
$vpat = '<info>([^<]+)<\\/info>';
$vpat3 = "/{$vpat}\\s*{$vpat}\\s*{$vpat}/";
$vpat2 = "/{$vpat}\\s*{$vpat}/";
// 3cols.
if (preg_match($vpat3, $vone, $vmat)) {
$vmodules[$vname][trim($vmat[1])] = [
trim($vmat[2]),
trim($vmat[3]),
];
}
elseif (preg_match($vpat2, $vone, $vmat)) {
$vmodules[$vname][trim($vmat[1])] = trim($vmat[2]);
}
}
}
}
return $vmodules;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
// Nothing to submit.
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DebuggingReviewForm:: |
protected | property | ||
DebuggingReviewForm:: |
protected | property | ||
DebuggingReviewForm:: |
protected | property | ||
DebuggingReviewForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
DebuggingReviewForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
DebuggingReviewForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
DebuggingReviewForm:: |
private | function | Generates an array of values from phpinfo(). | |
DebuggingReviewForm:: |
private | function | Returns raw data of configuration. | |
DebuggingReviewForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
DebuggingReviewForm:: |
public | function | Class constructor. | |
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
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. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |