You are here

public static function ConfigSelector::getConfigEntityLink in Configuration selector 8.2

Same name and namespace in other branches
  1. 8 src/ConfigSelector.php \Drupal\config_selector\ConfigSelector::getConfigEntityLink()

Generates a link for a configuration entity if possible.

Parameters

\Drupal\Core\Config\Entity\ConfigEntityInterface $entity: The configuration entity to generate a link for.

Return value

\Drupal\Core\GeneratedUrl|string The best URL to link to the entity with. Edit links are preferred to canonical links. If no link is possible an empty string is returned.

6 calls to ConfigSelector::getConfigEntityLink()
ConfigSelector::selectConfigOnInstall in src/ConfigSelector.php
Selects configuration to enable and disable after installing modules.
ConfigSelector::selectConfigOnUninstall in src/ConfigSelector.php
Selects configuration to enable after uninstalling a module.
ConfigSelectorTest::testGetConfigEntityLinkToUrlCanonical in tests/src/Unit/ConfigSelectorTest.php
@covers ::getConfigEntityLink
ConfigSelectorTest::testGetConfigEntityLinkToUrlEditForm in tests/src/Unit/ConfigSelectorTest.php
@covers ::getConfigEntityLink
ConfigSelectorTest::testGetConfigEntityLinkToUrlException in tests/src/Unit/ConfigSelectorTest.php
@covers ::getConfigEntityLink

... See full list

File

src/ConfigSelector.php, line 335

Class

ConfigSelector
Selects configuration to enable after a module install or uninstall.

Namespace

Drupal\config_selector

Code

public static function getConfigEntityLink(ConfigEntityInterface $entity) {
  try {
    if ($entity
      ->hasLinkTemplate('edit-form')) {
      $url = $entity
        ->toUrl('edit-form');
    }
    else {
      $url = $entity
        ->toUrl();
    }
  } catch (\Exception $e) {
  }
  return isset($url) ? $url
    ->toString() : '';
}