You are here

function paragraphs_browser_image_path_validate in Paragraphs Browser 8

Utility confirms path is relative to Drupal root, and prepends URI if applicable.

Parameters

$path:

Return value

bool|string

1 call to paragraphs_browser_image_path_validate()
paragraphs_browser_paragraph_type_form_builder in ./paragraphs_browser.module
Entity builder for the menu configuration entity.

File

./paragraphs_browser.module, line 157
Contains paragraphs_browser.module..

Code

function paragraphs_browser_image_path_validate($path) {

  // Absolute local file paths are invalid.
  if (\Drupal::service('file_system')
    ->realpath($path) == $path) {
    return FALSE;
  }

  // A path relative to the Drupal root or a fully qualified URI is valid.
  if (is_file($path)) {
    return $path;
  }

  // Prepend 'public://' for relative file paths within public filesystem.
  if (\Drupal::service('file_system')
    ->uriScheme($path) === FALSE) {
    $path = 'public://' . $path;
  }
  if (is_file($path)) {
    return $path;
  }
  return FALSE;
}