media_acquiadam-8.x-1.46/src/Form/AcquiadamMigrationSummaryForm.php

src/Form/AcquiadamMigrationSummaryForm.php
<?php

namespace Drupal\media_acquiadam\Form;

use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\media_acquiadam\Traits\MigrationTrait;

/**
 * The class defines the form for displaying migration summary.
 */
class AcquiadamMigrationSummaryForm {

  use StringTranslationTrait;
  use MigrationTrait;

  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $stored_values = $this->getMigrationConfig();

    // Add form elements for displaying migration summary.
    $form['summary'] = [
      '#type' => 'html_tag',
      '#tag' => 'p',
      '#value' => $this->t('As part of this migration process, we are updating the existing media type
       (provided by the legacy module media_acquiadam) by replacing its source with the new one from the
       acquia_dam module. Also, legacy media types without media items will be automatically deleted after migration.
       We also recommend deleting the newly created media types from the acquia_dam module that are mapped to replace
       legacy media, unless they have been explicitly excluded.'),
    ];

    // Get media type to be deleted.
    $bundle_to_delete = self::getMediaTypeDeletionList($stored_values);
    // List media types that will be deleted as part of migration.
    if ($bundle_to_delete) {
      $form['media_bundle_delete_info']['h6'] = [
        '#type' => 'html_tag',
        '#tag' => 'h6',
        '#value' => $this->t('Media types marked for deletion:'),
      ];
      $form['media_bundle_delete_info']['media_types'] = [
        '#type' => 'html_tag',
        '#tag' => 'ul',
      ];
      foreach ($bundle_to_delete as $bundle) {
        $form['media_bundle_delete_info']['media_types'][] = [
          '#type' => 'html_tag',
          '#tag' => 'li',
          '#value' => $bundle,
          '#attributes' => [
            'style' => 'color: red; font-style: italic;',
          ],
        ];
      }
    }

    // List of media types that will be updated.
    $bundle_to_update = self::getMediaTypeUpdateList($stored_values);
    if ($bundle_to_update) {
      $form['media_bundle_update']['h6'] = [
        '#type' => 'html_tag',
        '#tag' => 'h6',
        '#value' => $this->t('Media types label marked for update:'),
      ];
      $form['media_bundle_update']['media_label'] = [
        '#type' => 'html_tag',
        '#tag' => 'ul',
      ];
      foreach ($bundle_to_update as $bundle) {
        $form['media_bundle_update']['media_label'][] = [
          '#type' => 'html_tag',
          '#tag' => 'li',
          '#value' => $this->t('@old_media_label → <strong>@new_media_label</strong>', [
            '@old_media_label' => $bundle['old_media_label'],
            '@new_media_label' => $bundle['new_media_label'],
          ]),
        ];
      }
    }

    // Get the media counts.
    $counts = $this->getMediaCounts(array_keys($this->getEntityTypeManager()->getStorage('media_type')
      ->loadByProperties(['source_configuration.source_field' => 'field_acquiadam_asset_id'])));

    // Media type mapping.
    if (isset($stored_values['legacy_dam_media_types']) && $stored_values['legacy_dam_media_types']) {
      $form['media_bundle_update_info'] = [
        '#type' => 'table',
        '#header' => [
          $this->t('Media type label and name'),
          $this->t('Method to handle media files'),
          $this->t('Target source type'),
          $this->t('Number of Media Items'),
        ],
        '#caption' => $this->t('This table lists the media bundles that will be updated during the migration process.'),
        '#rows' => [],
      ];
      foreach ($stored_values['legacy_dam_media_types'] as $bundle_data) {
        if (isset($bundle_data['target_source_type'])) {
          $form['media_bundle_update_info']['#rows'][] = [
            $bundle_data['media_type_label'],
            ($bundle_data['sync_method'] == 'sync') ? $this->t('Sync') : $this->t('Embed'),
            $this->getMediaSourcePluginManager()
              ->createInstance($bundle_data['target_source_type'])
              ->getPluginDefinition()['label'],
            $counts[$bundle_data['media_type_id']],
          ];
        }
      }
    }

    // Key points to consider.
    $summary_data = [
      '<strong>Media type label and name:</strong>' => 'Legacy media types label which are mapped for migration.',
      '<strong>Method to handle media files:</strong>' => 'Mechanism to handle media files while rendering media items (sync or embed).',
      '<strong>Target source type:</strong>' => 'New source type for the media type being migrated.',
      '<strong>Number of Media Items:</strong>' => 'Total number of media items in the media type being migrated.',
    ];
    $form['summary']['key_points_h6'] = [
      '#type' => 'html_tag',
      '#tag' => 'h6',
      '#value' => $this->t('Key points to consider:'),
    ];
    $form['summary']['key_points'] = [
      '#type' => 'html_tag',
      '#tag' => 'ul',
    ];
    foreach ($summary_data as $key => $summary_item) {
      $form['summary']['key_points'][] = [
        '#type' => 'html_tag',
        '#tag' => 'li',
        '#value' => $key . ' ' . $this->t('@summary', ['@summary' => $summary_item]),
      ];
    }

    return $form;
  }

}

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

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