function EntityUserRole::import

Same name in other branches
  1. 10 core/modules/user/src/Plugin/migrate/destination/EntityUserRole.php \Drupal\user\Plugin\migrate\destination\EntityUserRole::import()

Overrides EntityConfigBase::import

File

core/modules/user/src/Plugin/migrate/destination/EntityUserRole.php, line 75

Class

EntityUserRole
Provides a destination plugin for migrating user role entities.

Namespace

Drupal\user\Plugin\migrate\destination

Code

public function import(Row $row, array $old_destination_id_values = []) : array|bool {
    $permissions = $row->getDestinationProperty('permissions') ?? [];
    // Get permissions that do not exist on the destination.
    $invalid_permissions = array_diff($permissions, $this->destinationPermissions);
    if ($invalid_permissions) {
        sort($invalid_permissions);
        // Log the message in the migration message table.
        $message = "Permission(s) '" . implode("', '", $invalid_permissions) . "' not found.";
        $this->migration
            ->getIdMap()
            ->saveMessage($row->getSourceIdValues(), $message, MigrationInterface::MESSAGE_WARNING);
    }
    $valid_permissions = array_intersect($permissions, $this->destinationPermissions);
    $row->setDestinationProperty('permissions', $valid_permissions);
    return parent::import($row, $old_destination_id_values);
}

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