Question

Created installation profile and need to make some custom block be visible on particular pages.

In profile_name.install : profile_name_install():

$values = array( 
    array( 
        'module' => 'my_custom_module',  
        'delta' => 'my_block', 
        'theme' => $default_theme,  
        'status' => 1,  
        'weight' => 0, 
        'region' => 'help',  
        'pages' => "admin/page1\nadmin/page2\nadmin/page3",  
        'cache' => 0,  
    ),
);

$query = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
foreach ($values as $record) { 
    $query->values($record); 
} 
$query->execute();

After installation those pages in block configuration are set to 'All pages except those listed', but I need them to be in 'Only the listed pages';

What extra values should I add in $values array? Is it correct way to set many pages with \n separator?

Was it helpful?

Solution

Per the hook_block_info() docs, you need to add visibility:

array( 
    'module' => 'my_custom_module',  
    'delta' => 'my_block', 
    'theme' => $default_theme,  
    'status' => 1,  
    'weight' => 0, 
    'region' => 'help',  
    'pages' => "admin/page1\nadmin/page2\nadmin/page3",  
    'cache' => 0,  
    'visibility' => BLOCK_VISIBILITY_LISTED
),
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top