protected function getScopeFields(CompInfoblock\Entity $infoblock, \Floxim\Main\Content\Entity $c_page) { $fields = array(); // format: [page_id]-[descendants|children|this]-[|type_id] //$path_ids = $c_page->getParentIds(); $path_ids = $c_page->getPath()->getValues('id'); $path = fx::data('page', $path_ids); if (!$path->findOne('id', $c_page['id'])) { $path[] = $c_page; } $path_count = count($path); $c_type = $c_page['type']; $page_com = fx::data('component', $c_page['type']); $c_type_name = $page_com->getItemName('one'); $container_infoblock = null; if ($infoblock['container_infoblock_id']) { $container_infoblock = fx::data('infoblock', $infoblock['container_infoblock_id']); } $c_scope_code = $infoblock->getScopeString(); $vals = array(); foreach ($path as $i => $pi) { //$sep = str_repeat(" -- ", $i); $sep = str_repeat(" ", $i * 6); $pn = $pi['name']; $pt = $pi->getComponent()->getItemName('one'); $pt_of = $pi->getComponent()->getItemName('of'); $is_last = $i === $path_count - 1; $c_page_id = $pi['id']; if ($i === 0) { $c_page_id = fx::env('site')->get('index_page_id'); $vals[] = array($c_page_id . '-descendants-', fx::alang('All pages')); if ($path_count > 1) { $vals[] = array($c_page_id . '-children-' . $c_type, sprintf(fx::alang('All pages of type %s'), $c_type_name)); } } if ($i !== 0) { $vals[] = array($c_page_id . '-descendants-', $sep . fx::util()->ucfirst(sprintf(fx::alang('%s %s and children'), $pt, $pn))); } if ($is_last) { $vals[] = array($c_page_id . '-this-', $sep . fx::util()->ucfirst(sprintf(fx::alang('%s %s only'), $pt, $pn))); } else { $vals[] = array($c_page_id . '-children-', $sep . fx::util()->ucfirst(sprintf(fx::alang('%s %s children only'), $pt_of, $pn))); } if (!$is_last && $i !== 0) { $vals[] = array($c_page_id . '-children-' . $c_type, $sep . fx::util()->ucfirst(sprintf(fx::alang('%s %s children of type %s'), $pt_of, $pn, $c_type_name))); } } // can be set to "hidden" later $scope_field_type = 'select'; if (!$infoblock['id']) { if ($container_infoblock) { $c_scope_code = $container_infoblock->getScopeString(); if ($container_infoblock['scope']['pages'] === 'this') { $scope_field_type = 'hidden'; } } else { $ctr = $infoblock->initController(); $cfg = $ctr->getConfig(true); if (isset($cfg['default_scope'])) { $c_scope_code = is_callable($cfg['default_scope']) ? call_user_func($cfg['default_scope']) : $cfg['default_scope']; if ($c_scope_code === 'this') { $c_scope_code = fx::env('page_id') . '-this-'; } elseif ($c_scope_code === 'all') { $c_scope_code = fx::env('site')->get('index_page_id') . '-descendants-'; } } } } $fields[] = array('type' => $scope_field_type, 'label' => fx::alang('Scope'), 'name' => 'complex_scope', 'values' => $vals, 'value' => $c_scope_code); $fields['visibility'] = array('type' => 'hidden', 'label' => 'Visibility', 'name' => 'visibility', 'value' => $infoblock['scope']['visibility']); return $fields; }