Last active
April 10, 2020 18:30
-
-
Save danny-englander/1e5058f0e0746564a1654f6954cc19e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
custom_layout: | |
label: custom_layout Two Column | |
src: | |
Plugin: | |
Layout: | |
TwoColumnLayout.php | |
templates: | |
layout--two-column.html.twig | |
icon_map: | |
- [first, second] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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