Commit 87c14bf3 authored by RoSk0's avatar RoSk0

Fixed code style violations.

parent 3fcdf5de
services:
crm_core_user_sync.relation:
class: Drupal\crm_core_user_sync\CrmCoreUserSyncRelation
arguments: ['@entity_type.manager', '@crm_core_user_sync.relation_rules']
arguments: ['@entity_type.manager', '@crm_core_user_sync.relation_rules', '@logger.channel.crm_core_user_sync']
crm_core_user_sync.relation_rules:
class: Drupal\crm_core_user_sync\CrmCoreUserSyncRelationRules
......@@ -12,3 +12,7 @@ services:
arguments: ['@current_user', '@config.factory', '@crm_core_user_sync.relation', '@entity_type.manager']
tags:
- { name: event_subscriber }
logger.channel.crm_core_user_sync:
parent: logger.channel_base
arguments: ['crm_core_user_sync']
......@@ -3,6 +3,7 @@
namespace Drupal\crm_core_user_sync;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelInterface;
use Drupal\crm_core_contact\Entity\Individual;
use Drupal\crm_core_contact\IndividualInterface;
use Drupal\crm_core_user_sync\Entity\Relation;
......@@ -29,6 +30,13 @@ class CrmCoreUserSyncRelation implements CrmCoreUserSyncRelationInterface {
*/
protected $rules;
/**
* Logger channel.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
/**
* Constructs a CrmCoreUserSyncRelation object.
*
......@@ -36,10 +44,13 @@ class CrmCoreUserSyncRelation implements CrmCoreUserSyncRelationInterface {
* The entity type manager.
* @param \Drupal\crm_core_user_sync\CrmCoreUserSyncRelationRules $rules
* Relation rules service.
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
* Logger channel.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, CrmCoreUserSyncRelationRules $rules) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, CrmCoreUserSyncRelationRules $rules, LoggerChannelInterface $logger) {
$this->storage = $entity_type_manager->getStorage('crm_core_user_sync_relation');
$this->rules = $rules;
$this->logger = $logger;
}
/**
......@@ -140,7 +151,7 @@ class CrmCoreUserSyncRelation implements CrmCoreUserSyncRelationInterface {
}
// Create the contact.
$contact = Individual::create(array('type' => $contact_type));
$contact = Individual::create(['type' => $contact_type]);
$contact->setOwner($account);
// For now we just add the name.
$contact->name->given = $account->getAccountName();
......@@ -164,8 +175,9 @@ class CrmCoreUserSyncRelation implements CrmCoreUserSyncRelationInterface {
$relation->setIndividual($contact);
$relation->save();
\Drupal::logger('crm_core_user_sync')->notice('User @user has been synchronized to the contact @contact_id, relation @rid has been created.', [
$this->logger->notice('User @user @uid has been synchronized to the contact @contact_id, relation @rid has been created.', [
'@user' => $account->getDisplayName(),
'@uid' => $account->id(),
'@contact_id' => $contact->id(),
'@rid' => $relation->id(),
]);
......
......@@ -3,7 +3,6 @@
namespace Drupal\crm_core_user_sync;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\crm_core_contact\IndividualInterface;
use Drupal\user\UserInterface;
......
......@@ -5,7 +5,6 @@ namespace Drupal\crm_core_user_sync\EventSubscriber;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\crm_core_contact\Entity\Individual;
use Drupal\crm_core_user_sync\CrmCoreUserSyncRelationInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
......
......@@ -32,13 +32,6 @@ class RuleForm extends ConfigFormBase {
$config = $this->config('crm_core_user_sync.settings');
$rules = $config->get('rules');
$rule = [
'role' => '',
'contact_type' => '',
'enabled' => TRUE,
'weight' => 0,
];
if ($rule_key === 'new') {
$rule = [
'role' => '',
......@@ -65,7 +58,7 @@ class RuleForm extends ConfigFormBase {
}
}
$types_options = ['' => t('- Select -')];
$types_options = ['' => $this->t('- Select -')];
foreach (IndividualType::loadMultiple() as $type) {
$types_options[$type->id()] = $type->label();
}
......@@ -75,34 +68,34 @@ class RuleForm extends ConfigFormBase {
$role_options[$role->id()] = $role->label();
}
$form['role'] = array(
$form['role'] = [
'#type' => 'select',
'#title' => t('User Role'),
'#title' => $this->t('User Role'),
'#options' => $role_options,
'#default_value' => isset($rule['role']) ? $rule['role'] : '',
'#required' => TRUE,
);
];
$form['contact_type'] = array(
$form['contact_type'] = [
'#type' => 'select',
'#title' => t('Contact Type'),
'#title' => $this->t('Contact Type'),
'#options' => $types_options,
'#default_value' => isset($rule['contact_type']) ? $rule['contact_type'] : '',
'#required' => TRUE,
);
];
$form['weight'] = array(
$form['weight'] = [
'#type' => 'weight',
'#title' => t('Weight'),
'#title' => $this->t('Weight'),
'#default_value' => isset($rule['weight']) ? $rule['weight'] : 0,
);
];
$form['enabled'] = array(
$form['enabled'] = [
'#type' => 'checkbox',
'#title' => t('Enabled'),
'#title' => $this->t('Enabled'),
'#default_value' => isset($rule['enabled']) ? $rule['enabled'] : TRUE,
'#description' => t('When checked, this rule will be used to synchronize user accounts. When unchecked, it will be ignored throughout the system.'),
);
'#description' => $this->t('When checked, this rule will be used to synchronize user accounts. When unchecked, it will be ignored throughout the system.'),
];
return parent::buildForm($form, $form_state);
}
......
......@@ -150,12 +150,12 @@ class SettingsForm extends ConfigFormBase {
* Sets batch for bulk user synchronization.
*/
public function bulkUserSync(array $form, FormStateInterface $form_state) {
$operations[] = array([UserSyncBatch::class, 'progress'], array());
$batch = array(
$operations[] = [[UserSyncBatch::class, 'progress'], []];
$batch = [
'operations' => $operations,
'title' => t('Processing user synchronization'),
'title' => $this->t('Processing user synchronization'),
'finished' => [UserSyncBatch::class, 'finished'],
);
];
batch_set($batch);
}
......
......@@ -9,6 +9,7 @@ use Drupal\Core\Form\FormState;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Block\BlockBase;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\crm_core_contact\Entity\Individual;
use Drupal\crm_core_user_sync\CrmCoreUserSyncRelationInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -45,6 +46,13 @@ class EditOwnContactInformationBlock extends BlockBase implements ContainerFacto
*/
protected $formBuilder;
/**
* Current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $accountProxy;
/**
* Constructs a new EditOwnContactInformationBlock instance.
*
......@@ -63,12 +71,15 @@ class EditOwnContactInformationBlock extends BlockBase implements ContainerFacto
* Entity type manager.
* @param \Drupal\Core\Form\FormBuilderInterface $formBuilder
* Form builder.
* @param \Drupal\Core\Session\AccountProxyInterface $accountProxy
* Current user.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, CrmCoreUserSyncRelationInterface $relation, EntityTypeManagerInterface $entityTypeManager, FormBuilderInterface $formBuilder) {
public function __construct(array $configuration, $plugin_id, $plugin_definition, CrmCoreUserSyncRelationInterface $relation, EntityTypeManagerInterface $entityTypeManager, FormBuilderInterface $formBuilder, AccountProxyInterface $accountProxy) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->relation = $relation;
$this->entityTypeManager = $entityTypeManager;
$this->formBuilder = $formBuilder;
$this->accountProxy = $accountProxy;
}
/**
......@@ -81,7 +92,8 @@ class EditOwnContactInformationBlock extends BlockBase implements ContainerFacto
$plugin_definition,
$container->get('crm_core_user_sync.relation'),
$container->get('entity_type.manager'),
$container->get('form_builder')
$container->get('form_builder'),
$container->get('current_user')
);
}
......@@ -97,7 +109,7 @@ class EditOwnContactInformationBlock extends BlockBase implements ContainerFacto
*/
public function build() {
if ($individualId = $this->relation->getUserIndividualId(\Drupal::currentUser()->id())) {
if ($individualId = $this->relation->getUserIndividualId($this->accountProxy->id())) {
/* @var $individual \Drupal\crm_core_contact\Entity\Individual */
/* @var $form \Drupal\crm_core_contact\Form\IndividualForm */
$individual = Individual::load($individualId);
......
......@@ -38,7 +38,7 @@ class UserSyncBatch {
$accounts = $userStorage->loadMultiple($uids);
foreach ($accounts as $account) {
if ($result = \Drupal::service('crm_core_user_sync.relation')->relate($account)) {
if (\Drupal::service('crm_core_user_sync.relation')->relate($account)) {
$context['results']['synced']++;
}
$context['sandbox']['last_uid'] = $account->id();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment