Profiler can create nodes, terms, users, etc. It would be really great if it could create custom blocks as well.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jyee’s picture

First attempt to provide the functionality is attached.

jyee’s picture

Status: Active » Needs review

oops. forgot to set status to needs review.

mariacha1’s picture

Status: Needs review » Needs work

It's a good start, but for blocks, since there isn't any built-in validation like there is with node_save(), a wrongly-entered value will fail the install with an ungraceful pdo error. Here's one of the ways I got it to die:

; a wrong type block
blocks[third][body] = Here's the body
blocks[third][info] = New info
blocks[third][format] = full_html
blocks[third][theme] = junk_theme
blocks[third][status] = test
blocks[third][weight] = test
blocks[third][region] = 5
blocks[third][custom] = 15
blocks[third][visibility] = -4
blocks[third][pages] = junk'page
blocks[third][title] = Here's a junk string
blocks[third][cache] = -1

Second, there's an easily-fixable bug. There should be a default value in the 'format' field. So this code:
'format' => $block['format'],
should be:
'format' => isset($block['format'])? $block['format'] : 'full_html',

Finally, the "info" field in the blocks_custom table must be unique. Is there a way to check for that before trying to save the block?

I can attempt to fix these things later...

jyee’s picture

Thanks, I can take a look into error checking, but theoretically, content is being created by a developer, so i'm not sure how far down the rabbit hole we should go on that.

I'll update it to set the default format to plain_text, as that exists in both minimal and typical install profiles (full_html only exists in typical) and should be a safer default.

As for the unique info field, we can check for that, by storing previous block info and validating against it. I did something similar in the nested menu node creation, but I'm concerned that continued use of that process could start consuming much more memory and become a problem.

jyee’s picture

Status: Needs work » Needs review
FileSize
2.72 KB

Updated patch to use plain_text when a format isn't declared. I've also added a check for the unique info field.

There's a change to execute the block insert within the foreach loop. While executing once at the end is technically more efficient, it creates a problem where a single record failure could fail the entire set of blocks.

jhedstrom’s picture

Status: Needs review » Needs work

This functionality/syntax needs to be called out in the README.

jhedstrom’s picture

Status: Needs work » Needs review
FileSize
3.68 KB

Here's some help text for the README.

q0rban’s picture

jyee, feel free to commit this after you have reviewed / tested.

jyee’s picture

Status: Needs review » Fixed

@jhedstrom thanks for the readme update. This has been committed to 7.x-2.x.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.