public static function load(Context $context, Page $page, Grid $grid, $module, $name, $counter, $row, $column, $position, $params = array()) { if (!strlen($module)) { return; } $block_yml_file = $context->getBlocksHome($module) . $name . '.local.yml'; if (!file_exists($block_yml_file)) { $block_yml_file = $context->getBlocksHome($module) . $name . '.yml'; } if (!file_exists($block_yml_file)) { $context->getResponse()->sendError(WebAppResponse::SC_INTERNAL_SERVER_ERROR, 'Missing block definition file ' . $name . '.yml'); return; } // Imports block class and return an instance $def = yaml_parse_file($block_yml_file); $fqcn = $def['class']; if (!strlen($fqcn)) { // @todo convert to new class loader $fqcn = '\\Innomedia\\EmptyBlock'; } // @todo convert to new namespace convention if (!class_exists($fqcn)) { $context->getResponse()->sendError(WebAppResponse::SC_INTERNAL_SERVER_ERROR, 'Missing class ' . $fqcn); return; } $tpl_root = $context->getBlocksHome($module); $tpl_file = ''; $locales = $context->getLocales(); foreach ($locales as $locale) { if (file_exists($tpl_root . $name . '_' . $locale . '.local.tpl.php')) { // Local template for given language exists $tpl_file = $tpl_root . $name . '_' . $locale . '.local.tpl.php'; break; } if (file_exists($tpl_root . $name . '_' . $locale . '.tpl.php')) { // Template for given language exists $tpl_file = $tpl_root . $name . '_' . $locale . '.tpl.php'; break; } } if (!strlen($tpl_file)) { $webapp = WebAppContainer::instance('\\Innomatic\\Webapp\\WebAppContainer')->getCurrentWebApp(); if (file_exists($tpl_root . $webapp->getInitParameter('InnomediaDefaultLanguage') . '.' . $name . '.local.tpl.php')) { // Local template for default language exists $tpl_file = $tpl_root . $webapp->getInitParameter('InnomediaDefaultLanguage') . '.' . $name . '.local.tpl.php'; } elseif (file_exists($tpl_root . $webapp->getInitParameter('InnomediaDefaultLanguage') . '.' . $name . '.tpl.php')) { // Template for default language exists $tpl_file = $tpl_root . $webapp->getInitParameter('InnomediaDefaultLanguage') . '.' . $name . '.tpl.php'; } elseif (file_exists($tpl_root . $name . '.local.tpl.php')) { // Local template for no specific language exists $tpl_file = $tpl_root . $name . '.local.tpl.php'; } else { // Template for no specific language exists $tpl_file = $tpl_root . $name . '.tpl.php'; } } // Build block $obj = new $fqcn($tpl_file); $obj->setPage($page)->setGrid($grid); // Set block counter $obj->setCounter($counter)->setRow($row)->setColumn($column)->setPosition($position); // Set block parameters $obj->setParameters($params); // Set block types $obj->setTypes(isset($def['types']) && is_array($def['types']) ? $def['types'] : array()); return $obj; }