/**
* Creates a new block.
*/
function install_add_block($module, $delta, $theme, $status, $weight, $region, $visibility, $pages, $custom, $throttle, $title) {
db_query("INSERT INTO {blocks} (module, delta, theme, status, weight, region, visibility, pages, custom, throttle, title) VALUES ('%s', '%s', '%s', %d, %d, '%s', %d, '%s', %d, %d, '%s')", $module, $delta, $theme, $status, $weight, $region, $visibility, $pages, $custom, $throttle, $title);
if ($module == 'block') {
$box = db_fetch_object(db_query('SELECT * FROM {boxes} WHERE bid=%d', $delta));
db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')", $box->bid, $box->body, $box->info, $box->format);
}
}
note:
$box = db_fetch_object(db_query('SELECT * FROM {boxes} WHERE bid=%d', $delta));
db_query("INSERT INTO {boxes} (bid, body, info, format) VALUES (%d, '%s', '%s', '%s')", $box->bid, $box->body, $box->info, $box->format);
Won't $box always contain null values? How can we do a select from boxes before we actually insert into it? :-)
AFAICT, the Wizard only exports the blocks data, and not the actual box content.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 185020_install_api_custom_block.3.d5.patch | 2.96 KB | dww |
| #3 | 185020_install_api_custom_block.3.d6.patch | 1.91 KB | dww |
| #1 | patch_blocks.diff | 2.88 KB | rwohleb |
Comments
Comment #1
rwohlebHere is a patch that fixes this functionality. It also fixes an argument order issue between crud.inc and the export code for install_add_block().
Comment #2
dwwMarked #312913: Custom block creation duplicate of this, though I think the patch there (http://drupal.org/files/issues/install_profile_api-block.patch) is a cleaner, better approach to this. That patch also needs backporting to D5, which should be pretty easy.
Comment #3
dwwUpdated the previously linked patch. I didn't like how it was automatically trying to call install_add_block() since then the caller has no control over the new custom block. I think it's better how Roger López described it in the original issue, instead of how it is in his patch. So, I re-wrote the patch, added better PHPDoc comments, renamed the "$title" argument to "$description" since that's what it really is, and gave $format a default of FILTER_FORMAT_DEFAULT. With this patch, to install a custom block, it's like so:
Shockingly, for the D5 backport, I had to backport db_last_insert_id(), too. :( {boxes}.bid is auto_increment in D5, too, and there doesn't seem to be any reasonable way to get the bid natively. Using the D5 admin UI, you create the box as 1 form and submit that on its own. Then you can configure it (to give it a title), and finally enable it. So, the D5 API doesn't provide any way to get the bid directly when you add a box. *sigh*
Patches for both D5 and D6. Both tested. Any objections to any of this before I commit?
Comment #4
dwwdmitrig01 said this was RTBC, so I committed to DRUPAL-6--1 and DRUPAL-5--2.