class Role
Same name in this branch
- 9 core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role
- 9 core/modules/user/src/Plugin/views/access/Role.php \Drupal\user\Plugin\views\access\Role
- 9 core/modules/user/src/Plugin/migrate/source/d7/Role.php \Drupal\user\Plugin\migrate\source\d7\Role
Same name and namespace in other branches
- 11.x core/modules/user/src/Entity/Role.php \Drupal\user\Entity\Role
- 11.x core/modules/user/src/Plugin/views/access/Role.php \Drupal\user\Plugin\views\access\Role
- 11.x core/modules/user/src/Plugin/migrate/source/d6/Role.php \Drupal\user\Plugin\migrate\source\d6\Role
- 11.x core/modules/user/src/Plugin/migrate/source/d7/Role.php \Drupal\user\Plugin\migrate\source\d7\Role
Drupal 6 role source from database.
For available configuration keys, refer to the parent classes.
Plugin annotation
@MigrateSource(
id = "d6_user_role",
source_module = "user"
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase extends \Drupal\Component\Plugin\PluginInspectionInterface, \Drupal\Component\Plugin\DerivativeInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
- class \Drupal\migrate\Plugin\migrate\source\SourcePluginBase extends \Drupal\migrate\Plugin\MigrateSourceInterface, \Drupal\migrate\Event\RollbackAwareInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\migrate\Plugin\migrate\source\SqlBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\migrate\Plugin\RequirementsInterface implements \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
- class \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase extends \Drupal\Component\Plugin\DependentPluginInterface uses \Drupal\Core\Entity\DependencyTrait implements \Drupal\migrate\Plugin\migrate\source\SqlBase
- class \Drupal\user\Plugin\migrate\source\d6\Role implements \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase
- class \Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase extends \Drupal\Component\Plugin\DependentPluginInterface uses \Drupal\Core\Entity\DependencyTrait implements \Drupal\migrate\Plugin\migrate\source\SqlBase
- class \Drupal\migrate\Plugin\migrate\source\SqlBase extends \Drupal\Core\Plugin\ContainerFactoryPluginInterface, \Drupal\migrate\Plugin\RequirementsInterface implements \Drupal\migrate\Plugin\migrate\source\SourcePluginBase
- class \Drupal\migrate\Plugin\migrate\source\SourcePluginBase extends \Drupal\migrate\Plugin\MigrateSourceInterface, \Drupal\migrate\Event\RollbackAwareInterface implements \Drupal\Core\Plugin\PluginBase
- class \Drupal\Core\Plugin\PluginBase uses \Drupal\Core\StringTranslation\StringTranslationTrait, \Drupal\Core\DependencyInjection\DependencySerializationTrait, \Drupal\Core\Messenger\MessengerTrait implements \Drupal\Component\Plugin\PluginBase
Expanded class hierarchy of Role
See also
\Drupal\migrate\Plugin\migrate\source\SqlBase
\Drupal\migrate\Plugin\migrate\source\SourcePluginBase
34 string references to 'Role'
- Block::query in core/
modules/ block/ src/ Plugin/ migrate/ source/ Block.php - ChangeUserRoleBase::buildConfigurationForm in core/
modules/ user/ src/ Plugin/ Action/ ChangeUserRoleBase.php - drupal6.php in core/
modules/ migrate_drupal/ tests/ fixtures/ drupal6.php - A database agnostic dump for testing purposes.
- drupal6.php in core/
modules/ aggregator/ tests/ fixtures/ drupal6.php - A database agnostic dump for testing purposes.
- drupal7.php in core/
modules/ rdf/ tests/ fixtures/ drupal7.php - A database agnostic dump for testing purposes.
File
-
core/
modules/ user/ src/ Plugin/ migrate/ source/ d6/ Role.php, line 21
Namespace
Drupal\user\Plugin\migrate\source\d6View source
class Role extends DrupalSqlBase {
/**
* List of filter IDs per role IDs.
*
* @var array
*/
protected $filterPermissions = [];
/**
* {@inheritdoc}
*/
public function query() {
$query = $this->select('role', 'r')
->fields('r', [
'rid',
'name',
])
->orderBy('r.rid');
return $query;
}
/**
* {@inheritdoc}
*/
public function fields() {
return [
'rid' => $this->t('Role ID.'),
'name' => $this->t('The name of the user role.'),
];
}
/**
* {@inheritdoc}
*/
protected function initializeIterator() {
$filter_roles = $this->select('filter_formats', 'f')
->fields('f', [
'format',
'roles',
])
->execute()
->fetchAllKeyed();
foreach ($filter_roles as $format => $roles) {
// Drupal 6 code: $roles = ','. implode(',', $roles) .',';
// Remove the beginning and ending comma.
foreach (explode(',', trim($roles, ',')) as $rid) {
$this->filterPermissions[$rid][] = $format;
}
}
return parent::initializeIterator();
}
/**
* {@inheritdoc}
*/
public function prepareRow(Row $row) {
$rid = $row->getSourceProperty('rid');
$permissions = $this->select('permission', 'p')
->fields('p', [
'perm',
])
->condition('rid', $rid)
->execute()
->fetchField();
// If a role has no permissions then set to an empty array. The role will
// be migrated and given the default D8 permissions.
if ($permissions) {
$row->setSourceProperty('permissions', explode(', ', $permissions));
}
else {
$row->setSourceProperty('permissions', []);
}
if (isset($this->filterPermissions[$rid])) {
$row->setSourceProperty("filter_permissions:{$rid}", $this->filterPermissions[$rid]);
}
return parent::prepareRow($row);
}
/**
* {@inheritdoc}
*/
public function getIds() {
$ids['rid']['type'] = 'integer';
return $ids;
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.