You are here

class DomainUserHandler in Domain Access 7.3

Migration class for supporting Drupal user accounts.

In our migration class, you may add a domain_user field mapping. This field may contain a domain_id string or array of domain ids (either numeric or machine_name, and you may mix the two).

If you fail to set domain_user, the user will be assigned to the default domain, if it exists.

Hierarchy

Expanded class hierarchy of DomainUserHandler

1 string reference to 'DomainUserHandler'
domain_migrate_api in ./domain.module

File

./domain.migrate.inc, line 298
Support for domains in core Drupal objects

View source
class DomainUserHandler extends MigrateDestinationHandler {
  public function __construct() {
    $this
      ->registerTypes(array(
      'user',
    ));
  }
  public function fields() {
    $fields = array(
      'domain_user' => t('Domain: assigned domains'),
    );
    return $fields;
  }
  public function prepare($user, stdClass $row) {

    // If set, ensure domains exist.
    $domains = array();
    if (isset($user->uid)) {
      domain_user_set($user);
    }
    if (isset($user->domain_user)) {
      $user->domain_user = (array) $user->domain_user;
      foreach ($user->domain_user as $id) {
        if ($domain = domain_load($id)) {
          $domains[$domain['domain_id']] = $domain['domain_id'];
        }
        if ($domain = domain_machine_name_load($id)) {
          $domains[$domain['domain_id']] = $domain['domain_id'];
        }
      }
    }

    // If empty, assign to the default domain.
    if (empty($domains) && ($default = domain_default_id())) {
      $domains[$default] = $default;
    }
    $user->domain_user = $domains;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DomainUserHandler::fields public function
DomainUserHandler::prepare public function
DomainUserHandler::__construct public function Overrides MigrateHandler::__construct
MigrateHandler::$dependencies protected property List of other handler classes which should be invoked before the current one.
MigrateHandler::$typesHandled protected property List of "types" handled by this handler. Depending on the kind of handler, these may be destination types, field types, etc.
MigrateHandler::getDependencies public function
MigrateHandler::getTypesHandled public function
MigrateHandler::handlesType public function Does this handler handle the given type? 1
MigrateHandler::registerTypes protected function Register a list of types handled by this class