Skip to content

Instantly share code, notes, and snippets.

@danny-englander
Last active April 10, 2020 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danny-englander/1e5058f0e0746564a1654f6954cc19e8 to your computer and use it in GitHub Desktop.
Save danny-englander/1e5058f0e0746564a1654f6954cc19e8 to your computer and use it in GitHub Desktop.
custom_layout:
label: custom_layout Two Column
src:
Plugin:
Layout:
TwoColumnLayout.php
templates:
layout--two-column.html.twig
icon_map:
- [first, second]
<?php
namespace Drupal\custom_layout\Plugin\Layout;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Layout\LayoutDefault;
use Drupal\Core\Plugin\PluginFormInterface;
/**
* Configurable two column layout plugin class.
*
* @internal
* Plugin classes are internal.
*/
class TwoColumnLayout extends LayoutDefault implements PluginFormInterface {
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'column_widths' => '50-50',
];
}
// Override any methods you'd like to customize here!
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$configuration = $this->getConfiguration();
$form['column_widths'] = [
'#type' => 'select',
'#title' => $this->t('Column widths'),
'#default_value' => $configuration['column_widths'],
'#options' => [
'25-75' => $this->t('25%/75 foooo%'),
'50-50' => $this->t('50%/50 barrr%'),
'75-25' => $this->t('75%/25%'),
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
// Any additional form validation that is required.
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['column_widths'] = $form_state->getValue('column_widths');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment