<?php

namespace Drupal\entity_type_extras\Plugin\paragraphs\Conversion;

use Drupal\paragraphs\ParagraphInterface;
use Drupal\paragraphs\ParagraphsConversionBase;

/**
 * Converts paragraphs of the type text_media_vertical to text_media_horizontal.
 *
 * @ParagraphsConversion(
 *   id = "text_media_horizontal_to_text_media_vertical",
 *   label = @Translation("Text/media vertical"),
 *   source_type = "text_media_horizontal",
 *   target_type = "text_media_vertical",
 * )
 */
class TextMediaHorizontalToTextMediaVertical extends ParagraphsConversionBase {

  /**
   * {@inheritdoc}
   */
  public function convert(
    array $settings,
    ParagraphInterface $original_paragraph,
    ?array $converted_paragraph = NULL,
  ): array {
    return [
      [
        'type' => 'text_media_vertical',
        'field_title_formatted' => $original_paragraph->get('field_title_formatted'),
        'field_text' => $original_paragraph->get('field_text')->value,
        'field_link' => $original_paragraph->get('field_link'),
        'field_mediaref_single' => $original_paragraph->get('field_mediaref_single'),
        'field_emphasized' => $original_paragraph->get('field_emphasized'),
      ],
    ];
  }

}
