diff --git a/core/lib/Drupal/Core/Block/BlockBase.php.orig b/core/lib/Drupal/Core/Block/BlockBase.php.orig deleted file mode 100644 index 8c97809..0000000 --- a/core/lib/Drupal/Core/Block/BlockBase.php.orig +++ /dev/null @@ -1,307 +0,0 @@ -configuration['label'])) { - return $this->configuration['label']; - } - - $definition = $this->getPluginDefinition(); - // Cast the admin label to a string since it is an object. - // @see \Drupal\Core\StringTranslation\TranslationWrapper - return (string) $definition['admin_label']; - } - - /** - * {@inheritdoc} - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->setConfiguration($configuration); - } - - /** - * {@inheritdoc} - */ - public function getConfiguration() { - return $this->configuration; - } - - /** - * {@inheritdoc} - */ - public function setConfiguration(array $configuration) { - $this->configuration = NestedArray::mergeDeep( - $this->baseConfigurationDefaults(), - $this->defaultConfiguration(), - $configuration - ); - } - - /** - * Returns generic default configuration for block plugins. - * - * @return array - * An associative array with the default configuration. - */ - protected function baseConfigurationDefaults() { - return array( - 'id' => $this->getPluginId(), - 'label' => '', - 'provider' => $this->pluginDefinition['provider'], - 'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE, - 'cache' => array( - // Blocks are cacheable by default. - 'max_age' => Cache::PERMANENT, - ), - ); - } - - /** - * {@inheritdoc} - */ - public function defaultConfiguration() { - return array(); - } - - /** - * {@inheritdoc} - */ - public function setConfigurationValue($key, $value) { - $this->configuration[$key] = $value; - } - - /** - * {@inheritdoc} - */ - public function calculateDependencies() { - return array(); - } - - /** - * {@inheritdoc} - */ - public function access(AccountInterface $account, $return_as_object = FALSE) { - $access = $this->blockAccess($account); - return $return_as_object ? $access : $access->isAllowed(); - } - - /** - * Indicates whether the block should be shown. - * - * Blocks with specific access checking should override this method rather - * than access(), in order to avoid repeating the handling of the - * $return_as_object argument. - * - * @param \Drupal\Core\Session\AccountInterface $account - * The user session for which to check access. - * - * @return \Drupal\Core\Access\AccessResult - * The access result. - * - * @see self::access() - */ - protected function blockAccess(AccountInterface $account) { - // By default, the block is visible. - return AccessResult::allowed(); - } - - /** - * {@inheritdoc} - * - * Creates a generic configuration form for all block types. Individual - * block plugins can add elements to this form by overriding - * BlockBase::blockForm(). Most block plugins should not override this - * method unless they need to alter the generic form elements. - * - * @see \Drupal\Core\Block\BlockBase::blockForm() - */ - public function buildConfigurationForm(array $form, FormStateInterface $form_state) { - $definition = $this->getPluginDefinition(); - $form['provider'] = array( - '#type' => 'value', - '#value' => $definition['provider'], - ); - - $form['admin_label'] = array( - '#type' => 'item', - '#title' => $this->t('Block description'), - '#plain_text' => $definition['admin_label'], - ); - $form['label'] = array( - '#type' => 'textfield', - '#title' => $this->t('Title'), - '#maxlength' => 255, - '#default_value' => $this->label(), - '#required' => TRUE, - ); - $form['label_display'] = array( - '#type' => 'checkbox', - '#title' => $this->t('Display title'), - '#default_value' => ($this->configuration['label_display'] === BlockInterface::BLOCK_LABEL_VISIBLE), - '#return_value' => BlockInterface::BLOCK_LABEL_VISIBLE, - ); - // Identical options to the ones for page caching. - // @see \Drupal\system\Form\PerformanceForm::buildForm() - $period = array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 86400); - $period = array_map(array(\Drupal::service('date.formatter'), 'formatInterval'), array_combine($period, $period)); - $period[0] = '<' . $this->t('no caching') . '>'; - $period[\Drupal\Core\Cache\Cache::PERMANENT] = $this->t('Forever'); - $form['cache'] = array( - '#type' => 'details', - '#title' => $this->t('Cache settings'), - ); - $form['cache']['max_age'] = array( - '#type' => 'select', - '#title' => $this->t('Maximum age'), - '#description' => $this->t('The maximum time this block may be cached.'), - '#default_value' => $this->configuration['cache']['max_age'], - '#options' => $period, - ); - - // Add plugin-specific settings for this block type. - $form += $this->blockForm($form, $form_state); - return $form; - } - - /** - * {@inheritdoc} - */ - public function blockForm($form, FormStateInterface $form_state) { - return array(); - } - - /** - * {@inheritdoc} - * - * Most block plugins should not override this method. To add validation - * for a specific block type, override BlockBase::blockValidate(). - * - * @see \Drupal\Core\Block\BlockBase::blockValidate() - */ - public function validateConfigurationForm(array &$form, FormStateInterface $form_state) { - // Remove the admin_label form item element value so it will not persist. - $form_state->unsetValue('admin_label'); - - $this->blockValidate($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function blockValidate($form, FormStateInterface $form_state) {} - - /** - * {@inheritdoc} - * - * Most block plugins should not override this method. To add submission - * handling for a specific block type, override BlockBase::blockSubmit(). - * - * @see \Drupal\Core\Block\BlockBase::blockSubmit() - */ - public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { - // Process the block's submission handling if no errors occurred only. - if (!$form_state->getErrors()) { - $this->configuration['label'] = $form_state->getValue('label'); - $this->configuration['label_display'] = $form_state->getValue('label_display'); - $this->configuration['provider'] = $form_state->getValue('provider'); - $this->configuration['cache'] = $form_state->getValue('cache'); - $this->blockSubmit($form, $form_state); - } - } - - /** - * {@inheritdoc} - */ - public function blockSubmit($form, FormStateInterface $form_state) {} - - /** - * {@inheritdoc} - */ - public function getMachineNameSuggestion() { - $definition = $this->getPluginDefinition(); - $admin_label = $definition['admin_label']; - - // @todo This is basically the same as what is done in - // \Drupal\system\MachineNameController::transliterate(), so it might make - // sense to provide a common service for the two. - $transliterated = $this->transliteration()->transliterate($admin_label, LanguageInterface::LANGCODE_DEFAULT, '_'); - $transliterated = Unicode::strtolower($transliterated); - - $transliterated = preg_replace('@[^a-z0-9_.]+@', '', $transliterated); - - return $transliterated; - } - - /** - * {@inheritdoc} - */ - public function getCacheMaxAge() { - $max_age = parent::getCacheMaxAge(); - // @todo Configurability of this will be removed in - // https://www.drupal.org/node/2458763. - return Cache::mergeMaxAges($max_age, (int) $this->configuration['cache']['max_age']); - } - - /** - * Wraps the transliteration service. - * - * @return \Drupal\Component\Transliteration\TransliterationInterface - */ - protected function transliteration() { - if (!$this->transliteration) { - $this->transliteration = \Drupal::transliteration(); - } - return $this->transliteration; - } - - /** - * Sets the transliteration service. - * - * @param \Drupal\Component\Transliteration\TransliterationInterface $transliteration - * The transliteration service. - */ - public function setTransliteration(TransliterationInterface $transliteration) { - $this->transliteration = $transliteration; - } - -} diff --git a/core/modules/block/src/BlockListBuilder.php.orig b/core/modules/block/src/BlockListBuilder.php.orig deleted file mode 100644 index b92e7ae..0000000 --- a/core/modules/block/src/BlockListBuilder.php.orig +++ /dev/null @@ -1,385 +0,0 @@ -themeManager = $theme_manager; - $this->formBuilder = $form_builder; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity.manager')->getStorage($entity_type->id()), - $container->get('theme.manager'), - $container->get('form_builder') - ); - } - - /** - * {@inheritdoc} - * - * @param string|null $theme - * (optional) The theme to display the blocks for. If NULL, the current - * theme will be used. - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request. - * - * @return array - * The block list as a renderable array. - */ - public function render($theme = NULL, Request $request = NULL) { - $this->request = $request; - $this->theme = $theme; - - return $this->formBuilder->getForm($this); - } - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'block_admin_display_form'; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state) { - $form['#attached']['library'][] = 'core/drupal.tableheader'; - $form['#attached']['library'][] = 'block/drupal.block'; - $form['#attached']['library'][] = 'block/drupal.block.admin'; - $form['#attributes']['class'][] = 'clearfix'; - - // Build the form tree. - $form['blocks'] = $this->buildBlocksForm(); - - $form['actions'] = array( - '#tree' => FALSE, - '#type' => 'actions', - ); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => $this->t('Save blocks'), - '#button_type' => 'primary', - ); - - return $form; - } - - /** - * Builds the main "Blocks" portion of the form. - * - * @return array - */ - protected function buildBlocksForm() { - // Build blocks first for each region. - $blocks = []; - $entities = $this->load(); - /** @var \Drupal\block\BlockInterface[] $entities */ - foreach ($entities as $entity_id => $entity) { - $definition = $entity->getPlugin()->getPluginDefinition(); - $blocks[$entity->getRegion()][$entity_id] = array( - 'label' => $entity->label(), - 'entity_id' => $entity_id, - 'weight' => $entity->getWeight(), - 'entity' => $entity, - 'category' => $definition['category'], - ); - } - - $form = array( - '#type' => 'table', - '#header' => array( - $this->t('Block'), - $this->t('Category'), - $this->t('Region'), - $this->t('Weight'), - $this->t('Operations'), - ), - '#attributes' => array( - 'id' => 'blocks', - ), - ); - - // Weights range from -delta to +delta, so delta should be at least half - // of the amount of blocks present. This makes sure all blocks in the same - // region get an unique weight. - $weight_delta = round(count($entities) / 2); - - $placement = FALSE; - if ($this->request->query->has('block-placement')) { - $placement = $this->request->query->get('block-placement'); - $form['#attached']['drupalSettings']['blockPlacement'] = $placement; - } - - // Loop over each region and build blocks. - $regions = $this->systemRegionList($this->getThemeName(), REGIONS_VISIBLE); - $block_regions_with_disabled = $regions + array(BlockInterface::BLOCK_REGION_NONE => $this->t('Disabled', array(), array('context' => 'Plural'))); - foreach ($block_regions_with_disabled as $region => $title) { - $form['#tabledrag'][] = array( - 'action' => 'match', - 'relationship' => 'sibling', - 'group' => 'block-region-select', - 'subgroup' => 'block-region-' . $region, - 'hidden' => FALSE, - ); - $form['#tabledrag'][] = array( - 'action' => 'order', - 'relationship' => 'sibling', - 'group' => 'block-weight', - 'subgroup' => 'block-weight-' . $region, - ); - - $form['region-' . $region] = array( - '#attributes' => array( - 'class' => array('region-title', 'region-title-' . $region), - 'no_striping' => TRUE, - ), - ); - $form['region-' . $region]['title'] = array( - '#prefix' => $region != BlockInterface::BLOCK_REGION_NONE ? $title : $block_regions_with_disabled[$region], - '#type' => 'link', - '#title' => $this->t('Place block in the %region region', ['%region' => $block_regions_with_disabled[$region]]), - '#url' => Url::fromRoute('block.admin_library', ['theme' => $this->getThemeName()], ['query' => ['region' => $region]]), - '#wrapper_attributes' => array( - 'colspan' => 5, - ), - '#attributes' => [ - 'class' => ['use-ajax', 'button', 'button--small'], - 'data-dialog-type' => 'modal', - 'data-dialog-options' => Json::encode([ - 'width' => 700, - ]), - ], - ); - - $form['region-' . $region . '-message'] = array( - '#attributes' => array( - 'class' => array( - 'region-message', - 'region-' . $region . '-message', - empty($blocks[$region]) ? 'region-empty' : 'region-populated', - ), - ), - ); - $form['region-' . $region . '-message']['message'] = array( - '#markup' => '' . $this->t('No blocks in this region') . '', - '#wrapper_attributes' => array( - 'colspan' => 5, - ), - ); - - if (isset($blocks[$region])) { - foreach ($blocks[$region] as $info) { - $entity_id = $info['entity_id']; - - $form[$entity_id] = array( - '#attributes' => array( - 'class' => array('draggable'), - ), - ); - if ($placement && $placement == Html::getClass($entity_id)) { - $form[$entity_id]['#attributes']['class'][] = 'color-success'; - $form[$entity_id]['#attributes']['class'][] = 'js-block-placed'; - } - $form[$entity_id]['info'] = array( - '#plain_text' => $info['label'], - '#wrapper_attributes' => array( - 'class' => array('block'), - ), - ); - $form[$entity_id]['type'] = array( - '#markup' => $info['category'], - ); - $form[$entity_id]['region-theme']['region'] = array( - '#type' => 'select', - '#default_value' => $region, - '#empty_value' => BlockInterface::BLOCK_REGION_NONE, - '#title' => $this->t('Region for @block block', array('@block' => $info['label'])), - '#title_display' => 'invisible', - '#options' => $regions, - '#attributes' => array( - 'class' => array('block-region-select', 'block-region-' . $region), - ), - '#parents' => array('blocks', $entity_id, 'region'), - ); - $form[$entity_id]['region-theme']['theme'] = array( - '#type' => 'hidden', - '#value' => $this->getThemeName(), - '#parents' => array('blocks', $entity_id, 'theme'), - ); - $form[$entity_id]['weight'] = array( - '#type' => 'weight', - '#default_value' => $info['weight'], - '#delta' => $weight_delta, - '#title' => $this->t('Weight for @block block', array('@block' => $info['label'])), - '#title_display' => 'invisible', - '#attributes' => array( - 'class' => array('block-weight', 'block-weight-' . $region), - ), - ); - $form[$entity_id]['operations'] = $this->buildOperations($info['entity']); - } - } - } - - // Do not allow disabling the main system content block when it is present. - if (isset($form['system_main']['region'])) { - $form['system_main']['region']['#required'] = TRUE; - } - return $form; - } - - /** - * Gets the name of the theme used for this block listing. - * - * @return string - * The name of the theme. - */ - protected function getThemeName() { - // If no theme was specified, use the current theme. - if (!$this->theme) { - $this->theme = $this->themeManager->getActiveTheme()->getName(); - } - return $this->theme; - } - - /** - * {@inheritdoc} - */ - protected function getEntityIds() { - return $this->getStorage()->getQuery() - ->condition('theme', $this->getThemeName()) - ->sort($this->entityType->getKey('id')) - ->execute(); - } - - /** - * {@inheritdoc} - */ - public function getDefaultOperations(EntityInterface $entity) { - $operations = parent::getDefaultOperations($entity); - - if (isset($operations['edit'])) { - $operations['edit']['title'] = $this->t('Configure'); - } - - return $operations; - } - - /** - * {@inheritdoc} - */ - public function validateForm(array &$form, FormStateInterface $form_state) { - // No validation. - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $entities = $this->storage->loadMultiple(array_keys($form_state->getValue('blocks'))); - /** @var \Drupal\block\BlockInterface[] $entities */ - foreach ($entities as $entity_id => $entity) { - $entity_values = $form_state->getValue(array('blocks', $entity_id)); - $entity->setWeight($entity_values['weight']); - $entity->setRegion($entity_values['region']); - if ($entity->getRegion() == BlockInterface::BLOCK_REGION_NONE) { - $entity->disable(); - } - else { - $entity->enable(); - } - $entity->save(); - } - drupal_set_message(t('The block settings have been updated.')); - - // Remove any previously set block placement. - $this->request->query->remove('block-placement'); - } - - /** - * Wraps system_region_list(). - */ - protected function systemRegionList($theme, $show = REGIONS_ALL) { - return system_region_list($theme, $show); - } - -} diff --git a/core/modules/block/src/BlockViewBuilder.php b/core/modules/block/src/BlockViewBuilder.php index 9a582352..6fc5b2f 100644 --- a/core/modules/block/src/BlockViewBuilder.php +++ b/core/modules/block/src/BlockViewBuilder.php @@ -16,6 +16,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Language\LanguageManagerInterface; +use Drupal\Core\Plugin\ContextAwarePluginInterface; use Drupal\Core\Render\Element; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -104,7 +105,8 @@ public function viewMultiple(array $entities = array(), $view_mode = 'full', $la // Allow altering of cacheability metadata or setting #create_placeholder. $this->moduleHandler->alter(['block_build', "block_build_" . $plugin->getBaseId()], $build[$entity_id], $plugin); - if ($plugin instanceof MainContentBlockPluginInterface) { + if ($plugin instanceof MainContentBlockPluginInterface + || ($plugin instanceof ContextAwarePluginInterface && !empty($plugin->getContextMapping()))) { // Immediately build a #pre_render-able block, since this block cannot // be built lazily. $build[$entity_id] += static::buildPreRenderableBlock($entity, $this->moduleHandler()); diff --git a/core/modules/block/src/Controller/BlockLibraryController.php.orig b/core/modules/block/src/Controller/BlockLibraryController.php.orig deleted file mode 100644 index 972dd73..0000000 --- a/core/modules/block/src/Controller/BlockLibraryController.php.orig +++ /dev/null @@ -1,178 +0,0 @@ -blockManager = $block_manager; - $this->routeMatch = $route_match; - $this->localActionManager = $local_action_manager; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('plugin.manager.block'), - $container->get('current_route_match'), - $container->get('plugin.manager.menu.local_action') - ); - } - - /** - * Shows a list of blocks that can be added to a theme's layout. - * - * @param \Symfony\Component\HttpFoundation\Request $request - * The current request. - * @param string $theme - * Theme key of the block list. - * - * @return array - * A render array as expected by the renderer. - */ - public function listBlocks(Request $request, $theme) { - // Since modals do not render any other part of the page, we need to render - // them manually as part of this listing. - if ($request->query->get(MainContentViewSubscriber::WRAPPER_FORMAT) === 'drupal_modal') { - $build['local_actions'] = $this->buildLocalActions(); - } - - $headers = [ - ['data' => $this->t('Block')], - ['data' => $this->t('Category')], - ['data' => $this->t('Operations')], - ]; - - // Only add blocks which work without any available context. - $definitions = $this->blockManager->getDefinitionsForContexts(); - // Order by category, and then by admin label. - $definitions = $this->blockManager->getSortedDefinitions($definitions); - - $region = $request->query->get('region'); - $rows = []; - foreach ($definitions as $plugin_id => $plugin_definition) { - $row = []; - $row['title']['data'] = [ - '#markup' => $plugin_definition['admin_label'], - '#prefix' => '
', - '#suffix' => '
', - ]; - $row['category']['data'] = $plugin_definition['category']; - $links['add'] = [ - 'title' => $this->t('Place block'), - 'url' => Url::fromRoute('block.admin_add', ['plugin_id' => $plugin_id, 'theme' => $theme]), - 'attributes' => [ - 'class' => ['use-ajax'], - 'data-dialog-type' => 'modal', - 'data-dialog-options' => Json::encode([ - 'width' => 700, - ]), - ], - ]; - if ($region) { - $links['add']['query']['region'] = $region; - } - $row['operations']['data'] = [ - '#type' => 'operations', - '#links' => $links, - ]; - $rows[] = $row; - } - - $build['#attached']['library'][] = 'block/drupal.block.admin'; - - $build['filter'] = [ - '#type' => 'search', - '#title' => $this->t('Filter'), - '#title_display' => 'invisible', - '#size' => 30, - '#placeholder' => $this->t('Filter by block name'), - '#attributes' => [ - 'class' => ['block-filter-text'], - 'data-element' => '.block-add-table', - 'title' => $this->t('Enter a part of the block name to filter by.'), - ], - ]; - - $build['blocks'] = [ - '#type' => 'table', - '#header' => $headers, - '#rows' => $rows, - '#empty' => $this->t('No blocks available.'), - '#attributes' => [ - 'class' => ['block-add-table'], - ], - ]; - - return $build; - } - - /** - * Builds the local actions for this listing. - * - * @return array - * An array of local actions for this listing. - */ - protected function buildLocalActions() { - $build = $this->localActionManager->getActionsForRoute($this->routeMatch->getRouteName()); - // Without this workaround, the action links will be rendered as
  • with - // no wrapping