You are here

function webform_views_webform_id_from_path in Webform Views Integration 8.5

Retrieve webform ID from a views path.

Parameters

string $path: Path where webform ID to extract from

Return value

string Webform ID if one is encountered in the provided $path, NULL otherwise

2 calls to webform_views_webform_id_from_path()
RouteSubscriber::alterRoutes in src/Routing/RouteSubscriber.php
Alters existing routes for a specific collection.
webform_views_menu_local_tasks_alter in ./webform_views.module
Implements hook_menu_local_tasks_alter().

File

./webform_views.module, line 231
Webform integration with views.

Code

function webform_views_webform_id_from_path($path) {
  $path = explode('/', $path);

  // Strip the last path chunk, this way we should be one level above the
  // current.
  array_pop($path);

  // Try each chunk of the path seeing if it is not actually a webform
  // id.
  foreach ($path as $k => $v) {
    $webform = \Drupal::entityTypeManager()
      ->getStorage('webform')
      ->load(str_replace('-', '_', $v));
    if ($webform) {
      return $webform
        ->id();
    }
  }
  return NULL;
}