usebb2drupal-8.x-1.0-rc1/usebb2drupal.module

usebb2drupal.module
<?php

/**
 * @file
 * UseBB2Drupal module file.
 */

use Drupal\node\Entity\Node;
use Drupal\comment\Entity\Comment;
use Drupal\Core\Database\Query\AlterableInterface;

/**
 * Implements hook_ENTITY_TYPE_presave() for node entities.
 *
 * Set the changed timestamp to the imported one from UseBB.
 */
function usebb2drupal_node_presave(Node $node) {
  if ($node->bundle() === 'forum') {
    if (isset($node->usebb_changed)) {
      $node->changed = $node->usebb_changed;
    }
    if (isset($node->usebb_poster_id) && intval($node->usebb_poster_id) === 0) {
      $node->uid = $node->usebb_poster_id;
    }
  }
}

/**
 * Implements hook_ENTITY_TYPE_presave() for comment entities.
 *
 * Set the changed timestamp to the imported one from UseBB. Same for the
 * hostname.
 */
function usebb2drupal_comment_presave(Comment $comment) {
  if ($comment->bundle() === 'comment_forum') {
    if (isset($comment->usebb_changed)) {
      $comment->changed = $comment->usebb_changed;
    }
    if (isset($comment->usebb_hostname)) {
      $comment->hostname = $comment->usebb_hostname;
    }
  }
}

/**
 * Implements hook_query_TAG_alter().
 */
function usebb2drupal_query_usebb2drupal_url_translator_alter(AlterableInterface $query) {
  \Drupal::service('usebb2drupal.url_translator')->alterQuery($query);
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc