You are here

function persian_date_entity_type_alter in Persian Date for Drupal 8 8.4

File

./persian_date.module, line 192
Contains persian_date.module.

Code

function persian_date_entity_type_alter(array &$entity_types) {
  if (!\Drupal::moduleHandler()
    ->moduleExists('content_translation')) {
    return;
  }

  // Provide defaults for translation info.

  /** @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
  foreach ($entity_types as $entity_type) {
    if ($entity_type
      ->isTranslatable()) {
      if (!$entity_type
        ->hasHandlerClass('translation')) {
        $entity_type
          ->setHandlerClass('translation', \Drupal\persian_date\TranslationHandler\ContentTranslationHandler::class);
      }
      else {

        // if has translation handler replace it with correct equivalent
        $handlerClass = $entity_type
          ->getHandlerClass('translation');
        switch ($handlerClass) {
          case \Drupal\block_content\BlockContentTranslationHandler::class:
            $entity_type
              ->setHandlerClass('translation', \Drupal\persian_date\TranslationHandler\BlockContentTranslationHandler::class);
            break;
          case \Drupal\comment\CommentTranslationHandler::class:
            $entity_type
              ->setHandlerClass('translation', \Drupal\persian_date\TranslationHandler\CommentTranslationHandler::class);
            break;
          case \Drupal\content_translation\ContentTranslationHandler::class:
            $entity_type
              ->setHandlerClass('translation', \Drupal\persian_date\TranslationHandler\ContentTranslationHandler::class);
            break;
          case \Drupal\node\NodeTranslationHandler::class:
            $entity_type
              ->setHandlerClass('translation', \Drupal\persian_date\TranslationHandler\NodeTranslationHandler::class);
            break;
          case \Drupal\user\ProfileTranslationHandler::class:
            $entity_type
              ->setHandlerClass('translation', \Drupal\persian_date\TranslationHandler\ProfileTranslationHandler::class);
            break;
          case \Drupal\taxonomy\TermTranslationHandler::class:
            $entity_type
              ->setHandlerClass('translation', \Drupal\persian_date\TranslationHandler\TermTranslationHandler::class);
            break;
        }
      }
    }
  }
}