You are here

function yamlform_theme_suggestions_alter in YAML Form 8

Implements hook_theme_suggestions_alter().

File

./yamlform.module, line 486
Enables the creation of forms and questionnaires.

Code

function yamlform_theme_suggestions_alter(array &$suggestions, array $variables, $hook) {
  if (strpos($hook, 'yamlform_') !== 0) {
    return;
  }
  if (strpos($hook, 'yamlform_element_base_') === 0 || strpos($hook, 'yamlform_container_base_') === 0) {
    $element = $variables['element'];
    if (empty($element['#type'])) {
      return;
    }
    $type = $element['#type'];
    $name = $element['#yamlform_key'];
    $suggestions[] = $hook . '__' . $type;
    $suggestions[] = $hook . '__' . $type . '__' . $name;

    /** @var \Drupal\yamlform\YamlFormElementManagerInterface $element_manager */
    $element_manager = \Drupal::service('plugin.manager.yamlform.element');
    $element_handler = $element_manager
      ->createInstance($type);
    if ($format = $element_handler
      ->getFormat($element)) {
      $suggestions[] = $hook . '__' . $type . '__' . $format;
      $suggestions[] = $hook . '__' . $type . '__' . $name . '__' . $format;
    }
  }
  elseif (isset($variables['yamlform_submission'])) {

    /** @var \Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission */
    $yamlform_submission = $variables['yamlform_submission'];
    $yamlform = $yamlform_submission
      ->getYamlForm();
    $suggestions[] = $hook . '__' . $yamlform
      ->id();
  }
  elseif (isset($variables['yamlform'])) {

    /** @var \Drupal\yamlform\YamlFormInterface $yamlform */
    $yamlform = $variables['yamlform'];
    $suggestions[] = $hook . '__' . $yamlform
      ->id();
  }
}