[development] The state of import export
emspace.com.au at gmail.com
emspace.com.au at gmail.com
Mon Jan 28 05:43:06 UTC 2008
I would add to the list http://drupal.org/project/install_profile_api
Particularly the crud.inc file.
I've used it for a couple projects and added bits to it.
Topically, I do have a node create function that works well most of
the time. But it's a bit flakey depending what contrib modules are
doing to the node form.
I focus on passing everything in a simple keyed array format, and the
function then makes it look like a node submission. The difficulty
I've had is making the submitted form the right structure - the cck
fields are difficult to emulate, but I'm handling many of them (text,
number, nodereference, etc).
If it's of any interest, here is the uncommitted code. I chopped out
some hacks, so this version untested.
function install_create_content($content_type, $properties) {
global $user;
$default = array();
$default['type'] = $content_type;
$default['format'] = 0;
$default['comment'] = 2; // Enable read/write comments
$default['status'] = 1; // Published
$default['promote'] = 0; // Not promoted to front page.
$default['sticky'] = 0; // Not sticky.
$default['created'] = date('g:i:sA');
$default['log'] = 'Updated at ' . date('g:i:sA') . ' via
install_create_content' ;
$default['name'] = $user->name;
$default['uid'] = $user->uid;
foreach ($properties AS $property => $value) {
$field = content_fields($property, $content_type);
if (isset($field['field_name'])) {
switch ($field['type']) {
case 'nodereference':
case 'userreference':
$default[$property] = array(array('nid' => $value));
break;
default:
if (is_array($value)) {
// Uncertain.
$default[$property][] = $value;
}
else {
$default[$property] = array(array('value' => $value));
}
}
if ($field['widget']['type'] == 'options_select' &&
isset($default[$property][0]['value'])) {
if ($field['multiple']) {
foreach ($property[0] AS $v) {
$default[$property]['keys'][$value] = $value;
}
}
else {
$default[$property]['key'] = $default[$property][0]['value'];
}
//unset($default[$property][0]);
}
unset($properties[$property]);
}
}
$node = array_merge($default, $properties);
$node = node_submit($node);
node_save($node);
return $node;
}
On 1/26/08, adrian rossouw <adrian at bryght.com> wrote:
>
> On 25 Jan 2008, at 4:56 PM, Daniel F. Kudwien wrote:
>
> >
> > It is. But it's the most advanced and flexible solution currently
> > available
> > for Drupal. Many folks have contributed to ImportExport API,
> > however the
> > module seems to be unmaintained currently. The API docs are in an
> > pre-alpha
> > state, too. So it is definitely not easy to understand, how
> > ImportExport
> > API works, and how it could work out for your requirements.
> it's a query builder. just like views / cck.
>
> and it has it's own set of _schema like hooks, which is what's
> annoying about it.
> since you get to type everything out ... again.
>
> I once wrote a install profile generator for it for drupal 4.7, but i
> didn't have the time nor energy
> to update ieapi for d5
>
>
More information about the development
mailing list