Commit 2a174c7a authored by Nigel McNie's avatar Nigel McNie
Browse files

Add View::import_from_config method to match $view->export_config()



Takes the config without much validation, so the method will whine like
a little girl if the config doesn't have everything set.
Signed-off-by: default avatarNigel McNie <nigel@catalyst.net.nz>
parent a70e3692
......@@ -1541,6 +1541,53 @@ class View {
return $config;
}
/**
* Given a data structure like the one created by {@link export_config},
* creates and returns a View object representing the config.
*
* @param array $config The config, as generated by export_config. Note
* that if you miss fields, this method will throw
* warnings.
* @param int $userid The user who issued the command to do the import
* (defaults to the logged in user)
* @return View The created view
*/
public static function import_from_config(array $config, $userid=null) {
$viewdata = array(
'title' => $config['title'],
'description' => $config['description'],
'type' => $config['type'],
'layout' => $config['layout'],
'numcolumns' => $config['numcolumns'],
'ownerformat' => $config['ownerformat'],
);
$view = View::create($viewdata, $userid);
if (isset($config['tags'])) $view->set('tags', $config['tags']); // TODO can this be done in the constructor?
$col = 1;
foreach ($config['columns'] as $column) {
$row = 1;
foreach ($column as $blockinstance) {
safe_require('blocktype', $blockinstance['type']);
$bi = call_static_method(generate_class_name('blocktype', $blockinstance['type']), 'import_create_blockinstance', $blockinstance['config']);
if ($bi) {
$bi->set('title', $blockinstance['title']);
$bi->set('column', $col);
$bi->set('order', $row);
$view->addblockinstance($bi);
$row++;
}
else {
log_debug("Blocktype {$blockinstance['type']}'s import_create_blockinstance did not give us a blockinstance, so not importing this block");
}
}
$col++;
}
return $view;
}
/**
* Makes a URL for a view block editing page
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment