summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKirill Roskolii2018-08-30 23:17:56 (GMT)
committerKirill Roskolii2018-08-30 23:17:56 (GMT)
commit87c14bf3196270f70aaec0c0ceb83311a32a262d (patch)
tree0b3c8cfa055b1a9a44a147874820a291ec481eb5
parent3fcdf5de735fecf13dced9d1cecd3769c76146fa (diff)
Fixed code style violations.
-rw-r--r--modules/crm_core_user_sync/crm_core_user_sync.services.yml6
-rw-r--r--modules/crm_core_user_sync/src/CrmCoreUserSyncRelation.php18
-rw-r--r--modules/crm_core_user_sync/src/CrmCoreUserSyncRelationRules.php1
-rw-r--r--modules/crm_core_user_sync/src/EventSubscriber/RequestSubscriber.php1
-rw-r--r--modules/crm_core_user_sync/src/Form/RuleForm.php35
-rw-r--r--modules/crm_core_user_sync/src/Form/SettingsForm.php8
-rw-r--r--modules/crm_core_user_sync/src/Plugin/Block/EditOwnContactInformationBlock.php18
-rw-r--r--modules/crm_core_user_sync/src/UserSyncBatch.php2
8 files changed, 54 insertions, 35 deletions
diff --git a/modules/crm_core_user_sync/crm_core_user_sync.services.yml b/modules/crm_core_user_sync/crm_core_user_sync.services.yml
index 4b54f16..81f4ba0 100644
--- a/modules/crm_core_user_sync/crm_core_user_sync.services.yml
+++ b/modules/crm_core_user_sync/crm_core_user_sync.services.yml
@@ -1,7 +1,7 @@
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']
diff --git a/modules/crm_core_user_sync/src/CrmCoreUserSyncRelation.php b/modules/crm_core_user_sync/src/CrmCoreUserSyncRelation.php
index 820ff3c..695c931 100644
--- a/modules/crm_core_user_sync/src/CrmCoreUserSyncRelation.php
+++ b/modules/crm_core_user_sync/src/CrmCoreUserSyncRelation.php
@@ -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;
@@ -30,16 +31,26 @@ class CrmCoreUserSyncRelation implements CrmCoreUserSyncRelationInterface {
protected $rules;
/**
+ * Logger channel.
+ *
+ * @var \Drupal\Core\Logger\LoggerChannelInterface
+ */
+ protected $logger;
+
+ /**
* Constructs a CrmCoreUserSyncRelation object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* 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(),
]);
diff --git a/modules/crm_core_user_sync/src/CrmCoreUserSyncRelationRules.php b/modules/crm_core_user_sync/src/CrmCoreUserSyncRelationRules.php
index 729cb67..a0ce934 100644
--- a/modules/crm_core_user_sync/src/CrmCoreUserSyncRelationRules.php
+++ b/modules/crm_core_user_sync/src/CrmCoreUserSyncRelationRules.php
@@ -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;
diff --git a/modules/crm_core_user_sync/src/EventSubscriber/RequestSubscriber.php b/modules/crm_core_user_sync/src/EventSubscriber/RequestSubscriber.php
index 7660234..5f9758a 100644
--- a/modules/crm_core_user_sync/src/EventSubscriber/RequestSubscriber.php
+++ b/modules/crm_core_user_sync/src/EventSubscriber/RequestSubscriber.php
@@ -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;
diff --git a/modules/crm_core_user_sync/src/Form/RuleForm.php b/modules/crm_core_user_sync/src/Form/RuleForm.php
index 317f298..0d96063 100644
--- a/modules/crm_core_user_sync/src/Form/RuleForm.php
+++ b/modules/crm_core_user_sync/src/Form/RuleForm.php
@@ -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);
}
diff --git a/modules/crm_core_user_sync/src/Form/SettingsForm.php b/modules/crm_core_user_sync/src/Form/SettingsForm.php
index 2c86c0c..c889ce1 100644
--- a/modules/crm_core_user_sync/src/Form/SettingsForm.php
+++ b/modules/crm_core_user_sync/src/Form/SettingsForm.php
@@ -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);
}
diff --git a/modules/crm_core_user_sync/src/Plugin/Block/EditOwnContactInformationBlock.php b/modules/crm_core_user_sync/src/Plugin/Block/EditOwnContactInformationBlock.php
index 9f9af11..66cc62e 100644
--- a/modules/crm_core_user_sync/src/Plugin/Block/EditOwnContactInformationBlock.php
+++ b/modules/crm_core_user_sync/src/Plugin/Block/EditOwnContactInformationBlock.php
@@ -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;
@@ -46,6 +47,13 @@ class EditOwnContactInformationBlock extends BlockBase implements ContainerFacto
protected $formBuilder;
/**
+ * Current user.
+ *
+ * @var \Drupal\Core\Session\AccountProxyInterface
+ */
+ protected $accountProxy;
+
+ /**
* Constructs a new EditOwnContactInformationBlock instance.
*
* @param array $configuration
@@ -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);
diff --git a/modules/crm_core_user_sync/src/UserSyncBatch.php b/modules/crm_core_user_sync/src/UserSyncBatch.php
index 007dc8b..7c8b4ee 100644
--- a/modules/crm_core_user_sync/src/UserSyncBatch.php
+++ b/modules/crm_core_user_sync/src/UserSyncBatch.php
@@ -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();