QueryTestForm.php in Lightweight Directory Access Protocol (LDAP) 8.3
File
ldap_query/src/Form/QueryTestForm.php
View source
<?php
namespace Drupal\ldap_query\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\FormBase;
use Drupal\ldap_query\Controller\QueryController;
use Drupal\ldap_servers\Form\ServerTestForm;
class QueryTestForm extends FormBase {
public function getFormId() {
return 'ldap_query_test_form';
}
public function __construct() {
}
public function buildForm(array $form, FormStateInterface $form_state, $ldap_query_entity = NULL) {
if ($ldap_query_entity) {
$controller = new QueryController($ldap_query_entity);
$controller
->execute();
$data = $controller
->getRawResults();
$form['result_count'] = [
'#markup' => '<h2>' . $this
->t('@count results', [
'@count' => $data['count'],
]) . '</h2>',
];
unset($data['count']);
$header[] = 'DN';
$attributes = $controller
->availableFields();
foreach ($attributes as $attribute) {
$header[] = $attribute;
}
$rows = [];
foreach ($data as $entry) {
$row = [
$entry['dn'],
];
foreach ($attributes as $attribute_data) {
$processedAttributeName = mb_strtolower($attribute_data);
if (!isset($entry[$processedAttributeName])) {
$row[] = 'No data';
}
elseif (is_array($entry[$processedAttributeName])) {
unset($entry[$processedAttributeName]['count']);
$row[] = ServerTestForm::binaryCheck(implode("\n", $entry[$processedAttributeName]));
}
else {
$row[] = ServerTestForm::binaryCheck($entry[$processedAttributeName]);
}
}
unset($entry['count']);
$rows[] = $row;
}
$form['result'] = [
'#type' => 'table',
'#header' => $header,
'#rows' => $rows,
];
return $form;
}
}
public function validateForm(array &$form, FormStateInterface $form_state) {
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}