You are here

public function WebformOptionsStorage::getUsedByWebforms in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/WebformOptionsStorage.php \Drupal\webform\WebformOptionsStorage::getUsedByWebforms()

Get list of webform that use the specified webform options.

Parameters

\Drupal\webform\WebformOptionsInterface $webform_options: A webform options entity.

Return value

array A list of webform that use the specified webform options.

Overrides WebformOptionsStorageInterface::getUsedByWebforms

File

src/WebformOptionsStorage.php, line 154

Class

WebformOptionsStorage
Storage controller class for "webform_options" configuration entities.

Namespace

Drupal\webform

Code

public function getUsedByWebforms(WebformOptionsInterface $webform_options) {
  if (!isset($this->usedByWebforms)) {

    // Looping through webform configuration instead of webform entities to
    // improve performance.
    $this->usedByWebforms = [];
    foreach ($this->configFactory
      ->listAll('webform.webform.') as $webform_config_name) {
      $config = $this->configFactory
        ->get($webform_config_name);
      $element_data = Yaml::encode($config
        ->get('elements'));
      if (preg_match_all('/(?:options|answers)\'\\: ([a-z_]+)/', $element_data, $matches)) {
        $webform_id = $config
          ->get('id');
        $webform_title = $config
          ->get('title');
        foreach ($matches[1] as $options_id) {
          $this->usedByWebforms[$options_id][$webform_id] = $webform_title;
        }
      }
    }
  }
  $options_id = $webform_options
    ->id();
  return isset($this->usedByWebforms[$options_id]) ? $this->usedByWebforms[$options_id] : [];
}