function MenuLink::prepareRow

Same name and namespace in other branches
  1. 9 core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php \Drupal\menu_link_content\Plugin\migrate\source\MenuLink::prepareRow()
  2. 8.9.x core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php \Drupal\menu_link_content\Plugin\migrate\source\MenuLink::prepareRow()
  3. 10 core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php \Drupal\menu_link_content\Plugin\migrate\source\MenuLink::prepareRow()

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 127

Class

MenuLink
Drupal 6/7 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);
        }
    }
    // In Drupal 6 the language for the menu is in the options array. Set
    // property 'is_localized' so that the process pipeline can determine if
    // the menu link is localize or not.
    $row->setSourceProperty('is_localized', NULL);
    $default_language = $this->variableGet('language_default', (object) [
        'language' => 'und',
    ]);
    $default_language = $default_language->language;
    $options = unserialize($row->getSourceProperty('options'));
    if (isset($options['langcode'])) {
        if ($options['langcode'] != $default_language) {
            $row->setSourceProperty('language', $options['langcode']);
            $row->setSourceProperty('is_localized', 'localized');
        }
    }
    $row->setSourceProperty('options', unserialize($row->getSourceProperty('options')));
    $row->setSourceProperty('enabled', !$row->getSourceProperty('hidden'));
    $description = $row->getSourceProperty('options/attributes/title');
    if ($description !== NULL) {
        $row->setSourceProperty('description', Unicode::truncate($description, 255));
    }
    return parent::prepareRow($row);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.