Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #89 from piyuesh23/category_alias
Browse files Browse the repository at this point in the history
Fixing alias generation for category translations.
  • Loading branch information
miromichalicka authored Oct 4, 2018
2 parents 7118f2b + e482602 commit b00cfba
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions modules/sku/acm_sku.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ services:
- '@acm.api'
- '@logger.factory'
- '@acm.i18n_helper'
- '@module_handler'

acm_sku.product_options_manager:
class: Drupal\acm_sku\ProductOptionsManager
Expand Down
21 changes: 20 additions & 1 deletion modules/sku/src/CategoryManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Logger\LoggerChannelFactory;
use Drupal\acm\Connector\ClientFactory;
use Drupal\Core\Extension\ModuleHandlerInterface;

/**
* Provides a service for category data to taxonomy synchronization.
Expand Down Expand Up @@ -64,6 +65,13 @@ class CategoryManager implements CategoryManagerInterface {
*/
private $logger;

/**
* Module Handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
private $modulehandler;

/**
* Constructor.
*
Expand All @@ -77,16 +85,19 @@ class CategoryManager implements CategoryManagerInterface {
* LoggerFactory object.
* @param \Drupal\acm\I18nHelper $i18nHelper
* Instance of I18nHelper service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* Module handler service.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ClientFactory $client_factory, APIWrapper $api_wrapper, LoggerChannelFactory $logger_factory, I18nHelper $i18nHelper) {
public function __construct(EntityTypeManagerInterface $entity_type_manager, ClientFactory $client_factory, APIWrapper $api_wrapper, LoggerChannelFactory $logger_factory, I18nHelper $i18nHelper, ModuleHandlerInterface $moduleHandler) {
$this->termStorage = $entity_type_manager->getStorage('taxonomy_term');
$this->vocabStorage = $entity_type_manager->getStorage('taxonomy_vocabulary');
$this->clientFactory = $client_factory;
$this->apiWrapper = $api_wrapper;
$this->logger = $logger_factory->get('acm_sku');
$this->i18nHelper = $i18nHelper;
$this->modulehandler = $moduleHandler;
}

/**
Expand Down Expand Up @@ -362,6 +373,14 @@ private function syncCategory(array $categories, $parent = NULL, $storeId = '')
'langcode' => $langcode,
]);

// We doing this because when the translation of node is created by
// addTranslation(), pathauto alias is not created for the translated
// version.
// @see https://www.drupal.org/project/pathauto/issues/2995829.
if ($this->modulehandler->moduleExists('pathauto')) {
$term->path->pathauto = 1;
}

$this->results['created']++;
}

Expand Down

0 comments on commit b00cfba

Please sign in to comment.