You are here

final class LayoutBuilderMigrationConfirmForm in Panelizer 8.5

A confirmation form for migrating an entity display to Layout Builder.

Hierarchy

Expanded class hierarchy of LayoutBuilderMigrationConfirmForm

1 string reference to 'LayoutBuilderMigrationConfirmForm'
panelizer.routing.yml in ./panelizer.routing.yml
panelizer.routing.yml

File

src/Form/LayoutBuilderMigrationConfirmForm.php, line 20

Namespace

Drupal\panelizer\Form
View 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

Namesort descending Modifiers Type Description Overrides
ConfirmFormBase::buildForm public function Form constructor. Overrides FormInterface::buildForm 21
ConfirmFormBase::getCancelText public function Returns a caption for the link which cancels the action. Overrides ConfirmFormInterface::getCancelText 1
ConfirmFormBase::getFormName public function Returns the internal name used to refer to the confirmation item. Overrides ConfirmFormInterface::getFormName
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
FormBase::$configFactory protected property The config factory. 1
FormBase::$requestStack protected property The request stack. 1
FormBase::$routeMatch protected property The route match.
FormBase::config protected function Retrieves a configuration object.
FormBase::configFactory protected function Gets the config factory for this form. 1
FormBase::container private function Returns the service container.
FormBase::currentUser protected function Gets the current user.
FormBase::getRequest protected function Gets the request object.
FormBase::getRouteMatch protected function Gets the route match.
FormBase::logger protected function Gets the logger for a specific channel.
FormBase::redirect protected function Returns a redirect response object for the specified route. Overrides UrlGeneratorTrait::redirect
FormBase::resetConfigFactory public function Resets the configuration factory.
FormBase::setConfigFactory public function Sets the config factory for this form.
FormBase::setRequestStack public function Sets the request stack object to use.
FormBase::validateForm public function Form validation handler. Overrides FormInterface::validateForm 62
LayoutBuilderMigrationConfirmForm::$entityDisplayRepository private property The entity display repository service.
LayoutBuilderMigrationConfirmForm::$entityTypeManager private property The entity type manager service.
LayoutBuilderMigrationConfirmForm::access public function Determines access to the form.
LayoutBuilderMigrationConfirmForm::create public static function Instantiates a new instance of this class. Overrides FormBase::create
LayoutBuilderMigrationConfirmForm::getCancelUrl public function Returns the route to go to if the user cancels the action. Overrides ConfirmFormInterface::getCancelUrl
LayoutBuilderMigrationConfirmForm::getConfirmText public function Returns a caption for the button that confirms the action. Overrides ConfirmFormBase::getConfirmText
LayoutBuilderMigrationConfirmForm::getDescription public function Returns additional text to display as a description. Overrides ConfirmFormBase::getDescription
LayoutBuilderMigrationConfirmForm::getDisplay private function Returns the entity view display being migrated.
LayoutBuilderMigrationConfirmForm::getFormId public function Returns a unique string identifying the form. Overrides FormInterface::getFormId
LayoutBuilderMigrationConfirmForm::getQuestion public function Returns the question to ask the user. Overrides ConfirmFormInterface::getQuestion
LayoutBuilderMigrationConfirmForm::submitForm public function Form submission handler. Overrides FormInterface::submitForm
LayoutBuilderMigrationConfirmForm::__construct public function LayoutBuilderMigrationConfirmForm constructor.
LinkGeneratorTrait::$linkGenerator protected property The link generator. 1
LinkGeneratorTrait::getLinkGenerator Deprecated protected function Returns the link generator.
LinkGeneratorTrait::l Deprecated protected function Renders a link to a route given a route name and its parameters.
LinkGeneratorTrait::setLinkGenerator Deprecated public function Sets the link generator service.
LoggerChannelTrait::$loggerFactory protected property The logger channel factory service.
LoggerChannelTrait::getLogger protected function Gets the logger for a specific channel.
LoggerChannelTrait::setLoggerFactory public function Injects the logger channel factory.
MessengerTrait::$messenger protected property The messenger. 29
MessengerTrait::messenger public function Gets the messenger. 29
MessengerTrait::setMessenger public function Sets the messenger.
RedirectDestinationTrait::$redirectDestination protected property The redirect destination service. 1
RedirectDestinationTrait::getDestinationArray protected function Prepares a 'destination' URL query parameter for use with \Drupal\Core\Url.
RedirectDestinationTrait::getRedirectDestination protected function Returns the redirect destination service.
RedirectDestinationTrait::setRedirectDestination public function Sets the redirect destination service.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.
UrlGeneratorTrait::$urlGenerator protected property The url generator.
UrlGeneratorTrait::getUrlGenerator Deprecated protected function Returns the URL generator service.
UrlGeneratorTrait::setUrlGenerator Deprecated public function Sets the URL generator service.
UrlGeneratorTrait::url Deprecated protected function Generates a URL or path for a specific route based on the given parameters.