From 8308c9ccbc12da00ef330990cf2b530e48c98e25 Mon Sep 17 00:00:00 2001
From: William Hearn <sylus1984@gmail.com>
Date: Tue, 20 Sep 2016 19:59:22 -0400
Subject: [PATCH] Issue #2296437 by rlmumford, josebc, sylus, dsnopek, mglaman:
 Implement style plugin type

---
 panels.routing.yml                                 |  7 ++
 panels.services.yml                                |  3 +
 src/Annotation/PanelsStyle.php                     | 35 ++++++++
 src/Form/PanelsBlockConfigureFormBase.php          | 14 ++++
 src/Form/PanelsBlockEditPanelsStyleForm.php        | 93 ++++++++++++++++++++++
 src/Form/PanelsContentForm.php                     | 14 +++-
 ...reFormBase.php => PanelsRegionEditFormBase.php} | 89 +++++++--------------
 src/Form/PanelsRegionEditPanelsStyleForm.php       | 29 +++++++
 .../DisplayBuilder/StandardDisplayBuilder.php      | 45 +++--------
 src/Plugin/DisplayVariant/PanelsDisplayVariant.php | 47 ++++++++++-
 src/Plugin/PanelsPattern/DefaultPattern.php        | 12 +++
 src/Plugin/PanelsStyle/PanelsStyleBase.php         | 54 +++++++++++++
 src/Plugin/PanelsStyle/PanelsStyleDefault.php      | 19 +++++
 src/Plugin/PanelsStyle/PanelsStyleInterface.php    | 43 ++++++++++
 src/Plugin/PanelsStyle/PanelsStyleList.php         | 35 ++++++++
 .../PanelsStyle/PanelsStylePluginManager.php       | 39 +++++++++
 .../PanelsStylePluginManagerInterface.php          | 16 ++++
 tests/src/Unit/PanelsDisplayVariantTest.php        | 10 ++-
 18 files changed, 508 insertions(+), 96 deletions(-)
 create mode 100644 src/Annotation/PanelsStyle.php
 create mode 100644 src/Form/PanelsBlockEditPanelsStyleForm.php
 copy src/Form/{PanelsBlockConfigureFormBase.php => PanelsRegionEditFormBase.php} (58%)
 create mode 100644 src/Form/PanelsRegionEditPanelsStyleForm.php
 create mode 100644 src/Plugin/PanelsStyle/PanelsStyleBase.php
 create mode 100644 src/Plugin/PanelsStyle/PanelsStyleDefault.php
 create mode 100644 src/Plugin/PanelsStyle/PanelsStyleInterface.php
 create mode 100644 src/Plugin/PanelsStyle/PanelsStyleList.php
 create mode 100644 src/Plugin/PanelsStyle/PanelsStylePluginManager.php
 create mode 100644 src/Plugin/PanelsStyle/PanelsStylePluginManagerInterface.php

diff --git panels.routing.yml panels.routing.yml
index 101a808..61091d3 100644
--- panels.routing.yml
+++ panels.routing.yml
@@ -26,3 +26,10 @@ panels.delete_block:
     _title: 'Delete block'
   requirements:
     _ctools_access: 'machine_name'
+panels.region_edit_style:
+  path: '/admin/structure/panels/{tempstore_id}/{machine_name}/region/edit/{region}/style'
+  defaults:
+    _form: 'Drupal\panels\Form\PanelsRegionEditPanelsStyleForm'
+    _title: 'Edit region style settings'
+  requirements:
+     _ctools_access: 'machine_name'
\ No newline at end of file
diff --git panels.services.yml panels.services.yml
index a54a1d7..9bfaf14 100644
--- panels.services.yml
+++ panels.services.yml
@@ -5,6 +5,9 @@ services:
   plugin.manager.panels.pattern:
     class: Drupal\panels\PanelsPatternManager
     parent: default_plugin_manager
+  plugin.manager.panels.style:
+    class: Drupal\panels\Plugin\PanelsStyle\PanelsStylePluginManager
+    arguments: ['@container.namespaces', '@cache.discovery', '@module_handler']
   panels.display_manager:
     class: Drupal\panels\PanelsDisplayManager
     arguments: ['@plugin.manager.display_variant', '@config.typed']
diff --git src/Annotation/PanelsStyle.php src/Annotation/PanelsStyle.php
new file mode 100644
index 0000000..bfcd11b
--- /dev/null
+++ src/Annotation/PanelsStyle.php
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * @file
+ * Contains Drupal\panels\Annotation\Style.
+ */
+
+namespace Drupal\panels\Annotation;
+
+use Drupal\Component\Annotation\Plugin;
+
+/**
+ * Defines a PanelsStyle annotation object.
+ *
+ * @todo: Document other annotation keys.
+ *
+ * @Annotation
+ */
+class PanelsStyle extends Plugin {
+
+  /**
+   * The human readable title.
+   *
+   * @var string
+   */
+  public $title = '';
+
+  /**
+   * The human readable description.
+   *
+   * @var string
+   */
+  public $description = '';
+
+}
\ No newline at end of file
diff --git src/Form/PanelsBlockConfigureFormBase.php src/Form/PanelsBlockConfigureFormBase.php
index 2dabe75..b367656 100644
--- src/Form/PanelsBlockConfigureFormBase.php
+++ src/Form/PanelsBlockConfigureFormBase.php
@@ -140,6 +140,19 @@ abstract class PanelsBlockConfigureFormBase extends FormBase {
       '#required' => TRUE,
     ];
 
+    $plugin_options = [];
+    foreach (\Drupal::service('plugin.manager.panels.style')->getDefinitions() as $definition) {
+      $plugin_options[$definition['id']] = $definition['title'];
+    }
+
+    $form['style'] = [
+      '#type'          => 'select',
+      '#title'         => $this->t('Style Plugin'),
+      '#description'   => $this->t('Please select the style plugin for this region.'),
+      '#options'       => $plugin_options,
+      '#default_value' => !empty($this->block->getConfiguration()['style']['plugin']) ? $this->block->getConfiguration()['style']['plugin'] : 'panels_default',
+    ];
+    
     $form['actions']['submit'] = [
       '#type' => 'submit',
       '#value' => $this->submitText(),
@@ -180,6 +193,7 @@ abstract class PanelsBlockConfigureFormBase extends FormBase {
 
     $configuration = $this->block->getConfiguration();
     $configuration['region'] = $form_state->getValue('region');
+    $configuration['style']['plugin'] = $form_state->getValue('style');
     $this->getVariantPlugin()->updateBlock($this->block->getConfiguration()['uuid'], $configuration);
 
     $cached_values = $this->getCachedValues($this->tempstore, $this->tempstore_id, $form_state->get('machine_name'));
diff --git src/Form/PanelsBlockEditPanelsStyleForm.php src/Form/PanelsBlockEditPanelsStyleForm.php
new file mode 100644
index 0000000..1651983
--- /dev/null
+++ src/Form/PanelsBlockEditPanelsStyleForm.php
@@ -0,0 +1,93 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\panels\Form\PanelsBlockEditPanelsStyleForm.
+ */
+
+namespace Drupal\panels\Form;
+
+use Drupal\Core\Form\FormStateInterface;
+use Drupal\page_manager\Form\DisplayVariantConfigureBlockFormBase;
+use Drupal\page_manager\PageInterface;
+
+/**
+ * Provides a form for editing a region of a display variant.
+ */
+class PanelsBlockEditPanelsStyleForm extends DisplayVariantConfigureBlockFormBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'panels_block_edit_panels_style_form';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function prepareBlock($block_id) {
+    return $this->displayVariant->getBlock($block_id);
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function submitText() {
+    return $this->t('Update style');
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildForm(array $form, FormStateInterface $form_state, PageInterface $page = NULL, $display_variant_id = NULL, $block_id = NULL) {
+    $this->page           = $page;
+    $this->displayVariant = $page->getVariant($display_variant_id);
+    $this->block          = $this->prepareBlock($block_id);
+    $form_state->set('display_variant_id', $display_variant_id);
+    $form_state->set('block_id', $this->block->getConfiguration()['uuid']);
+
+    $form['#tree'] = TRUE;
+
+    $plugin_options = [];
+    // @todo: Replace with an injected service?
+    foreach (\Drupal::service('plugin.manager.panels.style')->getDefinitions() as $definition) {
+      $plugin_options[$definition['id']] = $definition['title'];
+    }
+
+    $form['style'] = [
+      '#type'          => 'select',
+      '#title'         => $this->t('Style Plugin'),
+      '#description'   => $this->t('Please select the style plugin for this block.'),
+      '#options'       => $plugin_options,
+      '#default_value' => $this->block->getConfiguration()['style']['plugin'] ?: 'panels_default',
+    ];
+
+    $form['actions']['submit'] = [
+      '#type'        => 'submit',
+      '#value'       => $this->submitText(),
+      '#button_type' => 'primary',
+    ];
+    return $form;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function validateForm(array &$form, FormStateInterface $form_state) {
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function submitForm(array &$form, FormStateInterface $form_state) {
+    $this->displayVariant->updateBlock($this->block->getConfiguration()['uuid'], ['style' => ['plugin' => $form_state->getValue('style')]]);
+    $this->page->save();
+
+    $form_state->setRedirect('page_manager.display_variant_edit', [
+      'page'               => $this->page->id(),
+      'display_variant_id' => $this->displayVariant->id(),
+    ]);
+  }
+
+}
\ No newline at end of file
diff --git src/Form/PanelsContentForm.php src/Form/PanelsContentForm.php
index fbe2c8b..49aab42 100644
--- src/Form/PanelsContentForm.php
+++ src/Form/PanelsContentForm.php
@@ -156,7 +156,19 @@ class PanelsContentForm extends FormBase {
         $form['blocks']['region-' . $region]['title'] = [
           '#markup' => $variant_plugin->getRegionName($region),
           '#wrapper_attributes' => [
-            'colspan' => 5,
+            'colspan' => 4,
+          ],
+        ];
+        $region_operations['edit'] = [
+          'title' => $this->t('Edit'),
+          'url' => $pattern_plugin->getRegionEditUrl($this->tempstore_id, $machine_name, $region, $this->getRequest()->getRequestUri()),
+          'attributes' => $attributes,
+        ];
+        $form['blocks']['region-' . $region]['operations'] = [
+          '#type' => 'operations',
+          '#links' => $region_operations,
+          '#wrapper_attributes' => [
+            'colspan' => 1,
           ],
         ];
         $form['blocks']['region-' . $region . '-message'] = [
diff --git src/Form/PanelsBlockConfigureFormBase.php src/Form/PanelsRegionEditFormBase.php
similarity index 58%
copy from src/Form/PanelsBlockConfigureFormBase.php
copy to src/Form/PanelsRegionEditFormBase.php
index 2dabe75..0ce113f 100644
--- src/Form/PanelsBlockConfigureFormBase.php
+++ src/Form/PanelsRegionEditFormBase.php
@@ -2,7 +2,7 @@
 
 /**
  * @file
- * Contains \Drupal\panels\Form\PanelsBlockConfigureFormBase.
+ * Contains \Drupal\panels\Form\PanelsRegionEditFormBase.
  */
 
 namespace Drupal\panels\Form;
@@ -19,9 +19,9 @@ use Drupal\user\SharedTempStoreFactory;
 use Symfony\Component\DependencyInjection\ContainerInterface;
 
 /**
- * Provides a base form for configuring a block as part of a variant.
+ * Provides a base form for configuring a block as part of a display variant.
  */
-abstract class PanelsBlockConfigureFormBase extends FormBase {
+abstract class PanelsRegionEditFormBase extends FormBase {
 
   use ContextAwarePluginAssignmentTrait;
   use CachedValuesGetterTrait;
@@ -48,11 +48,11 @@ abstract class PanelsBlockConfigureFormBase extends FormBase {
   protected $variantPlugin;
 
   /**
-   * The plugin being configured.
+   * The region configuration.
    *
-   * @var \Drupal\Core\Block\BlockPluginInterface
+   * @var array
    */
-  protected $block;
+  protected $regionConfiguration;
 
   /**
    * Constructs a new VariantPluginConfigureBlockFormBase.
@@ -92,17 +92,6 @@ abstract class PanelsBlockConfigureFormBase extends FormBase {
   }
 
   /**
-   * Prepares the block plugin based on the block ID.
-   *
-   * @param string $block_id
-   *   Either a block ID, or the plugin ID used to create a new block.
-   *
-   * @return \Drupal\Core\Block\BlockPluginInterface
-   *   The block plugin.
-   */
-  abstract protected function prepareBlock($block_id);
-
-  /**
    * Returns the text to use for the submit button.
    *
    * @return string
@@ -113,36 +102,38 @@ abstract class PanelsBlockConfigureFormBase extends FormBase {
   /**
    * {@inheritdoc}
    */
-  public function buildForm(array $form, FormStateInterface $form_state, $tempstore_id = NULL, $machine_name = NULL, $block_id = NULL) {
+  public function buildForm(array $form, FormStateInterface $form_state, $tempstore_id = NULL, $machine_name = NULL, $region = NULL) {
     $this->tempstore_id = $tempstore_id;
     $cached_values = $this->getCachedValues($this->tempstore, $tempstore_id, $machine_name);
     $this->variantPlugin = $cached_values['plugin'];
-
     $contexts = $this->variantPlugin->getPattern()->getDefaultContexts($this->tempstore, $this->getTempstoreId(), $machine_name);
     $this->variantPlugin->setContexts($contexts);
     $form_state->setTemporaryValue('gathered_contexts', $contexts);
 
-    $this->block = $this->prepareBlock($block_id);
+    $display_configuration     = $this->variantPlugin->getConfiguration();
+    $this->regionConfiguration = !empty($display_configuration['regions'][$region]) ? $display_configuration['regions'][$region] : [];
+
+    $form_state->set('region', $region);
     $form_state->set('machine_name', $machine_name);
-    $form_state->set('block_id', $this->block->getConfiguration()['uuid']);
 
     $form['#tree'] = TRUE;
-    $form['settings'] = $this->block->buildConfigurationForm([], $form_state);
-    $form['settings']['id'] = [
-      '#type' => 'value',
-      '#value' => $this->block->getPluginId(),
-    ];
-    $form['region'] = [
-      '#title' => $this->t('Region'),
-      '#type' => 'select',
-      '#options' => $this->variantPlugin->getRegionNames(),
-      '#default_value' => $this->variantPlugin->getRegionAssignment($this->block->getConfiguration()['uuid']),
-      '#required' => TRUE,
+
+    $plugin_options = [];
+    foreach (\Drupal::service('plugin.manager.panels.style')->getDefinitions() as $definition) {
+      $plugin_options[$definition['id']] = $definition['title'];
+    }
+
+    $form['style'] = [
+      '#type'          => 'select',
+      '#title'         => $this->t('Style Plugin'),
+      '#description'   => $this->t('Please select the style plugin for this region.'),
+      '#options'       => $plugin_options,
+      '#default_value' => $this->regionConfiguration['style']['plugin'] ?: 'panels_default',
     ];
 
     $form['actions']['submit'] = [
-      '#type' => 'submit',
-      '#value' => $this->submitText(),
+      '#type'        => 'submit',
+      '#value'       => $this->submitText(),
       '#button_type' => 'primary',
     ];
     return $form;
@@ -152,35 +143,16 @@ abstract class PanelsBlockConfigureFormBase extends FormBase {
    * {@inheritdoc}
    */
   public function validateForm(array &$form, FormStateInterface $form_state) {
-    // The page might have been serialized, resulting in a new variant
-    // collection. Refresh the block object.
-    $this->block = $this->getVariantPlugin()->getBlock($form_state->get('block_id'));
-
-    $settings = (new FormState())->setValues($form_state->getValue('settings'));
-    // Call the plugin validate handler.
-    $this->block->validateConfigurationForm($form, $settings);
-    // Update the original form values.
-    $form_state->setValue('settings', $settings->getValues());
   }
 
   /**
    * {@inheritdoc}
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
-    $settings = (new FormState())->setValues($form_state->getValue('settings'));
-
-    // Call the plugin submit handler.
-    $this->block->submitConfigurationForm($form, $settings);
-    // Update the original form values.
-    $form_state->setValue('settings', $settings->getValues());
-
-    if ($this->block instanceof ContextAwarePluginInterface) {
-      $this->block->setContextMapping($settings->getValue('context_mapping', []));
-    }
-
-    $configuration = $this->block->getConfiguration();
-    $configuration['region'] = $form_state->getValue('region');
-    $this->getVariantPlugin()->updateBlock($this->block->getConfiguration()['uuid'], $configuration);
+    $style = $form_state->getValue('style');
+    $display_configuration = $this->variantPlugin->getConfiguration();
+    $display_configuration['regions'][$form_state->get('region')]['style']['plugin'] = $style;
+    $this->variantPlugin->setConfiguration($display_configuration);
 
     $cached_values = $this->getCachedValues($this->tempstore, $this->tempstore_id, $form_state->get('machine_name'));
     $cached_values['plugin'] = $this->getVariantPlugin();
@@ -199,5 +171,4 @@ abstract class PanelsBlockConfigureFormBase extends FormBase {
   protected function getVariantPlugin() {
     return $this->variantPlugin;
   }
-
-}
+}
\ No newline at end of file
diff --git src/Form/PanelsRegionEditPanelsStyleForm.php src/Form/PanelsRegionEditPanelsStyleForm.php
new file mode 100644
index 0000000..03d4b07
--- /dev/null
+++ src/Form/PanelsRegionEditPanelsStyleForm.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\panels\Form\PanelsRegionEditPanelsStyleForm.
+ */
+
+namespace Drupal\panels\Form;
+
+/**
+ * Provides a form for editing a region of a display variant.
+ */
+class PanelsRegionEditPanelsStyleForm extends PanelsRegionEditFormBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function getFormId() {
+    return 'panels_region_edit_style_form';
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function submitText() {
+    return $this->t('Update style');
+  }
+
+}
diff --git src/Plugin/DisplayBuilder/StandardDisplayBuilder.php src/Plugin/DisplayBuilder/StandardDisplayBuilder.php
index b9bfffe..97b423a 100644
--- src/Plugin/DisplayBuilder/StandardDisplayBuilder.php
+++ src/Plugin/DisplayBuilder/StandardDisplayBuilder.php
@@ -79,7 +79,6 @@ class StandardDisplayBuilder extends DisplayBuilderBase implements PluginWizardI
       $container->get('current_user')
     );
   }
-
   /**
    * Build render arrays for each of the regions.
    *
@@ -92,7 +91,11 @@ class StandardDisplayBuilder extends DisplayBuilderBase implements PluginWizardI
    *   An associative array, keyed by region ID, containing the render arrays
    *   representing the content of each region.
    */
-  protected function buildRegions(array $regions, array $contexts) {
+  protected function buildRegions(PanelsDisplayVariant $panels_display) {
+    $regions = $panels_display->getRegionAssignments();
+    $contexts = $panels_display->getContexts();
+    $layout = $panels_display->getLayout();
+
     $build = [];
     foreach ($regions as $region => $blocks) {
       if (!$blocks) {
@@ -103,43 +106,21 @@ class StandardDisplayBuilder extends DisplayBuilderBase implements PluginWizardI
       $build[$region]['#prefix'] = '<div class="' . $region_name . '">';
       $build[$region]['#suffix'] = '</div>';
 
-      /** @var \Drupal\Core\Block\BlockPluginInterface[] $blocks */
-      $weight = 0;
+      $build[$region] = [];
+      /** @var $blocks \Drupal\Core\Block\BlockPluginInterface[] */
       foreach ($blocks as $block_id => $block) {
         if ($block instanceof ContextAwarePluginInterface) {
           $this->contextHandler->applyContextMapping($block, $contexts);
         }
         if ($block->access($this->account)) {
-          $block_render_array = [
-            '#theme' => 'block',
-            '#attributes' => [],
-            '#contextual_links' => [],
-            '#weight' => $weight++,
-            '#configuration' => $block->getConfiguration(),
-            '#plugin_id' => $block->getPluginId(),
-            '#base_plugin_id' => $block->getBaseId(),
-            '#derivative_plugin_id' => $block->getDerivativeId(),
-          ];
-
-          // Build the block and bubble its attributes up if possible. This
-          // allows modules like Quickedit to function.
-          // See \Drupal\block\BlockViewBuilder::preRender() for reference.
-          $content = $block->build();
-          if ($content !== NULL && !Element::isEmpty($content)) {
-            foreach (['#attributes', '#contextual_links'] as $property) {
-              if (isset($content[$property])) {
-                $block_render_array[$property] += $content[$property];
-                unset($content[$property]);
-              }
-            }
-          }
-
-          $block_render_array['content'] = $content;
-
-          $build[$region][$block_id] = $block_render_array;
+          $build[$region][$block_id] = $panels_display->getBlockStyle($block_id)->buildBlock($panels_display, $block);
         }
       }
+      // Apply the region style last so that region styles have access to some
+      // pane information.
+     $build[$region] = $panels_display->getRegionStyle($region)->buildRegion($panels_display, $build[$region], $region, $blocks);
     }
+    $build['#title'] = $panels_display->renderPageTitle($panels_display->configuration['page_title']);
     return $build;
   }
 
@@ -151,7 +132,7 @@ class StandardDisplayBuilder extends DisplayBuilderBase implements PluginWizardI
     $contexts = $panels_display->getContexts();
     $layout = $panels_display->getLayout();
 
-    $regions = $this->buildRegions($regions, $contexts);
+    $regions = $this->buildRegions($panels_display);
     if ($layout) {
       $regions = $layout->build($regions);
     }
diff --git src/Plugin/DisplayVariant/PanelsDisplayVariant.php src/Plugin/DisplayVariant/PanelsDisplayVariant.php
index e620ab4..f3aae26 100644
--- src/Plugin/DisplayVariant/PanelsDisplayVariant.php
+++ src/Plugin/DisplayVariant/PanelsDisplayVariant.php
@@ -24,6 +24,7 @@ use Drupal\panels\Form\LayoutChangeRegions;
 use Drupal\panels\Form\LayoutChangeSettings;
 use Drupal\panels\Form\LayoutPluginSelector;
 use Drupal\panels\Form\LayoutPluginUpdate;
+use Drupal\panels\Plugin\PanelsStyle\PanelsStylePluginManagerInterface;
 use Drupal\panels\Plugin\DisplayBuilder\DisplayBuilderInterface;
 use Drupal\panels\Plugin\DisplayBuilder\DisplayBuilderManagerInterface;
 use Drupal\panels\Plugin\PanelsPattern\PanelsPatternInterface;
@@ -73,6 +74,12 @@ class PanelsDisplayVariant extends BlockDisplayVariant implements PluginWizardIn
    * @var \Drupal\layout_plugin\Plugin\Layout\LayoutInterface
    */
   protected $layout;
+  /**
+   * The style plugin manager.
+   *
+   * @var \Drupal\panels\Plugin\PanelsStyle\PanelsStylePluginManagerInterface;
+   */
+  protected $styleManager;
 
   /**
    * Constructs a new PanelsDisplayVariant.
@@ -102,10 +109,11 @@ class PanelsDisplayVariant extends BlockDisplayVariant implements PluginWizardIn
    * @param \Drupal\layout_plugin\Plugin\Layout\LayoutPluginManagerInterface $layout_manager
    *   The layout plugin manager.
    */
-  public function __construct(array $configuration, $plugin_id, $plugin_definition, ContextHandlerInterface $context_handler, AccountInterface $account, UuidInterface $uuid_generator, Token $token, BlockManager $block_manager, ConditionManager $condition_manager, ModuleHandlerInterface $module_handler, DisplayBuilderManagerInterface $builder_manager, LayoutPluginManagerInterface $layout_manager) {
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, ContextHandlerInterface $context_handler, AccountInterface $account, UuidInterface $uuid_generator, Token $token, BlockManager $block_manager, ConditionManager $condition_manager, ModuleHandlerInterface $module_handler, DisplayBuilderManagerInterface $builder_manager, LayoutPluginManagerInterface $layout_manager, PanelsStylePluginManagerInterface $style_manager) {
     $this->moduleHandler = $module_handler;
     $this->builderManager = $builder_manager;
     $this->layoutManager = $layout_manager;
+    $this->styleManager = $style_manager;
 
     parent::__construct($configuration, $plugin_id, $plugin_definition, $context_handler, $account, $uuid_generator, $token, $block_manager, $condition_manager);
   }
@@ -126,7 +134,8 @@ class PanelsDisplayVariant extends BlockDisplayVariant implements PluginWizardIn
       $container->get('plugin.manager.condition'),
       $container->get('module_handler'),
       $container->get('plugin.manager.panels.display_builder'),
-      $container->get('plugin.manager.layout_plugin')
+      $container->get('plugin.manager.layout_plugin'),
+      $container->get('plugin.manager.panels.style')
     );
   }
 
@@ -297,6 +306,38 @@ class PanelsDisplayVariant extends BlockDisplayVariant implements PluginWizardIn
   }
 
   /**
+   * Returns the panels style plugin to use for the block.
+   *
+   * @param string $block_id
+   *   The id of the block.
+   *
+   * @return \Drupal\panels\Plugin\PanelsStyle\PanelsStyleInterface
+   *   The style plugin.
+   */
+  public function getBlockStyle($block_id) {
+    $block_config = $this->configuration['blocks'][$block_id];
+    $style = !empty($block_config['style']['plugin']) ? $block_config['style']['plugin'] : 'panels_default';
+    $style_settings = !empty($block_config['style']['configuration']) ? $block_config['style']['configuration'] : [];
+    return $this->styleManager->createInstance($style, $style_settings);
+  }
+
+  /**
+   * Returns the panels style plugin to use for the region.
+   *
+   * @param string $region
+   *   The id of the region.
+   *
+   * @return \Drupal\panels\Plugin\PanelsStyle\PanelsStyleInterface
+   *   The style plugin.
+   */
+  public function getRegionStyle($region) {
+    $region_config = !empty($this->configuration['regions'][$region]) ? $this->configuration['regions'][$region] : [];
+    $style = !empty($region_config['style']['plugin']) ? $region_config['style']['plugin'] : 'panels_default';
+    $style_settings = !empty($region_config['style']['configuration']) ? $region_config['style']['configuration'] : [];
+    return $this->styleManager->createInstance($style, $style_settings);
+  }
+
+  /**
    * {@inheritdoc}
    */
   public function getRegionNames() {
@@ -484,7 +525,7 @@ class PanelsDisplayVariant extends BlockDisplayVariant implements PluginWizardIn
    * @return string
    *   The page title after replacing any tokens.
    */
-  protected function renderPageTitle($page_title) {
+  public function renderPageTitle($page_title) {
     $data = $this->getContextAsTokenData();
     return $this->token->replace($page_title, $data);
   }
diff --git src/Plugin/PanelsPattern/DefaultPattern.php src/Plugin/PanelsPattern/DefaultPattern.php
index 8db47fb..84a6b6a 100644
--- src/Plugin/PanelsPattern/DefaultPattern.php
+++ src/Plugin/PanelsPattern/DefaultPattern.php
@@ -128,4 +128,16 @@ class DefaultPattern extends PluginBase implements PanelsPatternInterface, Conta
     ]);
   }
 
+  /**
+   * {@inheritdoc}
+   */
+  public function getRegionEditUrl($tempstore_id, $machine_name, $region, $destination = NULL) {
+    return Url::fromRoute('panels.region_edit_style', [
+      'tempstore_id' => $tempstore_id,
+      'machine_name' => $machine_name,
+      'region' => $region,
+      'destination' => $destination,
+    ]);
+  }
+
 }
diff --git src/Plugin/PanelsStyle/PanelsStyleBase.php src/Plugin/PanelsStyle/PanelsStyleBase.php
new file mode 100644
index 0000000..70b21c7
--- /dev/null
+++ src/Plugin/PanelsStyle/PanelsStyleBase.php
@@ -0,0 +1,54 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\panels\Plugin\PanelsStyle\PanelsStyleBase.
+ */
+
+namespace Drupal\panels\Plugin\PanelsStyle;
+
+use Drupal\Component\Plugin\PluginBase;
+use Drupal\Component\Utility\Html;
+use Drupal\Component\Utility\SafeMarkup;
+use Drupal\Core\Block\BlockPluginInterface;
+use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant;
+use Drupal\panels\Plugin\PanelsStyle\PanelsStyleInterface;
+
+/**
+ * Base class for all style plugins.
+ */
+class PanelsStyleBase extends PluginBase implements PanelsStyleInterface {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildRegion(PanelsDisplayVariant $display, array $build, $region, array $blocks) {
+    $region_name = Html::getClass("block-region-$region");
+    $build['#prefix'] = '<div class="' . $region_name . '">';
+    $build['#suffix'] = '</div>';
+
+    return $build;
+  }
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildBlock(PanelsDisplayVariant $display, BlockPluginInterface $block) {
+    $build = [
+        '#theme' => 'block',
+        '#attributes' => ['class' => ['container']],
+        '#weight' => $display->getWeight(),
+        '#configuration' => $block->getConfiguration(),
+        '#plugin_id' => $block->getPluginId(),
+        '#base_plugin_id' => $block->getBaseId(),
+        '#derivative_plugin_id' => $block->getDerivativeId(),
+      ];
+    if (!empty($build['#configuration']['label'])) {
+      $build['#configuration']['label'] = SafeMarkup::checkPlain($build['#configuration']['label']);
+    }
+    $build['content'] = $block->build();
+
+    return $build;
+  }
+
+}
\ No newline at end of file
diff --git src/Plugin/PanelsStyle/PanelsStyleDefault.php src/Plugin/PanelsStyle/PanelsStyleDefault.php
new file mode 100644
index 0000000..513ca0e
--- /dev/null
+++ src/Plugin/PanelsStyle/PanelsStyleDefault.php
@@ -0,0 +1,19 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\panels\Plugin\PanelsStyle\PanelsStyleDefault.
+ */
+
+namespace Drupal\panels\Plugin\PanelsStyle;
+
+/**
+ * Defines the default panels style plugin.
+ *
+ * @PanelsStyle(
+ *   id = "panels_default",
+ *   title = @Translation("Default")
+ * )
+ */
+class PanelsStyleDefault extends PanelsStyleBase {
+}
\ No newline at end of file
diff --git src/Plugin/PanelsStyle/PanelsStyleInterface.php src/Plugin/PanelsStyle/PanelsStyleInterface.php
new file mode 100644
index 0000000..0e56e0c
--- /dev/null
+++ src/Plugin/PanelsStyle/PanelsStyleInterface.php
@@ -0,0 +1,43 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\panels\Plugin\PanelsStyle\PanelsStyleInterface.
+ */
+
+namespace Drupal\panels\Plugin\PanelsStyle;
+
+use Drupal\Component\Plugin\PluginInspectionInterface;
+use Drupal\Core\Block\BlockPluginInterface;
+use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant;
+
+/**
+ * Provides an interface for PanelsStyle plugins.
+ */
+interface PanelsStyleInterface extends PluginInspectionInterface {
+
+  /**
+   * Renders a region.
+   *
+   * @param PanelsDisplayVariant $display
+   *   The Panels display variant.
+   * @param array $build
+   *   The build array for the region to be modified.
+   * @param string $region
+   *   The region name.
+   * @param BlockPluginInterface[] $blocks
+   *   An array of blocks.
+   */
+  public function buildRegion(PanelsDisplayVariant $display, array $build, $region, array $blocks);
+
+  /**
+   * Render a block.
+   *
+   * @param PanelsDisplayVariant $display
+   *   The Panels display variant.
+   * @param BlockPluginInterface $block
+   *   The block.
+   */
+  public function buildBlock(PanelsDisplayVariant $display, BlockPluginInterface $block);
+
+}
diff --git src/Plugin/PanelsStyle/PanelsStyleList.php src/Plugin/PanelsStyle/PanelsStyleList.php
new file mode 100644
index 0000000..4a14a6f
--- /dev/null
+++ src/Plugin/PanelsStyle/PanelsStyleList.php
@@ -0,0 +1,35 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\panels\Plugin\PanelsStyle\PanelsStyleList.
+ */
+
+namespace Drupal\panels\Plugin\PanelsStyle;
+
+use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant;
+
+/**
+ * Defines the list panels style plugin.
+ *
+ * @PanelsStyle(
+ *   id = "panels_list",
+ *   title = @Translation("List")
+ * )
+ */
+class PanelsStyleList extends PanelsStyleBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  public function buildRegion(PanelsDisplayVariant $display, array $build, $region, array $blocks) {
+    $build = [
+      '#theme' => 'item_list',
+      '#list_type' => 'ul',
+      '#items' => $build,
+    ];
+
+    return parent::buildRegion($display, $build, $region, $blocks);
+  }
+
+}
\ No newline at end of file
diff --git src/Plugin/PanelsStyle/PanelsStylePluginManager.php src/Plugin/PanelsStyle/PanelsStylePluginManager.php
new file mode 100644
index 0000000..4d30425
--- /dev/null
+++ src/Plugin/PanelsStyle/PanelsStylePluginManager.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\panels\Plugin\PanelsStyle\PanelsStylePluginManager.
+ */
+
+namespace Drupal\panels\Plugin\PanelsStyle;
+
+use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Extension\ModuleHandlerInterface;
+use Drupal\Core\Plugin\DefaultPluginManager;
+use Drupal\Core\Plugin\Discovery\YamlDiscoveryDecorator;
+
+/**
+ * Plugin type manager for all styles.
+ */
+class PanelsStylePluginManager extends DefaultPluginManager implements PanelsStylePluginManagerInterface {
+
+  /**
+   * Constructs a PanelsStylePluginManager object.
+   *
+   * @param \Traversable $namespaces
+   *   An object that implements \Traversable which contains the root paths
+   *   keyed by the corresponding namespace to look for plugin implementations.
+   * @param \Drupal\Core\Cache\CacheBackendInterface $cache_backend
+   *   Cache backend instance to use.
+   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
+   *   The module handler to invoke the alter hook with.
+   */
+  public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
+    parent::__construct("Plugin/PanelsStyle", $namespaces, $module_handler, 'Drupal\panels\Plugin\PanelsStyle\PanelsStyleInterface', 'Drupal\panels\Annotation\PanelsStyle');
+    $this->discovery = new YamlDiscoveryDecorator($this->getDiscovery(), 'styles', $module_handler->getModuleDirectories());
+
+    $this->setCacheBackend($cache_backend, 'panels_style_plugins');
+    $this->alterInfo('panels_style_plugin');
+  }
+
+}
\ No newline at end of file
diff --git src/Plugin/PanelsStyle/PanelsStylePluginManagerInterface.php src/Plugin/PanelsStyle/PanelsStylePluginManagerInterface.php
new file mode 100644
index 0000000..fa1996f
--- /dev/null
+++ src/Plugin/PanelsStyle/PanelsStylePluginManagerInterface.php
@@ -0,0 +1,16 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\panels\Plugin\PanelsStyle;\PanelsStylePluginManagerInterface.
+ */
+
+namespace Drupal\panels\Plugin\PanelsStyle;
+
+use Drupal\Component\Plugin\PluginManagerInterface;
+
+/**
+ * Provides an interface for the discovery and instantiation of layout plugins.
+ */
+interface PanelsStylePluginManagerInterface extends PluginManagerInterface {
+
+}
diff --git tests/src/Unit/PanelsDisplayVariantTest.php tests/src/Unit/PanelsDisplayVariantTest.php
index 8ef088e..d0a5f83 100644
--- tests/src/Unit/PanelsDisplayVariantTest.php
+++ tests/src/Unit/PanelsDisplayVariantTest.php
@@ -19,6 +19,8 @@ use Drupal\layout_plugin\Plugin\Layout\LayoutInterface;
 use Drupal\layout_plugin\Plugin\Layout\LayoutPluginManagerInterface;
 use Drupal\panels\Plugin\DisplayBuilder\DisplayBuilderManagerInterface;
 use Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant;
+Use Drupal\panels\Plugin\PanelsStyle\PanelsStyleInterface;
+Use Drupal\panels\Plugin\PanelsStyle\PanelsStylePluginManagerInterface;
 use Drupal\Tests\UnitTestCase;
 use Prophecy\Argument;
 
@@ -94,12 +96,18 @@ class PanelsDisplayVariantTest extends UnitTestCase {
     $this->builderManager = $this->prophesize(DisplayBuilderManagerInterface::class);
     $this->layoutManager = $this->prophesize(LayoutPluginManagerInterface::class);
     $this->layout = $this->prophesize(LayoutInterface::class);
+    $this->styleManager = $this->prophesize(PanelsStylePluginManagerInterface::class);
+    $this->style = $this->prophesize(PanelsStyleInterface::class);
 
     $this->layoutManager
       ->createInstance(Argument::type('string'), Argument::type('array'))
       ->willReturn($this->layout->reveal());
 
-    $this->variant = new PanelsDisplayVariant([], '', [], $this->contextHandler->reveal(), $this->account->reveal(), $this->uuidGenerator->reveal(), $this->token->reveal(), $this->blockManager->reveal(), $this->conditionManager->reveal(), $this->moduleHandler->reveal(), $this->builderManager->reveal(), $this->layoutManager->reveal());
+    $this->styleManager
+      ->createInstance(Argument::type('string'), Argument::type('array'))
+      ->willReturn($this->style->reveal());
+
+    $this->variant = new PanelsDisplayVariant([], '', [], $this->contextHandler->reveal(), $this->account->reveal(), $this->uuidGenerator->reveal(), $this->token->reveal(), $this->blockManager->reveal(), $this->conditionManager->reveal(), $this->moduleHandler->reveal(), $this->builderManager->reveal(), $this->layoutManager->reveal(), $this->styleManager->reveal());
   }
 
   /**
-- 
2.5.4 (Apple Git-61)

