Exemplo n.º 1
0
 public static function getEditConfigs($componentClass, Kwf_Component_Generator_Abstract $gen, $idTemplate = null, $componentIdSuffix = '')
 {
     $ret = array('componentConfigs' => array(), 'contentEditComponents' => array());
     if (is_null($idTemplate)) {
         if ($gen->hasSetting('dbIdShortcut')) {
             $idTemplate = $gen->getSetting('dbIdShortcut') . '{0}';
         } else {
             $idTemplate = '{componentId}' . $gen->getIdSeparator() . '{0}';
         }
     }
     $cfg = Kwc_Admin::getInstance($componentClass)->getExtConfig();
     foreach ($cfg as $k => $c) {
         $suffix = $componentIdSuffix;
         if (isset($c['componentIdSuffix'])) {
             $suffix .= $c['componentIdSuffix'];
             unset($c['componentIdSuffix']);
         }
         $ret['componentConfigs'][$componentClass . '-' . $k] = $c;
         $ret['contentEditComponents'][] = array('componentClass' => $componentClass, 'type' => $k, 'idTemplate' => $idTemplate, 'idSeparator' => $gen->getIdSeparator(), 'componentIdSuffix' => $suffix, 'title' => $c['title'], 'icon' => $c['icon']);
     }
     foreach ($gen->getGeneratorPlugins() as $plugin) {
         $cls = get_class($plugin);
         $cfg = Kwc_Admin::getInstance($cls)->getExtConfig();
         foreach ($cfg as $k => $c) {
             $suffix = $componentIdSuffix;
             if (isset($c['componentIdSuffix'])) {
                 $suffix .= $c['componentIdSuffix'];
                 unset($c['componentIdSuffix']);
             }
             $ret['componentConfigs'][$cls . '-' . $k] = $c;
             $ret['contentEditComponents'][] = array('componentClass' => $cls, 'type' => $k, 'idTemplate' => $idTemplate, 'componentIdSuffix' => $suffix);
         }
     }
     if (Kwc_Abstract::hasSetting($componentClass, 'editComponents')) {
         $editComponents = Kwc_Abstract::getSetting($componentClass, 'editComponents');
         foreach ($editComponents as $c) {
             $childGen = Kwf_Component_Generator_Abstract::getInstances($componentClass, array('componentKey' => $c));
             if (!$childGen) {
                 throw new Kwf_Exception("editComponents '{$c}' doesn't exist in '{$componentClass}'");
             }
             $childGen = $childGen[0];
             $cls = Kwc_Abstract::getChildComponentClass($componentClass, null, $c);
             $edit = self::getEditConfigs($cls, $childGen, $idTemplate, $componentIdSuffix . $childGen->getIdSeparator() . $c);
             $ret['componentConfigs'] = array_merge($ret['componentConfigs'], $edit['componentConfigs']);
             $ret['contentEditComponents'] = array_merge($ret['contentEditComponents'], $edit['contentEditComponents']);
         }
     }
     return $ret;
 }