public function ParagraphsDemoUserToTextUser::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/ParagraphsDemoUserToTextUser.php, line 24

Class

ParagraphsDemoUserToTextUser
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";
  $user = NULL;
  if ($original_paragraph
    ->get('field_user_demo')->entity) {
    $username = $original_paragraph
      ->get('field_user_demo')->entity
      ->label();
    $user = $original_paragraph
      ->get('field_user_demo')->entity;
  }
  return [
    [
      'type' => 'text',
      'field_text_demo' => [
        'value' => $username,
      ],
    ],
    [
      'type' => 'user',
      'field_user_demo' => $user ?: NULL,
    ],
  ];
}