You are here

function record_shorten_shorten_create in Shorten URLs 8

Same name and namespace in other branches
  1. 8.2 modules/record_shorten/record_shorten.module \record_shorten_shorten_create()
  2. 6 record_shorten.module \record_shorten_shorten_create()
  3. 7.2 record_shorten.module \record_shorten_shorten_create()
  4. 7 record_shorten.module \record_shorten_shorten_create()

Implements hook_shorten_create().

File

modules/record_shorten/record_shorten.module, line 22
Records shortened URLs.

Code

function record_shorten_shorten_create($old, $new, $service) {
  $array = array(
    'original' => $old,
    'short' => $new,
    'service' => $service,
    'uid' => \Drupal::currentUser()
      ->id(),
    'hostname' => \Drupal::request()
      ->getClientIp(),
    'created' => REQUEST_TIME,
  );

  // @TODO : This creates duplicate records. Needs to be fixed.
  \Drupal::database()
    ->merge('record_shorten')
    ->key($array)
    ->fields($array)
    ->execute();
}