protected function checkConfig(&$config, $depth = 1, $gridBreadcrumb = array())
{
$fields =& $config['fields'];
if (!is_array($fields)) {
throw new \Ip\Exception('GRID configuration is missing \'fields\' attribute for table ' . $config['table']);
}
foreach ($fields as &$field) {
if (empty($field['type'])) {
$field['type'] = 'Text';
}
}
//if at least one of the fields is of type 'Tab', then make sure the first field is also 'Tab'. Otherwise tabs don't work.
if ($fields[0]['type'] != 'Tab') {
$tabExist = false;
foreach ($fields as $key => $fieldData) {
if (!empty($fieldData['type']) && $fieldData['type'] == 'Tab') {
$tabExist = true;
break;
}
}
if ($tabExist) {
array_unshift($fields, array('label' => __('General', 'Ip-admin', false), 'type' => 'Tab'));
}
}
//automatically add gridId to grid fields
$gridIndex = 0;
foreach ($fields as $key => &$fieldData) {
if (!empty($fieldData['type']) && $fieldData['type'] == 'Grid') {
$gridIndex++;
if (empty($fieldData['gridId'])) {
$fieldData['gridId'] = 'grid' . $gridIndex;
}
$subConfig = $fieldData['config'];
$loop = false;
foreach ($gridBreadcrumb as $crumb) {
if ($subConfig == $crumb) {
$loop = true;
}
}
if (!$loop) {
$newBreadcrumb = array_merge($gridBreadcrumb, array($config));
$this->checkConfig($fieldData['config'], $depth + 1, $newBreadcrumb);
}
}
}
if ($depth == 1) {
$this->configChecked = true;
}
}