Facebook
From Crippled Stork, 7 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 282
  1. <?php
  2.  
  3. class CustomParagraphsBookmaker extends ProcessPluginBase {
  4.  
  5.   /**
  6.    * {@inheritdoc}
  7.    */
  8.   public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
  9.     $source = $row->getSource();
  10.  
  11.     $paragraphs = [];
  12.  
  13.     for($i = 1; $i <= 7; $i++) {
  14.       if (!empty($source['field_heading_' . $i][0]['value'])) {
  15.         $paragraph = Paragraph::create([
  16.           'type' => 'paragraph',
  17.           'field_textfield' => $source['field_heading_' . $i][0]['value'],
  18.           'field_textfield2' => $source['field_anchor_' . $i][0]['value'],
  19.           'field_textarea' => array('value' => $source['field_body_' . $i][0]['value'], 'format' => 'full_html'),
  20.         ]);
  21.         $paragraph->save();
  22.         $paragraphs[] = array(
  23.           'target_id' => $paragraph->id(),
  24.           'target_revision_id' => $paragraph->getRevisionId(),
  25.         );
  26.       }
  27.     }
  28.  
  29.     return $paragraphs;
  30.   }
  31. }
  32.