private function GConfigForm::buildTable in Jammer 1.0.x
1 call to GConfigForm::buildTable()
- GConfigForm::buildForm in src/
Form/ GConfigForm.php - Form constructor.
File
- src/
Form/ GConfigForm.php, line 39
Class
Namespace
Drupal\jammer\FormCode
private function buildTable($data, &$headers) {
// create table headers
$headers = [
$this
->t('Form id'),
$this
->t('Element id'),
$this
->t('Hide/disable'),
$this
->t('Exception'),
$this
->t('Role(s)'),
$this
->t('Invert roles'),
$this
->t('Priority'),
$this
->t('Comment'),
$this
->t('Modify'),
$this
->t('Delete'),
];
// prepare array for per-group sorting
$groups = [];
foreach ($data as $entry) {
if (isset($entry['group']) and !empty($entry['group'])) {
$groups[$entry['group']] = $entry['group'];
}
}
// sort ascending and insert before the "unsorted" group
sort($groups, SORT_LOCALE_STRING);
array_unshift($groups, $this
->t("Unsorted entries"));
// prepare and store data in group-sorted array
$content = [];
foreach ($groups as $g) {
$content[$g] = [];
}
foreach ($data as $cnt => $entry) {
if (isset($entry['group']) and !empty($entry['group'])) {
$target = $entry['group'];
}
else {
$target = $this
->t("Unsorted entries");
}
$line = [];
$line[] = $entry['form'];
if (is_array($entry['elements'])) {
$line[] = implode(" ", $entry['elements']);
}
else {
$line[] = $entry['elements'];
}
if ($entry['remove'] == 0) {
$line[] = $this
->t('Remove');
}
else {
$line[] = $this
->t('Disable');
}
if ($entry['creation'] == 0) {
$line[] = $this
->t('Always');
}
else {
if ($entry['creation'] == 1) {
$line[] = $this
->t('Exclude creation');
}
else {
if ($entry['creation'] == 2) {
$line[] = $this
->t('Only creation');
}
else {
$line[] = $this
->t('Exclude when empty');
}
}
}
if (isset($entry['roles']) and is_array($entry['roles'])) {
$line[] = implode("; ", $entry['roles']);
}
else {
$line[] = "";
}
if ($entry['invert'] == 1) {
$line[] = $this
->t("Yes");
}
else {
$line[] = $this
->t("No");
}
$line[] = $entry['priority'];
$line[] = $entry['comment'];
// add modify/delete
$t = Link::createFromRoute('Modify', 'jammer.jammer_config_action', [
'action' => 'modify',
'id' => $cnt,
]);
$line[] = $t;
$t = Link::createFromRoute('Delete', 'jammer.jammer_config_action', [
'action' => 'delete',
'id' => $cnt,
]);
$line[] = $t;
$content[$target][] = $line;
}
// flatten result (with groups as separated rows)
$result = [];
foreach ($content as $grp => $list) {
$t = new FormattableMarkup("<b>• {$grp}</b>", []);
$result[] = [
$t,
'',
'',
'',
'',
'',
'',
'',
'',
];
foreach ($list as $l) {
$result[] = $l;
}
}
return $result;
}