2007-07-16 06:40:25 +00:00
< ? php
/**
* @ file
* Admin page callbacks for the block module .
*/
2013-01-17 04:03:30 +00:00
use Drupal\block\Plugin\Core\Entity\Block ;
2009-10-14 02:13:15 +00:00
/**
2011-11-03 10:53:06 +00:00
* Page callback : Attaches CSS for the block region demo .
*
* @ see block_menu ()
2009-10-14 02:13:15 +00:00
*/
function block_admin_demo ( $theme = NULL ) {
2011-08-12 14:27:04 +00:00
drupal_add_css ( drupal_get_path ( 'module' , 'block' ) . '/block.admin.css' );
2009-10-14 02:13:15 +00:00
return '' ;
}
2007-10-05 09:35:09 +00:00
/**
2011-11-03 10:53:06 +00:00
* Page callback : Shows the block administration page .
*
2013-01-17 04:03:30 +00:00
* @ param string $theme
* The theme to display the administration page for .
2010-07-24 17:53:55 +00:00
*
2013-01-17 04:03:30 +00:00
* @ return array
* A render array for a page containing a list of blocks .
2007-07-16 06:40:25 +00:00
*
2013-01-17 04:03:30 +00:00
* @ see block_menu ()
2007-07-16 06:40:25 +00:00
*/
2013-01-17 04:03:30 +00:00
function block_admin_display ( $theme ) {
2013-01-19 04:58:23 +00:00
return drupal_container () -> get ( 'plugin.manager.entity' )
-> getListController ( 'block' )
-> render ( $theme );
2007-07-16 06:40:25 +00:00
}
/**
2013-01-17 04:03:30 +00:00
* Page callback : Build the block instance add form .
2010-07-24 17:53:55 +00:00
*
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
* @ param string $plugin_id
* The plugin ID for the block instance .
* @ param string $theme
2013-01-17 04:03:30 +00:00
* The name of the theme for the block instance .
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
*
2013-01-17 04:03:30 +00:00
* @ return array
* The block instance edit form .
2007-07-16 06:40:25 +00:00
*/
2013-01-17 04:03:30 +00:00
function block_admin_add ( $plugin_id , $theme ) {
$entity = entity_create ( 'block' , array (
'plugin' => $plugin_id ,
'theme' => $theme ,
));
return entity_get_form ( $entity );
2007-07-16 06:40:25 +00:00
}
2010-07-24 17:53:55 +00:00
/**
2013-01-17 04:03:30 +00:00
* Page callback : Build the block instance edit form .
2010-07-24 17:53:55 +00:00
*
2013-01-17 04:03:30 +00:00
* @ param \Drupal\block\Plugin\Core\Entity\Block $entity
* The block instance .
2010-07-24 17:53:55 +00:00
*
2013-01-17 04:03:30 +00:00
* @ return array
* The block instance edit form .
2010-07-24 17:53:55 +00:00
*/
2013-01-17 04:03:30 +00:00
function block_admin_edit ( Block $entity ) {
// Get the theme for the page title.
$admin_theme = config ( 'system.theme' ) -> get ( 'admin' );
$themes = list_themes ();
$theme_key = $entity -> get ( 'theme' );
$theme = $themes [ $theme_key ];
// Use meaningful titles for the main site and administrative themes.
$theme_title = $theme -> info [ 'name' ];
if ( $theme_key == variable_get ( 'theme_default' , 'stark' )) {
$theme_title = t ( '!theme (default theme)' , array ( '!theme' => $theme_title ));
}
elseif ( $admin_theme && $theme_key == $admin_theme ) {
$theme_title = t ( '!theme (administration theme)' , array ( '!theme' => $theme_title ));
2007-07-16 06:40:25 +00:00
}
2013-01-17 04:03:30 +00:00
// Get the block subject for the page title.
2013-01-20 20:06:28 +00:00
drupal_set_title ( t ( " Configure %label block in %theme " , array ( '%label' => $entity -> label (), '%theme' => $theme_title )), PASS_THROUGH );
2013-01-17 04:03:30 +00:00
return entity_get_form ( $entity );
2007-07-16 06:40:25 +00:00
}
/**
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
* Form constructor for the block instance deletion form .
2011-11-03 10:53:06 +00:00
*
2013-01-17 04:03:30 +00:00
* @ param \Drupal\block\Plugin\Core\Entity\Block $entity
* The block instance .
2010-07-24 17:53:55 +00:00
*
2011-11-03 10:53:06 +00:00
* @ see block_menu ()
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
* @ see block_admin_block_delete_submit ()
2007-07-16 06:40:25 +00:00
*/
2013-01-17 04:03:30 +00:00
function block_admin_block_delete ( array $form , array & $form_state , Block $entity ) {
$form [ 'id' ] = array ( '#type' => 'value' , '#value' => $entity -> id ());
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
2013-01-17 04:03:30 +00:00
return confirm_form ( $form , t ( 'Are you sure you want to delete the block %name?' , array ( '%name' => $entity -> label ())), 'admin/structure/block' , '' , t ( 'Delete' ), t ( 'Cancel' ));
2007-07-16 06:40:25 +00:00
}
/**
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
* Form submission handler for block_admin_block_delete () .
2010-07-24 17:53:55 +00:00
*
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
* @ see block_admin_block_delete ()
2007-07-16 06:40:25 +00:00
*/
Issue #1535868 by EclipseGc, tim.plunkett, xjm, Jody Lynn, sdboyer, naxoc, tizzo, effulgentsia, dawehner, disasm, beejeebus: Convert all blocks into plugins.
2013-01-04 17:05:13 +00:00
function block_admin_block_delete_submit ( $form , & $form_state ) {
2013-01-17 04:03:30 +00:00
$entity = entity_load ( 'block' , $form_state [ 'values' ][ 'id' ]);
drupal_set_message ( t ( 'The block %name has been removed.' , array ( '%name' => $entity -> label ())));
$form_state [ 'redirect' ] = 'admin/structure/block/list/block_plugin_ui:' . $entity -> get ( 'theme' );
$entity -> delete ();
2007-07-16 06:40:25 +00:00
}
2007-09-01 05:31:09 +00:00
/**
2010-08-30 00:22:03 +00:00
* Processes variables for block - admin - display - form . tpl . php .
2007-09-01 05:31:09 +00:00
*
* The $variables array contains the following arguments :
* - $form
*
* @ see block - admin - display . tpl . php
* @ see theme_block_admin_display ()
*/
2007-10-05 09:35:09 +00:00
function template_preprocess_block_admin_display_form ( & $variables ) {
2010-08-30 00:22:03 +00:00
$variables [ 'block_regions' ] = $variables [ 'form' ][ 'block_regions' ][ '#value' ];
if ( isset ( $variables [ 'block_regions' ][ BLOCK_REGION_NONE ])) {
$variables [ 'block_regions' ][ BLOCK_REGION_NONE ] = t ( 'Disabled' );
}
2007-09-01 05:31:09 +00:00
2010-08-30 00:22:03 +00:00
foreach ( $variables [ 'block_regions' ] as $key => $value ) {
2007-11-14 09:50:00 +00:00
// Initialize an empty array for the region.
$variables [ 'block_listing' ][ $key ] = array ();
2007-09-01 05:31:09 +00:00
}
2007-11-14 09:50:00 +00:00
// Initialize disabled blocks array.
$variables [ 'block_listing' ][ BLOCK_REGION_NONE ] = array ();
2010-08-30 00:22:03 +00:00
// Add each block in the form to the appropriate place in the block listing.
foreach ( element_children ( $variables [ 'form' ][ 'blocks' ]) as $i ) {
$block = & $variables [ 'form' ][ 'blocks' ][ $i ];
// Fetch the region for the current block.
2010-09-24 21:36:22 +00:00
$region = ( isset ( $block [ 'region' ][ '#default_value' ]) ? $block [ 'region' ][ '#default_value' ] : BLOCK_REGION_NONE );
2010-08-30 00:22:03 +00:00
// Set special classes needed for table drag and drop.
$block [ 'region' ][ '#attributes' ][ 'class' ] = array ( 'block-region-select' , 'block-region-' . $region );
$block [ 'weight' ][ '#attributes' ][ 'class' ] = array ( 'block-weight' , 'block-weight-' . $region );
$variables [ 'block_listing' ][ $region ][ $i ] = new stdClass ();
$variables [ 'block_listing' ][ $region ][ $i ] -> row_class = ! empty ( $block [ '#attributes' ][ 'class' ]) ? implode ( ' ' , $block [ '#attributes' ][ 'class' ]) : '' ;
$variables [ 'block_listing' ][ $region ][ $i ] -> block_modified = ! empty ( $block [ '#attributes' ][ 'class' ]) && in_array ( 'block-modified' , $block [ '#attributes' ][ 'class' ]);
$variables [ 'block_listing' ][ $region ][ $i ] -> block_title = drupal_render ( $block [ 'info' ]);
$variables [ 'block_listing' ][ $region ][ $i ] -> region_select = drupal_render ( $block [ 'region' ]) . drupal_render ( $block [ 'theme' ]);
$variables [ 'block_listing' ][ $region ][ $i ] -> weight_select = drupal_render ( $block [ 'weight' ]);
2012-10-09 19:49:07 +00:00
$variables [ 'block_listing' ][ $region ][ $i ] -> operations = drupal_render ( $block [ 'operations' ]);
2010-08-30 00:22:03 +00:00
$variables [ 'block_listing' ][ $region ][ $i ] -> printed = FALSE ;
2007-09-01 05:31:09 +00:00
}
2009-02-03 18:55:32 +00:00
$variables [ 'form_submit' ] = drupal_render_children ( $variables [ 'form' ]);
2007-09-01 05:31:09 +00:00
}