You are here

public function CommerceSmartImporerService::createUrl in Commerce Smart Importer 8

Creates url value based on field settings.

1 call to CommerceSmartImporerService::createUrl()
CommerceSmartImporerService::formatField in src/Plugin/CommerceSmartImporerService.php
Formats one field value based on field settings.

File

src/Plugin/CommerceSmartImporerService.php, line 737
Main Commerce Smart Importer Service.

Class

CommerceSmartImporerService
This is main Commerce Smart Importer Service.

Namespace

Drupal\commerce_smart_importer\Plugin

Code

public function createUrl($url, $field_settings, $name = 'link') {
  if (filter_var(trim($url), FILTER_VALIDATE_URL)) {
    if ($field_settings['title'] == 1) {
      return [
        "uri" => trim($url),
        "title" => $name,
        "options" => [
          "target" => "_blank",
        ],
      ];
    }
    else {
      return [
        "uri" => trim($url),
        "options" => [
          "target" => "_blank",
        ],
      ];
    }
  }
  else {
    throw new Exception("Url is not valid");
  }
}