<?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_vertical_to_text_media_horizontal",
 *   label = @Translation("Text/media horizontal"),
 *   source_type = "text_media_vertical",
 *   target_type = "text_media_horizontal",
 * )
 */
class TextMediaVerticalToTextMediaHorizontal extends ParagraphsConversionBase {

  /**
   * {@inheritdoc}
   */
  public function convert(
    array $settings,
    ParagraphInterface $original_paragraph,
    ?array $converted_paragraph = NULL,
  ): array {
    return [
      [
        'type' => 'text_media_horizontal',
        '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'),
      ],
    ];
  }

}
