getListController('block') ->render($theme); } /** * Page callback: Build the block instance add form. * * @param string $plugin_id * The plugin ID for the block instance. * @param string $theme * The name of the theme for the block instance. * * @return array * The block instance edit form. */ function block_admin_add($plugin_id, $theme) { $entity = entity_create('block', array( 'plugin' => $plugin_id, 'theme' => $theme, )); return entity_get_form($entity); } /** * Page callback: Build the block instance edit form. * * @param \Drupal\block\Plugin\Core\Entity\Block $entity * The block instance. * * @return array * The block instance edit form. */ 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 == config('system.theme')->get('default')) { $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)); } // Get the block label for the page title. drupal_set_title(t("Configure %label block in %theme", array('%label' => $entity->label(), '%theme' => $theme_title)), PASS_THROUGH); return entity_get_form($entity); } /** * Prepares variables for block admin display form templates. * * Default template: block-admin-display-form.html.twig. * * @param array $variables * An associative array containing: * - form: A render element representing the form. */ function template_preprocess_block_admin_display_form(&$variables) { $variables['block_regions'] = $variables['form']['block_regions']['#value']; if (isset($variables['block_regions'][BLOCK_REGION_NONE])) { $variables['block_regions'][BLOCK_REGION_NONE] = t('Disabled'); } foreach ($variables['block_regions'] as $key => $value) { // Initialize an empty array for the region. $variables['block_listing'][$key] = array(); } $default_attributes = new Attribute(array('class' => array('draggable'))); $row = 0; // Initialize disabled blocks array. $variables['block_listing'][BLOCK_REGION_NONE] = array(); // 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. $region = (isset($block['region']['#default_value']) ? $block['region']['#default_value'] : BLOCK_REGION_NONE); // 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]->attributes = clone $default_attributes; $variables['block_listing'][$region][$i]->attributes['class'][] = $row % 2 == 0 ? 'odd' : 'even'; $row++; if(!empty($block['#attributes']['class'])) { $variables['block_listing'][$region][$i]->attributes['class'][] = implode(' ', $block['#attributes']['class']); } $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 = $block['info']; $variables['block_listing'][$region][$i]->region_select = array( 'region' => array( 'data' => $block['region'], '#weight' => 1, ), 'theme' => array( 'data' => $block['theme'], '#weight' => 2, ), ); $variables['block_listing'][$region][$i]->weight_select = $block['weight']; $variables['block_listing'][$region][$i]->operations = $block['operations']; $variables['block_listing'][$region][$i]->printed = FALSE; } }