class CrmCoreUserSyncRelationRules in CRM Core 8.3
Same name and namespace in other branches
- 8 modules/crm_core_user_sync/src/CrmCoreUserSyncRelationRules.php \Drupal\crm_core_user_sync\CrmCoreUserSyncRelationRules
CrmCoreUserSyncRelation service.
Hierarchy
- class \Drupal\crm_core_user_sync\CrmCoreUserSyncRelationRules
Expanded class hierarchy of CrmCoreUserSyncRelationRules
1 file declares its use of CrmCoreUserSyncRelationRules
- CrmCoreUserSyncRelationRulesTest.php in modules/
crm_core_user_sync/ tests/ src/ Unit/ CrmCoreUserSyncRelationRulesTest.php
1 string reference to 'CrmCoreUserSyncRelationRules'
- crm_core_user_sync.services.yml in modules/
crm_core_user_sync/ crm_core_user_sync.services.yml - modules/crm_core_user_sync/crm_core_user_sync.services.yml
1 service uses CrmCoreUserSyncRelationRules
- crm_core_user_sync.relation_rules in modules/
crm_core_user_sync/ crm_core_user_sync.services.yml - Drupal\crm_core_user_sync\CrmCoreUserSyncRelationRules
File
- modules/
crm_core_user_sync/ src/ CrmCoreUserSyncRelationRules.php, line 12
Namespace
Drupal\crm_core_user_syncView source
class CrmCoreUserSyncRelationRules {
/**
* The configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Rules.
*
* @var array
*/
protected $rules;
/**
* Config name.
*
* @var string
*/
private $configName;
/**
* Constructs a CrmCoreUserSyncRelationRules object.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The configuration factory.
* @param string $configName
* Name of the configuration object that stores rules.
*/
public function __construct(ConfigFactoryInterface $config_factory, $configName) {
$this->configFactory = $config_factory;
$this->configName = $configName;
}
/**
* Retrieves the individual contact id for specified user.
*
* @return int|null
* Individual id, if relation exists.
*/
protected function getRules() {
if ($this->rules === NULL) {
$rules = $this->configFactory
->get($this->configName)
->get('rules');
uasort($rules, [
$this,
'weightCmp',
]);
$this->rules = $rules;
}
return $this->rules;
}
/**
* Rules weight comparison function.
*/
protected function weightCmp(array $a, array $b) {
if ($a['weight'] == $b['weight']) {
return 0;
}
return $a['weight'] < $b['weight'] ? -1 : 1;
}
/**
* Checks if provided contact can be linked to this account.
*
* @param \Drupal\user\UserInterface $account
* User account to check.
* @param \Drupal\crm_core_contact\IndividualInterface $contact
* Contact record to check.
*
* @return bool
* TRUE if the contact is valid.
*/
public function valid(UserInterface $account, IndividualInterface $contact) {
return $contact
->bundle() === $this
->getContactType($account);
}
/**
* Get contact type resolved from configured synchronization rules.
*
* @param \Drupal\user\UserInterface $account
* User account to check.
*
* @return string|false
* Intividual contact type (bundle) to be user for this user account.
*/
public function getContactType(UserInterface $account) {
foreach ($this
->getRules() as $rule) {
if ($rule['enabled'] && $account
->hasRole($rule['role'])) {
return $rule['contact_type'];
}
}
return FALSE;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CrmCoreUserSyncRelationRules:: |
protected | property | The configuration factory. | |
CrmCoreUserSyncRelationRules:: |
private | property | Config name. | |
CrmCoreUserSyncRelationRules:: |
protected | property | Rules. | |
CrmCoreUserSyncRelationRules:: |
public | function | Get contact type resolved from configured synchronization rules. | |
CrmCoreUserSyncRelationRules:: |
protected | function | Retrieves the individual contact id for specified user. | |
CrmCoreUserSyncRelationRules:: |
public | function | Checks if provided contact can be linked to this account. | |
CrmCoreUserSyncRelationRules:: |
protected | function | Rules weight comparison function. | |
CrmCoreUserSyncRelationRules:: |
public | function | Constructs a CrmCoreUserSyncRelationRules object. |