diff --git a/modules/entity_share_async/src/Controller/EntryPoint.php b/modules/entity_share_async/src/Controller/EntryPoint.php index c3765b8..124c5b4 100644 --- a/modules/entity_share_async/src/Controller/EntryPoint.php +++ b/modules/entity_share_async/src/Controller/EntryPoint.php @@ -53,13 +53,14 @@ class EntryPoint extends ControllerBase { } $data_keys = [ + 'remote_config_id', 'remote_id', 'channel_id', 'uuid', ]; foreach ($data_keys as $data_key) { if (!isset($request_body[$data_key]) || empty($request_body[$data_key]) || !is_string($request_body[$data_key])) { - throw new AccessDeniedHttpException($this->t('The request body is not correct. Expected body is like {"remote_id":"example","channel_id":"example","uuid":"example"}.')); + throw new AccessDeniedHttpException($this->t('The request body is not correct. Expected body is like {"remote_config_id":"example","remote_id":"example","channel_id":"example","uuid":"example"}.')); } } @@ -83,6 +84,7 @@ class EntryPoint extends ControllerBase { $this->queueHelper->enqueue( $request_body['remote_id'], $request_body['channel_id'], + $request_body['remote_config_id'], [$request_body['uuid']] ); diff --git a/modules/entity_share_notifier/config/schema/entity_share_subscriber.schema.yml b/modules/entity_share_notifier/config/schema/entity_share_subscriber.schema.yml index 1baad7d..23f43fd 100644 --- a/modules/entity_share_notifier/config/schema/entity_share_subscriber.schema.yml +++ b/modules/entity_share_notifier/config/schema/entity_share_subscriber.schema.yml @@ -20,6 +20,9 @@ entity_share_notifier.entity_share_subscriber.*: remote_id: type: string label: 'Remote ID' + remote_config_id: + type: string + label: 'Remote Config import ID' channel_ids: type: sequence label: 'Channel IDs' diff --git a/modules/entity_share_notifier/src/Entity/EntityShareSubscriber.php b/modules/entity_share_notifier/src/Entity/EntityShareSubscriber.php index f5124f8..91a58aa 100644 --- a/modules/entity_share_notifier/src/Entity/EntityShareSubscriber.php +++ b/modules/entity_share_notifier/src/Entity/EntityShareSubscriber.php @@ -39,6 +39,7 @@ use Drupal\Core\Entity\EntityStorageInterface; * "basic_auth_username", * "basic_auth_password", * "remote_id", + * "remote_config_id", * "channel_ids", * }, * links = { @@ -94,6 +95,13 @@ class EntityShareSubscriber extends ConfigEntityBase implements EntityShareSubsc */ protected $remote_id; + /** + * The remote config ID used on the subscriber website to pull this server. + * + * @var string + */ + protected $remote_config_id; + /** * The list of channel IDs this subscriber will be notified on. * diff --git a/modules/entity_share_notifier/src/Form/EntityShareSubscriberForm.php b/modules/entity_share_notifier/src/Form/EntityShareSubscriberForm.php index ba27666..baa7499 100644 --- a/modules/entity_share_notifier/src/Form/EntityShareSubscriberForm.php +++ b/modules/entity_share_notifier/src/Form/EntityShareSubscriberForm.php @@ -65,6 +65,14 @@ class EntityShareSubscriberForm extends EntityForm { '#required' => TRUE, ]; + $form['remote_config_id'] = [ + '#type' => 'textfield', + '#title' => $this->t('Remote Config ID'), + '#default_value' => $entity_share_subscriber->get('remote_config_id'), + '#description' => $this->t('The remote config ID used on the subscriber website to pull this server.'), + '#required' => TRUE, + ]; + $form['remote_id'] = [ '#type' => 'textfield', '#title' => $this->t('Remote ID'), diff --git a/modules/entity_share_notifier/src/HookHandler/EntityHookHandler.php b/modules/entity_share_notifier/src/HookHandler/EntityHookHandler.php index 76a166c..93a69c0 100644 --- a/modules/entity_share_notifier/src/HookHandler/EntityHookHandler.php +++ b/modules/entity_share_notifier/src/HookHandler/EntityHookHandler.php @@ -6,6 +6,7 @@ namespace Drupal\entity_share_notifier\HookHandler; use Drupal\Core\DependencyInjection\ContainerInjectionInterface; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Entity\EntityTypeBundleInfoInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Http\ClientFactory; use Drupal\Core\Language\LanguageInterface; @@ -58,6 +59,13 @@ class EntityHookHandler implements ContainerInjectionInterface { */ protected $logger; + /** + * The bundle infos from the website. + * + * @var array + */ + protected $bundleInfos; + /** * EntityHookHandler constructor. * @@ -71,19 +79,23 @@ class EntityHookHandler implements ContainerInjectionInterface { * The client factory. * @param \Psr\Log\LoggerInterface $logger * The logger service. + * @param \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_type_bundle_info + * The entity type bundle info service. */ public function __construct( EntityTypeManagerInterface $entity_type_manager, LanguageManagerInterface $language_manager, ChannelManipulatorInterface $channel_manipulator, ClientFactory $client_factory, - LoggerInterface $logger + LoggerInterface $logger, + EntityTypeBundleInfoInterface $entity_type_bundle_info ) { $this->entityTypeManager = $entity_type_manager; $this->languageManager = $language_manager; $this->channelManipulator = $channel_manipulator; $this->clientFactory = $client_factory; $this->logger = $logger; + $this->bundleInfos = $entity_type_bundle_info->getAllBundleInfo(); } /** @@ -95,7 +107,8 @@ class EntityHookHandler implements ContainerInjectionInterface { $container->get('language_manager'), $container->get('entity_share_server.channel_manipulator'), $container->get('http_client_factory'), - $container->get('logger.channel.entity_share_notifier') + $container->get('logger.channel.entity_share_notifier'), + $container->get('entity_type.bundle.info') ); } @@ -133,10 +146,12 @@ class EntityHookHandler implements ContainerInjectionInterface { continue; } - // Check langcode. - $channel_langcode = $channel->get('channel_langcode'); - if ($channel_langcode != $entity_langcode) { - continue; + // Check langcode, if applicable. + if (isset($this->bundleInfos[$channel_entity_type][$channel_bundle]['translatable']) && $this->bundleInfos[$channel_entity_type][$channel_bundle]['translatable']) { + $channel_langcode = $channel->get('channel_langcode'); + if ($channel_langcode != $entity_langcode) { + continue; + } } // TODO. Will require to add a new field on channel to store the user to @@ -174,6 +189,7 @@ class EntityHookHandler implements ContainerInjectionInterface { } $remote_id = $subscriber->get('remote_id'); + $remote_config_id = $subscriber->get('remote_config_id'); $http_client = $this->clientFactory->fromOptions([ 'base_uri' => $subscriber->get('subscriber_url') . '/', 'auth' => [ @@ -189,6 +205,7 @@ class EntityHookHandler implements ContainerInjectionInterface { try { $http_client->request('POST', 'entity_share/async', [ 'json' => [ + 'remote_config_id' => $remote_config_id, 'remote_id' => $remote_id, 'channel_id' => $channel_id, 'uuid' => $entity_uuid,