class LayoutPluginSelector in Panels 8.3
Same name and namespace in other branches
- 8.4 src/Form/LayoutPluginSelector.php \Drupal\panels\Form\LayoutPluginSelector
Provides a form for selecting a layout plugin.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\panels\Form\LayoutPluginSelector
Expanded class hierarchy of LayoutPluginSelector
2 files declare their use of LayoutPluginSelector
- PanelsDisplayVariant.php in src/
Plugin/ DisplayVariant/ PanelsDisplayVariant.php - StandardDisplayBuilder.php in src/
Plugin/ DisplayBuilder/ StandardDisplayBuilder.php
File
- src/
Form/ LayoutPluginSelector.php, line 15
Namespace
Drupal\panels\FormView source
class LayoutPluginSelector extends FormBase {
/**
* The layout plugin manager.
*
* @var \Drupal\layout_plugin\Plugin\Layout\LayoutPluginManagerInterface
*/
protected $manager;
/**
* The tempstore factory.
*
* @var \Drupal\user\SharedTempStoreFactory
*/
protected $tempstore;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('plugin.manager.layout_plugin'), $container
->get('user.shared_tempstore'));
}
/**
* LayoutPluginSelector constructor.
*
* @param \Drupal\layout_plugin\Plugin\Layout\LayoutPluginManagerInterface $manager
* The layout plugin manager.
* @param \Drupal\user\SharedTempStoreFactory $tempstore
* The tempstore factory.
*/
public function __construct(LayoutPluginManagerInterface $manager, SharedTempStoreFactory $tempstore) {
$this->manager = $manager;
$this->tempstore = $tempstore;
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'panels_layout_selection_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
/* @var $variant_plugin \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant */
$variant_plugin = $cached_values['plugin'];
$form['layout'] = [
'#title' => $this
->t('Layout'),
'#type' => 'select',
'#options' => Layout::layoutPluginManager()
->getLayoutOptions([
'group_by_category' => TRUE,
]),
'#default_value' => $variant_plugin
->getConfiguration()['layout'] ?: NULL,
];
$wizard = $form_state
->getFormObject();
$form['update_layout'] = [
'#type' => 'submit',
'#value' => $this
->t('Change Layout'),
'#access' => !empty($variant_plugin
->getConfiguration()['layout']),
'#validate' => [
[
$this,
'validateForm',
],
],
'#submit' => [
[
$this,
'submitForm',
],
[
$wizard,
'submitForm',
],
],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
/* @var $variant_plugin \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant */
$variant_plugin = $cached_values['plugin'];
// If we're changing the layout, the variant plugin must remain out of date
// until the layout is fully configured and regions are remapped.
if ($form_state
->getValue('op') == $form['update_layout']['#value']) {
$cached_values['layout_change'] = [
'old_layout' => $variant_plugin
->getConfiguration()['layout'],
'new_layout' => $form_state
->getValue('layout'),
];
/** @var \Drupal\ctools\Wizard\EntityFormWizardInterface $wizard */
$wizard = $form_state
->getFormObject();
$next_op = $wizard
->getNextOp();
$form_state
->setValue('op', $next_op);
}
$variant_plugin
->setLayout($form_state
->getValue('layout'), $form_state
->getValue('layout_settings') ?: []);
$cached_values['plugin'] = $variant_plugin;
$form_state
->setTemporaryValue('wizard', $cached_values);
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
/* @var $variant_plugin \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant */
$variant_plugin = $cached_values['plugin'];
if ((string) $form_state
->getValue('op') == $this
->t('Change Layout') && $variant_plugin
->getConfiguration()['layout'] == $form_state
->getValue('layout')) {
$form_state
->setErrorByName('layout', $this
->t('You must select a different layout if you wish to change layouts.'));
}
if ($form['update_layout']['#access'] && $variant_plugin
->getConfiguration()['layout'] != $form_state
->getValue('layout') && $form_state
->getValue('op') != $form['update_layout']['#value']) {
$form_state
->setErrorByName('layout', $this
->t('To select a different layout, you must click "Change Layout".'));
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
FormBase:: |
protected | property | The config factory. | 1 |
FormBase:: |
protected | property | The request stack. | 1 |
FormBase:: |
protected | property | The route match. | |
FormBase:: |
protected | function | Retrieves a configuration object. | |
FormBase:: |
protected | function | Gets the config factory for this form. | 1 |
FormBase:: |
private | function | Returns the service container. | |
FormBase:: |
protected | function | Gets the current user. | |
FormBase:: |
protected | function | Gets the request object. | |
FormBase:: |
protected | function | Gets the route match. | |
FormBase:: |
protected | function | Gets the logger for a specific channel. | |
FormBase:: |
protected | function |
Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait:: |
|
FormBase:: |
public | function | Resets the configuration factory. | |
FormBase:: |
public | function | Sets the config factory for this form. | |
FormBase:: |
public | function | Sets the request stack object to use. | |
LayoutPluginSelector:: |
protected | property | The layout plugin manager. | |
LayoutPluginSelector:: |
protected | property | The tempstore factory. | |
LayoutPluginSelector:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
LayoutPluginSelector:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
LayoutPluginSelector:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LayoutPluginSelector:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
LayoutPluginSelector:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
LayoutPluginSelector:: |
public | function | LayoutPluginSelector constructor. | |
LinkGeneratorTrait:: |
protected | property | The link generator. | 1 |
LinkGeneratorTrait:: |
protected | function | Returns the link generator. | |
LinkGeneratorTrait:: |
protected | function | Renders a link to a route given a route name and its parameters. | |
LinkGeneratorTrait:: |
public | function | Sets the link generator service. | |
LoggerChannelTrait:: |
protected | property | The logger channel factory service. | |
LoggerChannelTrait:: |
protected | function | Gets the logger for a specific channel. | |
LoggerChannelTrait:: |
public | function | Injects the logger channel factory. | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
RedirectDestinationTrait:: |
protected | property | The redirect destination service. | 1 |
RedirectDestinationTrait:: |
protected | function | Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url. | |
RedirectDestinationTrait:: |
protected | function | Returns the redirect destination service. | |
RedirectDestinationTrait:: |
public | function | Sets the redirect destination service. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
UrlGeneratorTrait:: |
protected | property | The url generator. | |
UrlGeneratorTrait:: |
protected | function | Returns the URL generator service. | |
UrlGeneratorTrait:: |
public | function | Sets the URL generator service. | |
UrlGeneratorTrait:: |
protected | function | Generates a URL or path for a specific route based on the given parameters. |