You are here

public function CustomLinkManager::get in Simple XML sitemap 4.x

Gets custom link settings for the currently set variants.

Parameters

string|null $path: Limits the result set by an internal path.

bool $supplement_defaults: Supplements the result set with default custom link settings.

bool $multiple_variants: If true, returns an array of results keyed by variant name, otherwise it returns the result set for the first variant only.

Return value

array|mixed|null

2 calls to CustomLinkManager::get()
CustomLinkManager::add in src/Manager/CustomLinkManager.php
Stores a custom path along with its settings to configuration for the currently set variants.
CustomLinkManager::remove in src/Manager/CustomLinkManager.php
Removes custom links from currently set variants.

File

src/Manager/CustomLinkManager.php, line 107

Class

CustomLinkManager
Class CustomLinkManager

Namespace

Drupal\simple_sitemap\Manager

Code

public function get(?string $path = NULL, bool $supplement_defaults = TRUE, bool $multiple_variants = FALSE) : array {
  $all_custom_links = [];
  foreach ($this
    ->getVariants(FALSE) as $variant) {
    $custom_links = $this->configFactory
      ->get("simple_sitemap.custom_links.{$variant}")
      ->get('links');
    $custom_links = !empty($custom_links) ? $custom_links : [];
    if (!empty($custom_links) && $path !== NULL) {
      foreach ($custom_links as $key => $link) {
        if ($link['path'] !== $path) {
          unset($custom_links[$key]);
        }
      }
    }
    if (!empty($custom_links) && $supplement_defaults) {
      foreach ($custom_links as $i => $link_settings) {
        self::supplementDefaultSettings($link_settings);
        $custom_links[$i] = $link_settings;
      }
    }
    $custom_links = $path !== NULL && !empty($custom_links) ? array_values($custom_links)[0] : array_values($custom_links);
    if (!empty($custom_links)) {
      if ($multiple_variants) {
        $all_custom_links[$variant] = $custom_links;
      }
      else {
        return $custom_links;
      }
    }
  }
  return $all_custom_links;
}