You are here

public function MenuLink::prepareRow in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php \Drupal\menu_link_content\Plugin\migrate\source\MenuLink::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

3 calls to MenuLink::prepareRow()
MenuLinkLocalized::prepareRow in core/modules/menu_link_content/src/Plugin/migrate/source/d7/MenuLinkLocalized.php
Adds additional data to the row.
MenuLinkTranslation::prepareRow in core/modules/menu_link_content/src/Plugin/migrate/source/d6/MenuLinkTranslation.php
Adds additional data to the row.
MenuLinkTranslation::prepareRow in core/modules/menu_link_content/src/Plugin/migrate/source/d7/MenuLinkTranslation.php
Adds additional data to the row.
3 methods override MenuLink::prepareRow()
MenuLinkLocalized::prepareRow in core/modules/menu_link_content/src/Plugin/migrate/source/d7/MenuLinkLocalized.php
Adds additional data to the row.
MenuLinkTranslation::prepareRow in core/modules/menu_link_content/src/Plugin/migrate/source/d6/MenuLinkTranslation.php
Adds additional data to the row.
MenuLinkTranslation::prepareRow in core/modules/menu_link_content/src/Plugin/migrate/source/d7/MenuLinkTranslation.php
Adds additional data to the row.

File

core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php, line 83

Class

MenuLink
Drupal menu link source from database.

Namespace

Drupal\menu_link_content\Plugin\migrate\source

Code

public function prepareRow(Row $row) {

  // In Drupal 7 a language neutral menu_link can be translated. The menu
  // link is treated as if it is in the site default language. So, here
  // we look to see if this menu link has a translation and if so, the
  // language is changed to the default language. With the language set
  // the entity API will allow the saving of the translations.
  if ($row
    ->hasSourceProperty('language') && $row
    ->getSourceProperty('language') == 'und' && $this
    ->hasTranslation($row
    ->getSourceProperty('mlid'))) {
    $default_language = $this
      ->variableGet('language_default', (object) [
      'language' => 'und',
    ]);
    $default_language = $default_language->language;
    $row
      ->setSourceProperty('language', $default_language);
  }

  // If this menu link is part of translation set skip the translations. The
  // translations are migrated in d7_menu_link_localized.yml.
  $row
    ->setSourceProperty('skip_translation', TRUE);
  if ($row
    ->hasSourceProperty('i18n_tsid') && $row
    ->getSourceProperty('i18n_tsid') != 0) {
    $source_mlid = $this
      ->select('menu_links', 'ml')
      ->fields('ml', [
      'mlid',
    ])
      ->condition('i18n_tsid', $row
      ->getSourceProperty('i18n_tsid'))
      ->orderBy('mlid')
      ->range(0, 1)
      ->execute()
      ->fetchField();
    if ($source_mlid !== $row
      ->getSourceProperty('mlid')) {
      $row
        ->setSourceProperty('skip_translation', FALSE);
    }
  }
  $row
    ->setSourceProperty('options', unserialize($row
    ->getSourceProperty('options')));
  $row
    ->setSourceProperty('enabled', !$row
    ->getSourceProperty('hidden'));
  $row
    ->setSourceProperty('description', Unicode::truncate($row
    ->getSourceProperty('options/attributes/title'), 255));
  return parent::prepareRow($row);
}