function block_add_block_form_submit

Form submission handler for block_add_block_form().

Saves the new custom block.

See also

block_add_block_form()

block_add_block_form_validate()

File

modules/block/block.admin.inc, line 553

Code

function block_add_block_form_submit($form, &$form_state) {
    $delta = db_insert('block_custom')->fields(array(
        'body' => $form_state['values']['body']['value'],
        'info' => $form_state['values']['info'],
        'format' => $form_state['values']['body']['format'],
    ))
        ->execute();
    // Store block delta to allow other modules to work with new block.
    $form_state['values']['delta'] = $delta;
    $query = db_insert('block')->fields(array(
        'visibility',
        'pages',
        'custom',
        'title',
        'module',
        'theme',
        'status',
        'weight',
        'delta',
        'cache',
    ));
    foreach (list_themes() as $key => $theme) {
        if ($theme->status) {
            $query->values(array(
                'visibility' => (int) $form_state['values']['visibility'],
                'pages' => trim($form_state['values']['pages']),
                'custom' => (int) $form_state['values']['custom'],
                'title' => $form_state['values']['title'],
                'module' => $form_state['values']['module'],
                'theme' => $theme->name,
                'status' => 0,
                'weight' => 0,
                'delta' => $delta,
                'cache' => DRUPAL_NO_CACHE,
            ));
        }
    }
    $query->execute();
    $query = db_insert('block_role')->fields(array(
        'rid',
        'module',
        'delta',
    ));
    foreach (array_filter($form_state['values']['roles']) as $rid) {
        $query->values(array(
            'rid' => $rid,
            'module' => $form_state['values']['module'],
            'delta' => $delta,
        ));
    }
    $query->execute();
    // Store regions per theme for this block
    foreach ($form_state['values']['regions'] as $theme => $region) {
        db_merge('block')->key(array(
            'theme' => $theme,
            'delta' => $delta,
            'module' => $form_state['values']['module'],
        ))
            ->fields(array(
            'region' => $region == BLOCK_REGION_NONE ? '' : $region,
            'pages' => trim($form_state['values']['pages']),
            'status' => (int) ($region != BLOCK_REGION_NONE),
        ))
            ->execute();
    }
    drupal_set_message(t('The block has been created.'));
    cache_clear_all();
    $form_state['redirect'] = 'admin/structure/block';
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.