You are here

public function ConditionalFieldsFormHelper::getSelector in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 src/ConditionalFieldsFormHelper.php \Drupal\conditional_fields\ConditionalFieldsFormHelper::getSelector()

Build a jQuery selector if it was not overridden by a custom value.

Note that this may be overridden later by a state handler.

1 call to ConditionalFieldsFormHelper::getSelector()
ConditionalFieldsFormHelper::processDependeeFields in src/ConditionalFieldsFormHelper.php
Determine and register dependee field effects.

File

src/ConditionalFieldsFormHelper.php, line 297

Class

ConditionalFieldsFormHelper
Helper to interact with forms.

Namespace

Drupal\conditional_fields

Code

public function getSelector($options_selector, $dependee_form_field) {
  if (!$options_selector) {
    $selector = $this
      ->buildJquerySelectorForField($dependee_form_field);
  }
  else {

    // Replace the language placeholder in the selector with current language.
    $current_language = \Drupal::languageManager()
      ->getCurrentLanguage()
      ->getId();
    $language = isset($dependee_form_field['#language']) ? $dependee_form_field['#language'] : $current_language;
    $selector = str_replace('%lang', $language, $options_selector);
  }
  return $selector;
}