media_acquiadam-8.x-1.46/src/Form/AcquiadamMigrationMapForm.php
src/Form/AcquiadamMigrationMapForm.php
<?php
namespace Drupal\media_acquiadam\Form;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\media_acquiadam\Traits\MigrationTrait;
/**
* The acquia dam migration map form.
*/
class AcquiadamMigrationMapForm {
use StringTranslationTrait;
use MigrationTrait;
/**
* {@inheritdoc}
*/
public function buildForm($form, FormStateInterface $form_state) {
$stored_values = $this->getMigrationConfig();
$processed_stored_values = $this->processStoredValues($stored_values);
$form['wrapper'] = [
'#type' => 'container',
'#attributes' => ['id' => 'form-table-wrapper'],
];
$form['wrapper']['info'] = [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this->t('
<p>
This dashboard helps migrate legacy media types to Acquia DAM by
providing a mapping between <b>Media: Acquia DAM media types</b> and
their corresponding media source in Acquia DAM. This
dashboard allows you to track the progress of the migration and its
completion.
</p>
<p>The following outlines the details of each column:</p>
<ul>
<li>
<b>Media type label and name:</b> You can change the label while
migrating to the Acquia DAM system.
</li>
<li>
<b>Number of media items:</b> Count of DAM assets in each media type
which needs to be migrated.
</li>
<li>
<b>Method to handle media files:</b> Provided the two methods:
<ul>
<li><b>Sync:</b> This method will render your assets locally.</li>
<li><b>Embed:</b> This method will render the assets from Widen CDN.</li>
</ul>
</li>
<li>
<b>Target source type:</b> A list of Acquia DAM media sources from which
you can select the desired target source for migrating the asset.
</li>
</ul>
'),
];
$form['wrapper']['legacy_dam_media_types'] = [
'#type' => 'table',
'#header' => [
'media_type_label' => $this->t('Media type label and name'),
'media_count' => $this->t('Number of media items'),
'separator' => '',
'sync_method' => $this->t('Method to handle media files'),
'target_source_type' => $this->t('Target source type'),
],
'#attributes' => [
'id' => 'media_acquiadam_migration_table',
'style' => 'border: 1px solid #dee2e6; border-collapse: collapse;',
],
];
$legacy_dam_media_types = $this->getLegacyDamMediaTypes();
$media_source_plugins = $this->getAcquiaDamPluginAsOptions();
foreach ($legacy_dam_media_types as $legacy_dam_media_type) {
$form['wrapper']['legacy_dam_media_types'][] = [
'media_type_id' => [
'#type' => 'hidden',
'#value' => $legacy_dam_media_type['machine_name'],
'#wrapper_attributes' => ['style' => 'display: none;'],
],
'media_type_label' => [
'#type' => 'textfield',
'#default_value' => $processed_stored_values['legacy_dam_media_types'][$legacy_dam_media_type['machine_name']]['media_type_label'] ?? $legacy_dam_media_type['label'],
'#description' => $this->t('Machine name: <code>@media-type-machine-name</code>', [
'@media-type-machine-name' => $legacy_dam_media_type['machine_name'],
]),
'#maxlength' => 128,
'#size' => 20,
'#attributes' => [
'placeholder' => $this->t('e.g. @suggested_media_bundle_label', [
'@suggested_media_bundle_label' => $legacy_dam_media_type['label'],
]),
'disabled' => !$legacy_dam_media_type['count'],
],
],
'media_count' => $legacy_dam_media_type['count'] ? [
'#type' => 'html_tag',
'#tag' => 'h6',
'#value' => $legacy_dam_media_type['count'],
'#wrapper_attributes' => [
'style' => 'text-align: center;',
],
] : [
'#type' => 'html_tag',
'#tag' => 'h6',
'#value' => 0,
'#attributes' => [
'style' => 'color: gray; font-style: italic; text-align: center;',
],
],
'separator' => [
'#type' => 'html_tag',
'#tag' => 'span',
'#value' => $legacy_dam_media_type['count'] ? "\u{2794}" : "",
'#wrapper_attributes' => [
'style' => 'text-align: center; color: rgba(0, 0, 0, 0.33); font-size: 22px;',
],
],
'sync_method' => $legacy_dam_media_type['count'] ? [
'#type' => 'select',
'#options' => [
'embed' => $this->t('Embed'),
'sync' => $this->t('Sync'),
],
'#default_value' => $processed_stored_values['legacy_dam_media_types'][$legacy_dam_media_type['machine_name']]['sync_method'] ?? $legacy_dam_media_type['method'],
] : [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this->t('Delete'),
'#attributes' => [
'style' => 'color: red; font-style: italic;',
],
],
'target_source_type' => $legacy_dam_media_type['count'] ? [
'#type' => 'select',
'#options' => $media_source_plugins,
'#empty_option' => $this->t('- Select -'),
'#default_value' => $processed_stored_values['legacy_dam_media_types'][$legacy_dam_media_type['machine_name']]['target_source_type'] ?? '',
'#required' => TRUE,
] : [
'#type' => 'html_tag',
'#tag' => 'p',
'#value' => $this->t('Since there are no media items in this media type, it is marked for deletion.'),
],
];
}
return $form;
}
}
