You are here

public function GridStack::getIconUri in GridStack 8

Same name and namespace in other branches
  1. 8.2 src/Entity/GridStack.php \Drupal\gridstack\Entity\GridStack::getIconUri()

Returns the icon URI.

1 call to GridStack::getIconUri()
GridStack::getIconUrl in src/Entity/GridStack.php
Returns the icon URL.

File

src/Entity/GridStack.php, line 348

Class

GridStack
Defines the GridStack configuration entity.

Namespace

Drupal\gridstack\Entity

Code

public function getIconUri() {
  $id = $this
    ->id();
  $uri = file_build_uri('gridstack/' . $id . '.png');

  // The icon was updated, and stored at public://gridstack/ directory.
  if (is_file($uri)) {
    return $uri;
  }

  // The icon may be empty, or not, yet not always exists at public directory.
  $uri = $this
    ->getOption('icon');
  $dependencies = $this
    ->getDependencies();
  $module = isset($dependencies['module'][0]) && !empty($dependencies['module'][0]) ? $dependencies['module'][0] : '';

  // Support static icons at MODULE_NAME/images/OPTIONSET_ID.png as long as
  // the module dependencies are declared explicitly for the stored optionset.
  if (empty($uri) || !is_file($uri)) {

    // Reset to empty first.
    $uri = '';
    $handler = \Drupal::service('gridstack.manager')
      ->getModuleHandler();
    if ($module && $handler
      ->moduleExists($module)) {
      $icon_path = drupal_get_path('module', $module) . '/images/' . $id . '.png';
      if (is_file(DRUPAL_ROOT . '/' . $icon_path)) {
        $uri = $icon_path;
      }
    }
  }
  return $uri;
}