Hi,

Is it possible to create a new bean programmatically, e.g. inside a module's hook_install() function?

Thanks to beans having machine names, this would allow me to automatically create beans and place them in certain regions with the help of the context module.

An example on how to do this would be great!

Comments

bforchhammer’s picture

Status: Active » Fixed

Well, I have figured it out. It's actually fairly simple:

  $bean = bean_create(array('type' => 'my_bean_type'));
  $bean->label = 'Administrative Label';
  $bean->title = 'Bean Title';
  $bean->delta = 'bean-machine-name';
  $bean->field_block_content = array(
    'en' => array(array(
      'value' => '<p>Text</p>',
      'format' => 'wysiwyg_editor',
    )),
  );
  $bean->save();

Instead of 'en' you may want to use LANGUAGE_NONE for non-multilingual sites.

Status: Fixed » Closed (fixed)

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