function RolesLookup::transform

Same name and namespace in other branches
  1. 10 core/modules/block/src/Plugin/migrate/process/RolesLookup.php \Drupal\block\Plugin\migrate\process\RolesLookup::transform()

Overrides ProcessPluginBase::transform

File

core/modules/block/src/Plugin/migrate/process/RolesLookup.php, line 88

Class

RolesLookup
Gets the destination roles ID for an array of source roles IDs.

Namespace

Drupal\block\Plugin\migrate\process

Code

public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $roles = $row->get('roles');
    $roles_result = [];
    // If the block is assigned to specific roles, add the user_role condition.
    if ($roles) {
        foreach ($roles as $role_id) {
            $lookup_result = $this->migrateLookup
                ->lookup([
                $this->migration,
            ], [
                $role_id,
            ]);
            if ($lookup_result) {
                $roles_result[$role_id] = $lookup_result[0]['id'];
            }
        }
    }
    return $roles_result;
}

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