You are here

public function D7FlagForList::prepareRow in Flag Lists 8

Same name and namespace in other branches
  1. 4.0.x src/Plugin/migrate/source/D7FlagForList.php \Drupal\flag_lists\Plugin\migrate\source\D7FlagForList::prepareRow()

Adds additional data to the row.

Parameters

\Drupal\migrate\Row $row: The row object.

Return value

bool FALSE if this row needs to be skipped.

Overrides SourcePluginBase::prepareRow

File

src/Plugin/migrate/source/D7FlagForList.php, line 72

Class

D7FlagForList
Minimalistic example for a SqlBase source plugin.

Namespace

Drupal\flag_lists\Plugin\migrate\source

Code

public function prepareRow(Row $row) {

  // Check and get the user name.
  $uid = $row
    ->getSourceProperty('uid');
  $user = User::load($uid);
  if (!empty($user)) {
    $owner = $user
      ->get('name')->value;
  }
  else {
    $user = User::load('1');
    $owner = $user
      ->get('name')->value;
  }
  $row
    ->setSourceProperty('uid', $owner);

  // Check if the template flag exist.
  $found = FALSE;
  $flagService = \Drupal::service('flag');
  $templateFlags = $flagService
    ->getAllFlags($row
    ->getSourceProperty('entity_type'));
  foreach ($templateFlags as $flag) {
    if ($found = $flag
      ->get('id') == $row
      ->getSourceProperty('name')) {
      break;
    }
  }
  if (!$found) {
    $message = $this
      ->t('The template flag "@flag" wasn\'t found.', [
      '@flag' => $row
        ->getSourceProperty('title'),
    ]);
    $messenger = \Drupal::messenger();
    $logger = \Drupal::logger('flag_lists');
    $messenger
      ->addWarning($message);
    $logger
      ->warning($message);
  }
  return parent::prepareRow($row);
}