public static function parseShowOnConditions($showOn, $formControl = null, $group = null)
{
if (!$showOn) {
return array();
}
$formPath = $formControl ?: '';
if ($group) {
$groups = explode('.', $group);
if (empty($formPath) && isset($groups[0])) {
$formPath = $groups[0];
array_shift($groups);
}
foreach ($groups as $group) {
$formPath .= '[' . $group . ']';
}
}
$showOnData = array();
$showOnParts = preg_split('#(\\[AND\\]|\\[OR\\])#', $showOn, -1, PREG_SPLIT_DELIM_CAPTURE);
$op = '';
foreach ($showOnParts as $showOnPart) {
if ($showOnPart === '[AND]' || $showOnPart === '[OR]') {
$op = trim($showOnPart, '[]');
continue;
}
$compareEqual = strpos($showOnPart, '!:') === false;
$showOnPartBlocks = explode($compareEqual ? ':' : '!:', $showOnPart, 2);
$dotPos = strpos($showOnPartBlocks[0], '.');
if ($dotPos === false) {
$field = $formPath ? $formPath . '[' . $showOnPartBlocks[0] . ']' : $showOnPartBlocks[0];
} else {
if ($dotPos === 0) {
$fieldName = substr($showOnPartBlocks[0], 1);
$field = $formControl ? $formControl . '[' . $fieldName . ']' : $fieldName;
} else {
if ($formControl) {
$field = $formControl . ('[' . str_replace('.', '][', $showOnPartBlocks[0]) . ']');
} else {
$groupParts = explode('.', $showOnPartBlocks[0]);
$field = array_shift($groupParts) . '[' . join('][', $groupParts) . ']';
}
}
}
$showOnData[] = array('field' => $field, 'values' => explode(',', $showOnPartBlocks[1]), 'sign' => $compareEqual === true ? '=' : '!=', 'op' => $op);
if ($op !== '') {
$op = '';
}
}
return $showOnData;
}