1

I am trying to programmatically create beans in a custom module using entity_metadata_wrapper. This is creating a bean for each installed theme. (In Drupal 7)

Is there a way I can create only one instance of the bean block?

for example in my database it creates a bean block for

  • my subtheme
  • omega
  • seven

I would like to only create one block/bean for my subtheme. I am then using mymodule_beans_block_info_alter(&$blocks, $theme, $code_blocks) {} to then change region location and other block parameters.

function bean_ctas_enable(){
    foreach(bean_ctas_info() as $bean_content){
        $bean_ids = array();
        $bean = bean_create(array('type' => 'block_cta'));
        $bean_wrap = entity_metadata_wrapper('bean', $bean);
        $bean_wrap->label->set($bean_content['label']);
        $bean_wrap->title->set($bean_content['title']);
        $bean_wrap->field_text->set(array(
            'value' => ($bean_content['field_text']),
            'format' => ('full_html'),
            ));
        $bean_wrap->field_link->set(array(
            'url' => ($bean_content['link_url']),
            'title' => 'Read More',
        ));
        $bean_wrap->save();
        $bean_ids[] = $bean_wrap->bid->value();
        //set variable to store bean ids
        variable_set('bean_ctas_bean_ids', $bean_ids);
    }
}
0

I used hook_block_info_alter(&$blocks, $theme, $code_blocks) to alter the blocks in my custom modules .module file

inside of my hook_block_info_alter i wrote an if statment

if($blocks['bean'][$key]['theme'] == variable_get('theme_default', '0')){}

to make sure I was only altering regions only for my default theme

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.