Skip to content
Snippets Groups Projects
Commit 3a322a26 authored by Antonio De Marco's avatar Antonio De Marco
Browse files

Initial port to Layout Discovery #80

parent 37ba1149
No related branches found
No related tags found
No related merge requests found
...@@ -3,17 +3,18 @@ ...@@ -3,17 +3,18 @@
namespace Drupal\ui_patterns_layouts\Plugin\Layout; namespace Drupal\ui_patterns_layouts\Plugin\Layout;
use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Layout\LayoutDefault;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\layout_plugin\Plugin\Layout\LayoutBase; use Drupal\Core\Plugin\PluginFormInterface;
use Drupal\ui_patterns\UiPatternsManager; use Drupal\ui_patterns\UiPatternsManager;
use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerInterface;
/** /**
* Class LayoutDefault. * Class LayoutDefault.
* *
* @package Drupal\layout_plugin\Plugin\Layout * @package Drupal\ui_patterns_layouts\Plugin\Layout
*/ */
class PatternLayout extends LayoutBase implements ContainerFactoryPluginInterface { class PatternLayout extends LayoutDefault implements PluginFormInterface, ContainerFactoryPluginInterface {
/** /**
* Pattern manager service. * Pattern manager service.
...@@ -91,8 +92,8 @@ class PatternLayout extends LayoutBase implements ContainerFactoryPluginInterfac ...@@ -91,8 +92,8 @@ class PatternLayout extends LayoutBase implements ContainerFactoryPluginInterfac
* {@inheritdoc} * {@inheritdoc}
*/ */
public function buildConfigurationForm(array $form, FormStateInterface $form_state) { public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$configuration = $this->getConfiguration(); $configuration = $this->getConfiguration();
$form = [];
$form['pattern'] = [ $form['pattern'] = [
'#group' => 'additional_settings', '#group' => 'additional_settings',
...@@ -117,6 +118,19 @@ class PatternLayout extends LayoutBase implements ContainerFactoryPluginInterfac ...@@ -117,6 +118,19 @@ class PatternLayout extends LayoutBase implements ContainerFactoryPluginInterfac
return $form; return $form;
} }
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration = $form_state->getValues();
}
/** /**
* Remove default field template if "Only content" option has been selected. * Remove default field template if "Only content" option has been selected.
* *
......
...@@ -4,5 +4,5 @@ description: Use patterns as layout plugins. ...@@ -4,5 +4,5 @@ description: Use patterns as layout plugins.
core: 8.x core: 8.x
package: User interface package: User interface
dependencies: dependencies:
- layout_plugin - layout_discovery
- ui_patterns - ui_patterns
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
use Drupal\ui_patterns\Element\PatternContext; use Drupal\ui_patterns\Element\PatternContext;
use Drupal\Core\Layout\LayoutDefinition;
/** /**
* Implements hook_layout_alter(). * Implements hook_layout_alter().
...@@ -21,14 +22,12 @@ function ui_patterns_layouts_layout_alter(&$definitions) { ...@@ -21,14 +22,12 @@ function ui_patterns_layouts_layout_alter(&$definitions) {
'category' => 'Patterns', 'category' => 'Patterns',
'class' => '\Drupal\ui_patterns_layouts\Plugin\Layout\PatternLayout', 'class' => '\Drupal\ui_patterns_layouts\Plugin\Layout\PatternLayout',
'pattern' => $pattern_definition['id'], 'pattern' => $pattern_definition['id'],
'path' => '', 'template' => 'pattern-' . $pattern_definition['id'],
'template_path' => NULL,
]; ];
foreach ($pattern_definition['fields'] as $field_name => $field) { foreach ($pattern_definition['fields'] as $field_name => $field) {
$definition['regions'][$field_name]['label'] = $field['label']; $definition['regions'][$field_name]['label'] = $field['label'];
$definition['region_names'][$field_name] = $field['label'];
} }
$definitions['pattern_' . $pattern_definition['id']] = $definition; $definitions['pattern_' . $pattern_definition['id']] = new LayoutDefinition($definition);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment