drowl_paragraphs-8.x-3.9/modules/drowl_paragraphs_container2layout/src/Form/ConvertAllForm.php

modules/drowl_paragraphs_container2layout/src/Form/ConvertAllForm.php
<?php

namespace Drupal\drowl_paragraphs_container2layout\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Messenger\MessengerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\drowl_paragraphs_container2layout\ParagraphsConverter;

/**
 * Form to allow conversion of all container paragraphs to layout paragraphs.
 */
class ConvertAllForm extends FormBase {


  /**
   * The messenger.
   *
   * @var \Drupal\Core\Messenger\MessengerInterface
   */
  protected $messenger;

  /**
   * The paragraphs converter service.
   *
   * @var \Drupal\drowl_paragraphs_container2layout\ParagraphsConverter
   */
  protected $paragraphsConverter;

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('messenger'),
      $container->get('drowl_paragraphs_container2layout.paragraphs_converter')
    );
  }

  /**
   * ConvertAllForm constructor.
   *
   * @param \Drupal\Core\Messenger\MessengerInterface $messenger
   *   The messenger.
   * @param \Drupal\drowl_paragraphs_container2layout\ParagraphsConverter
   *   The paragraphs converter service.
   */
  public function __construct(MessengerInterface $messenger, ParagraphsConverter $paragraphsConverter) {
    $this->messenger = $messenger;
    $this->paragraphsConverter = $paragraphsConverter;
  }

  /**
   * {@inheritdoc}
   */
  public function getFormId() {
    return 'drowl_paragraphs_container2layout_convert_all';
  }

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $this->messenger->addWarning($this->t('The submission of this form can cause errors and data loss. Take a backup before submit and check all paragraphs and site functionality in detail afterwards!'), 'warning');
    $form['description'] = [
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => $this->t('Convert all "Container" paragraph entities to "Layout" paragraph entities on all entities. This allows to upgrade to drowl_paragraphs:^4 and to use layout_paragraphs module.'),
    ];
    $form['steps'] = [
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => $this->t("Take a restorable backup, delete orphaned composite entities, run the conversion and check the results. This will not result in 1:1 converted layouts in all cases as it's focused on most typical combinations. Manual alignment might be required!"),
    ];
    $form['actions'] = ['#type' => 'actions'];
    $form['actions']['submit'] = [
      '#type' => 'submit',
      '#button_type' => 'primary',
      '#value' => $this->t('Convert all Container Paragraphs to Layout Paragraphs'),
    ];

    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $this->paragraphsConverter->convertAllFromAllEntities();
    $this->messenger->addStatus('Container paragraphs have been converted. Check the results carefully and remove the unwanted fields from Layout Paragraph Type afterwards.');
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc