function hook_paragraphs_conversion_alter

Alters the paragraphs after conversion.

This hook is fired once per converted paragraph entity. The hook implementations must handle paragraphs translations on their own.

Parameters

\Drupal\paragraphs\ParagraphInterface $original: The original paragraph entity.

\Drupal\paragraphs\ParagraphInterface $converted: The converted paragraph entity.

File

paragraphs/paragraphs.api.php, line 63
Hooks and documentation related to paragraphs module.

Code

function hook_paragraphs_conversion_alter(ParagraphInterface $original, ParagraphInterface $converted) {

  // Alter the converted text value.
  if ($converted
    ->bundle() == 'text_image') {
    $field_name = 'field_text_demo';
    if ($converted
      ->hasField($field_name) && !$converted
      ->get($field_name)
      ->isEmpty()) {
      $value = implode(', ', [
        'New',
        $converted
          ->get($field_name)->value,
      ]);
      $converted
        ->set($field_name, $value);
    }
  }
}