public function ParagraphsDemoUserText::convert

Submit the values taken from the form to store the values.

This method is responsible for submitting the data and saving it in the paragraphs entity.

Parameters

array $settings: The conversion settings to be applied.

\Drupal\paragraphs\ParagraphInterface $original_paragraph: The original paragraph to convert.

array $converted_paragraphs: (optional) The array of converted paragraphs.

Overrides ParagraphsConversionBase::convert

File

paragraphs/modules/paragraphs_demo/src/Plugin/paragraphs/Conversion/ParagraphsDemoUserText.php, line 25

Class

ParagraphsDemoUserText
Provides a Paragraphs conversion plugin.

Namespace

Drupal\paragraphs_demo\Plugin\paragraphs\Conversion

Code

public function convert(array $settings, ParagraphInterface $original_paragraph, array $converted_paragraphs = NULL) {
  $username = "Empty user field";
  if ($original_paragraph
    ->get('field_user_demo')->entity) {
    $username = $original_paragraph
      ->get('field_user_demo')->entity
      ->label();
  }
  $converted_paragraphs = [
    [
      'type' => 'text',
      'field_text_demo' => [
        'value' => $username,
      ],
    ],
  ];
  if ($settings['multiple']) {
    $converted_paragraphs[] = [
      'type' => 'text',
      'field_text_demo' => [
        'value' => $username,
      ],
    ];
  }
  return $converted_paragraphs;
}