You are here

public function AddBannerForm::dynamic_banner_set_banner in Dynamic Banner 8

Set a banner for a given path, preventing duplicates. Note if dbid comes in null then we are creating a banner

1 call to AddBannerForm::dynamic_banner_set_banner()
AddBannerForm::submitForm in src/forms/AddBannerForm.php
Form submission handler.

File

src/forms/AddBannerForm.php, line 357

Class

AddBannerForm

Namespace

Drupal\dynamic_banner\forms

Code

public function dynamic_banner_set_banner($path, $imgurl, $imgfid, $text, $link, $mode, $time_on, $time_off, $dbid = NULL) {
  if (!$mode) {
    $mode = BANNER_DEFAULT_BANNER_MODE;
  }

  // First we check if we are dealing with an existing alias and delete or modify it based on dbid.
  // we dont need to do a complicated check here because the code already made it for us
  if ($dbid) {

    // Update the existing banner.
    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
    // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
    \Drupal::database()
      ->update('dynamic_banner')
      ->fields(array(
      'path' => $path,
      'imgurl' => $imgurl,
      'imgfid' => isset($imgfid[0]) ? $imgfid[0] : '',
      'text' => $text,
      'link' => $link,
      'mode' => $mode,
      'start_time' => $time_on,
      'end_time' => $time_off,
    ))
      ->condition('dbid', $dbid)
      ->execute();
  }
  else {

    // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
    // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
    \Drupal::database()
      ->insert('dynamic_banner')
      ->fields(array(
      'path' => $path,
      'imgurl' => $imgurl,
      'imgfid' => isset($imgfid[0]) ? $imgfid[0] : '',
      'text' => $text,
      'link' => $link,
      'mode' => $mode,
      'start_time' => $time_on,
      'end_time' => $time_off,
    ))
      ->execute();
  }
}