class PanelizerWizardGeneralForm in Panelizer 8.4
Same name and namespace in other branches
- 8.5 src/Form/PanelizerWizardGeneralForm.php \Drupal\panelizer\Form\PanelizerWizardGeneralForm
- 8.3 src/Form/PanelizerWizardGeneralForm.php \Drupal\panelizer\Form\PanelizerWizardGeneralForm
General settings for a panelized bundle.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\panelizer\Form\PanelizerWizardGeneralForm
Expanded class hierarchy of PanelizerWizardGeneralForm
2 files declare their use of PanelizerWizardGeneralForm
- PanelizerAddWizard.php in src/
Wizard/ PanelizerAddWizard.php - PanelizerWizardBase.php in src/
Wizard/ PanelizerWizardBase.php
File
- src/
Form/ PanelizerWizardGeneralForm.php, line 15
Namespace
Drupal\panelizer\FormView source
class PanelizerWizardGeneralForm extends FormBase {
/**
* The SharedTempStore key for our current wizard values.
*
* @var string|NULL
*/
protected $machine_name;
/**
* The Panelizer service.
*
* @var \Drupal\panelizer\PanelizerInterface
*/
protected $panelizer;
/**
* The entity type ID for the layout being worked on.
*
* @var string
*/
protected $entityTypeId;
/**
* The entity bundle for the layout being worked on.
*
* @var string
*/
protected $bundle;
/**
* The view mode name for the layout being worked on.
*
* @var string
*/
protected $viewMode;
/**
* PanelizerWizardGeneralForm constructor.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* The current route match.
* @param \Drupal\panelizer\PanelizerInterface $panelizer
* The Panelizer service.
*/
public function __construct(RouteMatchInterface $route_match, PanelizerInterface $panelizer) {
$this->routeMatch = $route_match;
if ($route_match
->getRouteName() == 'panelizer.wizard.add') {
$this->entityTypeId = $route_match
->getParameter('entity_type_id');
$this->bundle = $route_match
->getParameter('bundle');
$this->viewMode = $route_match
->getParameter('view_mode_name');
}
$this->panelizer = $panelizer;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('current_route_match'), $container
->get('panelizer'));
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'panelizer_wizard_general_form';
}
/**
* @param $machine_name
* @param $element
*/
public static function validateMachineName($machine_name, $element) {
// Attempt to load via the machine name and entity type.
if (isset($element['#machine_name']['prefix'])) {
$panelizer = \Drupal::service('panelizer');
// Load the panels display variant.
$full_machine_name = $element['#machine_name']['prefix'] . '__' . $machine_name;
return $panelizer
->getDefaultPanelsDisplayByMachineName($full_machine_name);
}
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
/** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $plugin */
$plugin = $cached_values['plugin'];
$form_state = new FormState();
$form_state
->setValues($form_state
->getValue('variant_settings', []));
$settings = $plugin
->buildConfigurationForm([], $form_state);
// If the entity view display supports custom Panelizer layouts, force use
// of the in-place editor. Right now, there is no other way to work with
// custom layouts.
if (isset($cached_values['id'])) {
list($this->entityTypeId, $this->bundle, $this->viewMode) = explode('__', $cached_values['id']);
}
$panelizer_settings = $this->panelizer
->getPanelizerSettings($this->entityTypeId, $this->bundle, $this->viewMode);
if (!empty($panelizer_settings['custom'])) {
$settings['builder']['#default_value'] = 'ipe';
$settings['builder']['#access'] = FALSE;
}
$settings['#tree'] = TRUE;
$form['variant_settings'] = $settings;
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->hasValue('id') && !isset($this->machine_name) && $form_state
->has('machine_name_prefix')) {
$form_state
->setValue('id', "{$form_state->get('machine_name_prefix')}__{$form_state->getValue('id')}");
}
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$cached_values = $form_state
->getTemporaryValue('wizard');
/** @var \Drupal\panels\Plugin\DisplayVariant\PanelsDisplayVariant $plugin */
$plugin = $cached_values['plugin'];
$plugin
->submitConfigurationForm($form['variant_settings'], (new FormState())
->setValues($form_state
->getValue('variant_settings', [])));
$configuration = $plugin
->getConfiguration();
$cached_values['plugin']
->setConfiguration($configuration);
}
}
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. | |
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. | |
PanelizerWizardGeneralForm:: |
protected | property | The entity bundle for the layout being worked on. | |
PanelizerWizardGeneralForm:: |
protected | property | The entity type ID for the layout being worked on. | |
PanelizerWizardGeneralForm:: |
protected | property | The SharedTempStore key for our current wizard values. | |
PanelizerWizardGeneralForm:: |
protected | property | The Panelizer service. | |
PanelizerWizardGeneralForm:: |
protected | property | The view mode name for the layout being worked on. | |
PanelizerWizardGeneralForm:: |
public | function |
Form constructor. Overrides FormInterface:: |
|
PanelizerWizardGeneralForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
PanelizerWizardGeneralForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
PanelizerWizardGeneralForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
PanelizerWizardGeneralForm:: |
public | function |
Form validation handler. Overrides FormBase:: |
|
PanelizerWizardGeneralForm:: |
public static | function | ||
PanelizerWizardGeneralForm:: |
public | function | PanelizerWizardGeneralForm constructor. | |
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. |