You are here

class LinkIconManager in Link Icon 8

Provides LinkIconManager service.

Hierarchy

Expanded class hierarchy of LinkIconManager

1 string reference to 'LinkIconManager'
linkicon.services.yml in ./linkicon.services.yml
linkicon.services.yml
1 service uses LinkIconManager
linkicon.manager in ./linkicon.services.yml
Drupal\linkicon\LinkIconManager

File

src/LinkIconManager.php, line 11

Namespace

Drupal\linkicon
View source
class LinkIconManager implements LinkIconManagerInterface {

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $config;

  /**
   * The module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * {@inheritdoc}
   */
  public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler) {
    $this->config = $config_factory
      ->get('linkicon.settings');
    $this->moduleHandler = $module_handler;
  }

  /**
   * {@inheritdoc}
   */
  public function getSetting($setting_name) {
    return $this->config
      ->get($setting_name);
  }

  /**
   * {@inheritdoc}
   */
  public function simplifySettings(array $settings = []) {
    $config = [];
    foreach ($settings as $key => $value) {
      $config[str_replace('linkicon_', '', $key)] = $value;
    }
    return $config;
  }

  /**
   * {@inheritdoc}
   */
  public function extractAllowedValues($values, $is_tooltip = FALSE) {
    $allowed_values = [];
    if ($values) {
      $list = explode("\n", strip_tags($values));
      foreach ($list as $value) {
        if (strpos($value, "|") !== FALSE) {
          list($key, $title, $tooltip) = array_pad(array_map('trim', explode("|", $value, 3)), 3, NULL);
          $allowed_values[$key] = $is_tooltip && !empty($tooltip) ? $tooltip : $title;
        }
        else {
          $allowed_values[$value] = $value;
        }
      }
    }
    return $allowed_values;
  }

  /**
   * Implements hook_library_info_build().
   */
  public function libraryInfoBuild() {
    $libraries = [];
    if ($font_path = $this
      ->getSetting('font')) {
      if (strpos($font_path, ',') !== FALSE) {
        $paths = array_map('trim', explode(',', $font_path));
        foreach ($paths as $path) {
          $library_path[$path] = [];
        }
      }
      else {
        $library_path = [
          $font_path => [],
        ];
      }
      $libraries['linkicon.font'] = [
        'css' => [
          'base' => $library_path,
        ],
      ];
    }
    return $libraries;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LinkIconManager::$config protected property The config factory.
LinkIconManager::$moduleHandler protected property The module handler service.
LinkIconManager::extractAllowedValues public function Returns extracted allowed title values. Overrides LinkIconManagerInterface::extractAllowedValues
LinkIconManager::getSetting public function Returns available settings. Overrides LinkIconManagerInterface::getSetting
LinkIconManager::libraryInfoBuild public function Implements hook_library_info_build().
LinkIconManager::simplifySettings public function
LinkIconManager::__construct public function
LinkIconManagerInterface::LINKICON_PREDEFINED constant Play safe predefined option on forms, where DRUPAL_REQUIRED = 2.