private function ViewsEFFieldsetData::recursivetreetofapi in Views Exposed Form Fieldset 8
Tree to FAPI recursive.
Parameters
array $data: The data.
array $form: The form.
array $element: The element.
1 call to ViewsEFFieldsetData::recursivetreetofapi()
- ViewsEFFieldsetData::treetofapi in src/
ViewsEFFieldsetData.php - Convert the tree data into form api data.
File
- src/
ViewsEFFieldsetData.php, line 139
Class
- ViewsEFFieldsetData
- Class ViewsEFFieldsetData.
Namespace
Drupal\views_ef_fieldsetCode
private function recursivetreetofapi(array $data, array &$form, array &$element = []) {
foreach ($data as $key => $item) {
// If it's a filter field.
if ($item['item']['type'] === 'filter') {
$form_info = isset($form['#info']['filter-' . $item['item']['id']]) ? $form['#info']['filter-' . $item['item']['id']] : NULL;
$field_name = $form_info['value'] ?: $item['item']['id'];
if (isset($form[$field_name]) && is_array($form[$field_name])) {
$element[$field_name] = $form[$field_name] + [
'#weight' => $item['item']['weight'],
'#title' => $form_info['label'] ?: '',
'#description' => $form_info['description'] ?: '',
];
unset($form['#info']['filter-' . $item['item']['id']]);
unset($form[$field_name]);
}
}
// If it's a sort field.
if ($item['item']['type'] === 'sort') {
$field_name = $item['item']['id'];
if (isset($form[$field_name]) && is_array($form[$field_name])) {
$element[$field_name] = $form[$field_name];
$element[$field_name]['#weight'] = $item['item']['weight'];
unset($form[$field_name]);
}
}
// If it's the action buttons.
if ($item['item']['type'] === 'buttons') {
$field_name = $item['item']['id'];
if (isset($form['actions'][$field_name]) && is_array($form['actions'][$field_name])) {
$button = $form['actions'][$field_name];
$button['#weight'] = $item['item']['weight'];
$button['#access'] = TRUE;
$element[$field_name] = $button;
$form['actions'][$field_name]['#attributes']['style'][] = 'display:none;';
// unset($form['actions'][$field_name]);.
}
}
if (!empty($item['children']) && $item['item']['type'] === 'container') {
$element['container-' . $item['item']['id']] = [
'#type' => $item['item']['container_type'],
'#title' => t('@title', [
'@title' => $item['item']['title'],
]),
'#group' => 'container-' . $item['item']['pid'],
'#description' => t('@description', [
'@description' => $item['item']['description'],
]),
'#open' => (bool) $item['item']['open'],
'#attributes' => [
'class' => [
'views-ef-fieldset-container',
'views-ef-fieldset-' . $item['item']['id'],
],
],
'#weight' => $item['item']['weight'],
];
$element['container-' . $item['item']['id']]['children'] = [];
$this
->recursivetreetofapi($item['children'], $form, $element['container-' . $item['item']['id']]['children']);
}
}
}