public function QueryTestForm::buildForm in Lightweight Directory Access Protocol (LDAP) 8.3
Same name and namespace in other branches
- 8.4 ldap_query/src/Form/QueryTestForm.php \Drupal\ldap_query\Form\QueryTestForm::buildForm()
Form constructor.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
array The form structure.
Overrides FormInterface::buildForm
File
- ldap_query/
src/ Form/ QueryTestForm.php, line 32
Class
- QueryTestForm
- Test form for queries.
Namespace
Drupal\ldap_query\FormCode
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;
}
}