You are here

public function WebformOptionsCustom::getUrl in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_options_custom/src/Entity/WebformOptionsCustom.php \Drupal\webform_options_custom\Entity\WebformOptionsCustom::getUrl()

Set a custom options element template URL.

Return value

string A custom options element template URL.

Overrides WebformOptionsCustomInterface::getUrl

1 call to WebformOptionsCustom::getUrl()
WebformOptionsCustom::getTemplate in modules/webform_options_custom/src/Entity/WebformOptionsCustom.php
Set a custom options element HTML/SVG template.

File

modules/webform_options_custom/src/Entity/WebformOptionsCustom.php, line 281

Class

WebformOptionsCustom
Defines the webform options custom entity.

Namespace

Drupal\webform_options_custom\Entity

Code

public function getUrl() {
  global $base_url;
  $url = $this->url;
  if (empty($url)) {
    return NULL;
  }
  if (strpos($url, '/') === 0) {

    // Map root-relative path.
    $url = $base_url . preg_replace('/^' . preg_quote(base_path(), '/') . '/', '/', $url);
  }
  elseif (strpos($url, 'http') !== 0) {

    // Map webform_option_custom/images path.
    $path = drupal_get_path('module', 'webform_options_custom') . '/images/' . $url;
    if (file_exists($path)) {
      $url = $base_url . '/' . $path;
    }
  }
  if (strpos($url, 'http') === 0) {
    return $url;
  }
  return NULL;
}