function _block_compare

Sorts active blocks by region, then by weight; sorts inactive blocks by name.

Callback for usort() in block_admin_display_prepare_blocks().

1 string reference to '_block_compare'
block_admin_display_prepare_blocks in modules/block/block.admin.inc
Prepares a list of blocks for display on the blocks administration page.

File

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

Code

function _block_compare($a, $b) {
    global $theme_key;
    // Theme should be set before calling this function, or the current theme
    // is being used.
    $theme =& drupal_static(__FUNCTION__ . ':theme');
    if (!isset($theme)) {
        $theme = $theme_key;
    }
    $regions =& drupal_static(__FUNCTION__ . ':regions');
    // We need the region list to correctly order by region.
    if (!isset($regions)) {
        $regions = array_flip(array_keys(system_region_list($theme)));
        $regions[BLOCK_REGION_NONE] = count($regions);
    }
    // Separate enabled from disabled.
    $status = $b['status'] - $a['status'];
    if ($status) {
        return $status;
    }
    // Sort by region (in the order defined by theme .info file).
    if (!empty($a['region']) && !empty($b['region']) && ($place = $regions[$a['region']] - $regions[$b['region']])) {
        return $place;
    }
    // Sort by weight, unless disabled.
    if ($a['region'] != BLOCK_REGION_NONE) {
        $weight = $a['weight'] - $b['weight'];
        if ($weight) {
            return $weight;
        }
    }
    // Sort by title.
    return strcmp($a['info'], $b['info']);
}

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