final class LayoutBuilderMigrationConfirmForm in Panelizer 8.5
A confirmation form for migrating an entity display to Layout Builder.
Hierarchy
- class \Drupal\Core\Form\FormBase implements ContainerInjectionInterface, FormInterface uses DependencySerializationTrait, LoggerChannelTrait, MessengerTrait, LinkGeneratorTrait, RedirectDestinationTrait, UrlGeneratorTrait, StringTranslationTrait
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
- class \Drupal\panelizer\Form\LayoutBuilderMigrationConfirmForm
- class \Drupal\Core\Form\ConfirmFormBase implements ConfirmFormInterface
Expanded class hierarchy of LayoutBuilderMigrationConfirmForm
1 string reference to 'LayoutBuilderMigrationConfirmForm'
File
- src/
Form/ LayoutBuilderMigrationConfirmForm.php, line 20
Namespace
Drupal\panelizer\FormView source
final class LayoutBuilderMigrationConfirmForm extends ConfirmFormBase {
/**
* The entity display repository service.
*
* @var \Drupal\Core\Entity\EntityDisplayRepositoryInterface
*/
private $entityDisplayRepository;
/**
* The entity type manager service.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
private $entityTypeManager;
/**
* LayoutBuilderMigrationConfirmForm constructor.
*
* @param \Drupal\Core\Entity\EntityDisplayRepositoryInterface $entity_display_repository
* The entity display repository service.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager service.
* @param \Drupal\Core\Routing\RouteMatchInterface $route_match
* (optional) The current route match service.
* @param \Drupal\Core\StringTranslation\TranslationInterface $translation
* (optional) The string translation service.
*/
public function __construct(EntityDisplayRepositoryInterface $entity_display_repository, EntityTypeManagerInterface $entity_type_manager, RouteMatchInterface $route_match = NULL, TranslationInterface $translation = NULL) {
$this->entityDisplayRepository = $entity_display_repository;
$this->entityTypeManager = $entity_type_manager;
$this->routeMatch = $route_match;
if ($translation) {
$this
->setStringTranslation($translation);
}
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container) {
return new static($container
->get('entity_display.repository'), $container
->get('entity_type.manager'), $container
->get('current_route_match'), $container
->get('string_translation'));
}
/**
* Determines access to the form.
*
* @return \Drupal\Core\Access\AccessResult
* The access result.
*/
public function access() {
$entity_type_id = $this
->getDisplay()
->getTargetEntityTypeId();
return AccessResult::allowedIfHasPermission($this
->currentUser(), "administer {$entity_type_id} display");
}
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'panelizer_layout_builder_migration_confirm_form';
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$form_state
->setRedirectUrl($this
->getCancelUrl());
$display = $this
->getDisplay();
$batch = LayoutBuilderMigration::fromDisplay($display)
->toArray();
batch_set($batch);
}
/**
* Returns the entity view display being migrated.
*
* @return \Drupal\layout_builder\Entity\LayoutEntityDisplayInterface
* The entity view display being migrated.
*/
private function getDisplay() {
$route_match = $this
->getRouteMatch();
return $this->entityDisplayRepository
->getViewDisplay($route_match
->getParameter('entity_type_id'), $route_match
->getParameter('bundle'), $route_match
->getParameter('view_mode'));
}
/**
* {@inheritdoc}
*/
public function getCancelUrl() {
$display = $this
->getDisplay();
$entity_type_id = $display
->getTargetEntityTypeId();
$parameters = FieldUI::getRouteBundleParameter($this->entityTypeManager
->getDefinition($entity_type_id), $display
->getTargetBundle());
$parameters['view_mode_name'] = $display
->getMode();
return Url::fromRoute("entity.entity_view_display.{$entity_type_id}.view_mode", $parameters);
}
/**
* {@inheritdoc}
*/
public function getQuestion() {
return $this
->t('Are you sure you want to migrate this entity display to Layout Builder?');
}
/**
* {@inheritdoc}
*/
public function getDescription() {
$description = '';
$description .= '<p>' . $this
->t('Hold your horses, cowpoke. <strong>This migration has <em>NOT</em> been thoroughly tested</strong>, and it will modify both the content and configuration of your site. That means <strong>there is a risk of data loss!</strong>') . '</p>';
$description .= '<p>' . $this
->t('If you choose to proceed, it is <strong><em>strongly recommended that you back up</em></strong> your database and configuration first, in case things go wrong and you need to restore everything to a pre-migration state. You should also thoroughly examine your site after the migration to ensure everything looks and works the way you expect it to.') . '</p>';
$description .= '<p>' . $this
->t('If you discover problems, please <a href=":url">post an issue in the Panelizer issue queue</a> describing what went awry, in much detail as possible. That will help us fix it and make this migration better for everyone.', [
':url' => 'https://www.drupal.org/node/add/project-issue/panelizer',
]) . '</p>';
$description .= '<p>' . $this
->t('You <strong>cannot undo this operation!</strong>') . '</p>';
return $description;
}
/**
* {@inheritdoc}
*/
public function getConfirmText() {
return $this
->t('I understand the risks and have backed up my database. Proceed!');
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ConfirmFormBase:: |
public | function |
Form constructor. Overrides FormInterface:: |
21 |
ConfirmFormBase:: |
public | function |
Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface:: |
1 |
ConfirmFormBase:: |
public | function |
Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface:: |
|
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. | |
FormBase:: |
public | function |
Form validation handler. Overrides FormInterface:: |
62 |
LayoutBuilderMigrationConfirmForm:: |
private | property | The entity display repository service. | |
LayoutBuilderMigrationConfirmForm:: |
private | property | The entity type manager service. | |
LayoutBuilderMigrationConfirmForm:: |
public | function | Determines access to the form. | |
LayoutBuilderMigrationConfirmForm:: |
public static | function |
Instantiates a new instance of this class. Overrides FormBase:: |
|
LayoutBuilderMigrationConfirmForm:: |
public | function |
Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface:: |
|
LayoutBuilderMigrationConfirmForm:: |
public | function |
Returns a caption for the button that confirms the action. Overrides ConfirmFormBase:: |
|
LayoutBuilderMigrationConfirmForm:: |
public | function |
Returns additional text to display as a description. Overrides ConfirmFormBase:: |
|
LayoutBuilderMigrationConfirmForm:: |
private | function | Returns the entity view display being migrated. | |
LayoutBuilderMigrationConfirmForm:: |
public | function |
Returns a unique string identifying the form. Overrides FormInterface:: |
|
LayoutBuilderMigrationConfirmForm:: |
public | function |
Returns the question to ask the user. Overrides ConfirmFormInterface:: |
|
LayoutBuilderMigrationConfirmForm:: |
public | function |
Form submission handler. Overrides FormInterface:: |
|
LayoutBuilderMigrationConfirmForm:: |
public | function | LayoutBuilderMigrationConfirmForm 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. |