class FeedsUserProcessor in Feeds 8.2
Defines a user processor.
Creates Users from feed items.
Plugin annotation
@Plugin(
id = "user",
title = @Translation("User processor"),
description = @Translation("Creates users from feed items.")
)
Hierarchy
- class \Drupal\feeds\Plugin\FeedsConfigurable
- class \Drupal\feeds\Plugin\FeedsPlugin implements FeedsSourceInterface
- class \Drupal\feeds\Plugin\FeedsProcessor
- class \Drupal\feeds\Plugin\feeds\processor\FeedsUserProcessor
- class \Drupal\feeds\Plugin\FeedsProcessor
- class \Drupal\feeds\Plugin\FeedsPlugin implements FeedsSourceInterface
Expanded class hierarchy of FeedsUserProcessor
3 string references to 'FeedsUserProcessor'
- FeedsUIUserInterfaceTestCase::testEditFeedConfiguration in feeds_ui/
feeds_ui.test - UI functionality tests on feeds_ui_overview(), feeds_ui_create_form(), Change plugins on feeds_ui_edit_page().
- feeds_import_feeds_importer_default in feeds_import/
feeds_import.feeds_importer_default.inc - Implementation of hook_feeds_importer_default().
- _feeds_feeds_plugins in ./
feeds.plugins.inc - Break out for feeds_feed_plugins().
File
- lib/
Drupal/ feeds/ Plugin/ feeds/ processor/ FeedsUserProcessor.php, line 28 - FeedsUserProcessor class.
Namespace
Drupal\feeds\Plugin\feeds\processorView source
class FeedsUserProcessor extends FeedsProcessor {
/**
* Define entity type.
*/
public function entityType() {
return 'user';
}
/**
* Implements parent::entityInfo().
*/
protected function entityInfo() {
$info = parent::entityInfo();
$info['label plural'] = t('Users');
return $info;
}
/**
* Creates a new user account in memory and returns it.
*/
protected function newEntity(FeedsSource $source) {
return entity_create('user', array(
'uid' => 0,
'roles' => array_filter($this->config['roles']),
'status' => $this->config['status'],
));
}
/**
* Loads an existing user.
*/
protected function entityLoad(FeedsSource $source, $uid) {
$user = parent::entityLoad($source, $uid);
// Copy the password so that we can compare it again at save.
$user->feeds_original_pass = $user->pass;
return $user;
}
/**
* Validates a user account.
*/
protected function entityValidate($account) {
if (empty($account->name) || empty($account->mail) || !valid_email_address($account->mail)) {
throw new FeedsValidationException(t('User name missing or email not valid.'));
}
}
/**
* Save a user account.
*/
protected function entitySave($account) {
if ($this->config['defuse_mail']) {
$account->mail = $account->mail . '_test';
}
// Remove pass from $account if the password is unchanged.
if (isset($account->feeds_original_pass) && $account->pass == $account->feeds_original_pass) {
unset($account->pass);
}
$account
->save();
if ($account->uid && !empty($account->openid)) {
$authmap = array(
'uid' => $account->uid,
'module' => 'openid',
'authname' => $account->openid,
);
if (SAVED_UPDATED != drupal_write_record('authmap', $authmap, array(
'uid',
'module',
))) {
drupal_write_record('authmap', $authmap);
}
}
}
/**
* Delete multiple user accounts.
*/
protected function entityDeleteMultiple($uids) {
user_delete_multiple($uids);
}
/**
* Override parent::configDefaults().
*/
public function configDefaults() {
return array(
'roles' => array(),
'status' => 1,
'defuse_mail' => FALSE,
) + parent::configDefaults();
}
/**
* Override parent::configForm().
*/
public function configForm(&$form_state) {
$form = parent::configForm($form_state);
$form['status'] = array(
'#type' => 'radios',
'#title' => t('Status'),
'#description' => t('Select whether users should be imported active or blocked.'),
'#options' => array(
0 => t('Blocked'),
1 => t('Active'),
),
'#default_value' => $this->config['status'],
);
$roles = user_roles(TRUE);
unset($roles['authenticated']);
$options = array();
foreach ($roles as $role) {
$options[$role->id] = $role
->label();
}
if ($options) {
$form['roles'] = array(
'#type' => 'checkboxes',
'#title' => t('Additional roles'),
'#description' => t('Every user is assigned the "authenticated user" role. Select additional roles here.'),
'#default_value' => $this->config['roles'],
'#options' => $options,
);
}
$form['defuse_mail'] = array(
'#type' => 'checkbox',
'#title' => t('Defuse e-mail addresses'),
'#description' => t('This appends _test to all imported e-mail addresses to ensure they cannot be used as recipients.'),
'#default_value' => $this->config['defuse_mail'],
);
return $form;
}
/**
* Override setTargetElement to operate on a target item that is a node.
*/
public function setTargetElement(FeedsSource $source, $target_user, $target_element, $value) {
switch ($target_element) {
case 'created':
$target_user->created = feeds_to_unixtime($value, REQUEST_TIME);
break;
case 'language':
$target_user->language = strtolower($value);
break;
default:
parent::setTargetElement($source, $target_user, $target_element, $value);
break;
}
}
/**
* Return available mapping targets.
*/
public function getMappingTargets() {
$targets = parent::getMappingTargets();
$targets += array(
'name' => array(
'name' => t('User name'),
'description' => t('Name of the user.'),
'optional_unique' => TRUE,
),
'mail' => array(
'name' => t('Email address'),
'description' => t('Email address of the user.'),
'optional_unique' => TRUE,
),
'created' => array(
'name' => t('Created date'),
'description' => t('The created (e. g. joined) data of the user.'),
),
'pass' => array(
'name' => t('Unencrypted Password'),
'description' => t('The unencrypted user password.'),
),
'status' => array(
'name' => t('Account status'),
'description' => t('Whether a user is active or not. 1 stands for active, 0 for blocked.'),
),
'language' => array(
'name' => t('User language'),
'description' => t('Default language for the user.'),
),
);
if (module_exists('openid')) {
$targets['openid'] = array(
'name' => t('OpenID identifier'),
'description' => t('The OpenID identifier of the user. <strong>CAUTION:</strong> Use only for migration purposes, misconfiguration of the OpenID identifier can lead to severe security breaches like users gaining access to accounts other than their own.'),
'optional_unique' => TRUE,
);
}
// Let other modules expose mapping targets.
self::loadMappers();
$entity_type = $this
->entityType();
$bundle = $this
->bundle();
drupal_alter('feeds_processor_targets', $targets, $entity_type, $bundle);
return $targets;
}
/**
* Get id of an existing feed item term if available.
*/
protected function existingEntityId(FeedsSource $source, FeedsParserResult $result) {
if ($uid = parent::existingEntityId($source, $result)) {
return $uid;
}
// Iterate through all unique targets and try to find a user for the
// target's value.
foreach ($this
->uniqueTargets($source, $result) as $target => $value) {
switch ($target) {
case 'name':
$uid = db_query("SELECT uid FROM {users} WHERE name = :name", array(
':name' => $value,
))
->fetchField();
break;
case 'mail':
$uid = db_query("SELECT uid FROM {users} WHERE mail = :mail", array(
':mail' => $value,
))
->fetchField();
break;
case 'openid':
$uid = db_query("SELECT uid FROM {authmap} WHERE authname = :authname AND module = 'openid'", array(
':authname' => $value,
))
->fetchField();
break;
}
if ($uid) {
// Return with the first nid found.
return $uid;
}
}
return 0;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | CTools export enabled status of this object. | |
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
public static | property | ||
FeedsConfigurable:: |
public | function | Similar to setConfig but adds to existing configuration. | |
FeedsConfigurable:: |
public | function | Submission handler for configForm(). | 2 |
FeedsConfigurable:: |
public | function | Validation handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Copy a configuration. | 1 |
FeedsConfigurable:: |
public | function | Determine whether this object is persistent and enabled. I. e. it is defined either in code or in the database and it is enabled. | 1 |
FeedsConfigurable:: |
public | function | Implements getConfig(). | 1 |
FeedsConfigurable:: |
public static | function | Instantiate a FeedsConfigurable object. | 1 |
FeedsConfigurable:: |
public | function | Set configuration. | |
FeedsConfigurable:: |
public | function | Override magic method __get(). Make sure that $this->config goes through getConfig(). | |
FeedsConfigurable:: |
public | function | Override magic method __isset(). This is needed due to overriding __get(). | |
FeedsPlugin:: |
public static | function | Get all available plugins. | |
FeedsPlugin:: |
public static | function | Gets all available plugins of a particular type. | |
FeedsPlugin:: |
public static | function | Determines whether given plugin is derived from given base plugin. | |
FeedsPlugin:: |
public | function |
Returns TRUE if $this->sourceForm() returns a form. Overrides FeedsSourceInterface:: |
|
FeedsPlugin:: |
public static | function | Loads on-behalf implementations from mappers/ directory. | |
FeedsPlugin:: |
public | function |
Save changes to the configuration of this object.
Delegate saving to parent (= Feed) which will collect
information from this object by way of getConfig() and store it. Overrides FeedsConfigurable:: |
|
FeedsPlugin:: |
public | function |
Implements FeedsSourceInterface::sourceDefaults(). Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
public | function |
A source is being deleted. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public | function |
Callback methods, exposes source form. Overrides FeedsSourceInterface:: |
3 |
FeedsPlugin:: |
public | function |
Validation handler for sourceForm. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public | function |
A source is being saved. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public static | function | Determines the type of a plugin. | |
FeedsPlugin:: |
protected | function |
Constructor. Overrides FeedsConfigurable:: |
|
FeedsProcessor:: |
public | function | Bundle type this processor operates on. | |
FeedsProcessor:: |
public | function | Provides a list of bundle options for use in select lists. | |
FeedsProcessor:: |
public | function | Remove all stored results or stored results up to a certain time for a source. | |
FeedsProcessor:: |
protected | function | Creates a log message for when an exception occured during import. | |
FeedsProcessor:: |
protected | function | Access check for saving an enity. | 1 |
FeedsProcessor:: |
public | function | Deletes feed items older than REQUEST_TIME - $time. | |
FeedsProcessor:: |
protected | function | Returns a database query used to select entities to expire. | 1 |
FeedsProcessor:: |
public | function | Per default, don't support expiry. If processor supports expiry of imported items, return the time after which items should be removed. | 1 |
FeedsProcessor:: |
protected | function | Retrieves the MD5 hash of $entity_id from the database. | |
FeedsProcessor:: |
public | function | ||
FeedsProcessor:: |
public | function | Get mappings. | |
FeedsProcessor:: |
protected | function | Create MD5 hash of item and mappings array. | |
FeedsProcessor:: |
public | function | Counts the number of items imported by this processor. | |
FeedsProcessor:: |
protected | function | Loads existing entity information and places it on $entity->feeds_item. | |
FeedsProcessor:: |
protected | function | Execute mapping on an item. | |
FeedsProcessor:: |
protected | function | Adds Feeds specific information on $entity->feeds_item. | |
FeedsProcessor:: |
public | function |
Implements FeedsPlugin::pluginType(). Overrides FeedsPlugin:: |
|
FeedsProcessor:: |
public | function | Process the result of the parsing stage. | |
FeedsProcessor:: |
protected | function | Utility function that iterates over a target array and retrieves all sources that are unique. | |
FeedsUserProcessor:: |
public | function |
Override parent::configDefaults(). Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
public | function |
Override parent::configForm(). Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
protected | function |
Delete multiple user accounts. Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
protected | function |
Implements parent::entityInfo(). Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
protected | function |
Loads an existing user. Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
protected | function |
Save a user account. Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
public | function |
Define entity type. Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
protected | function |
Validates a user account. Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
protected | function |
Get id of an existing feed item term if available. Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
public | function |
Return available mapping targets. Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
protected | function |
Creates a new user account in memory and returns it. Overrides FeedsProcessor:: |
|
FeedsUserProcessor:: |
public | function |
Override setTargetElement to operate on a target item that is a node. Overrides FeedsProcessor:: |