Best Phoronix-test-suite code snippet using variables
webform.theme.template.inc
Source:webform.theme.template.inc  
...19use Drupal\webform\Utility\WebformDateHelper;20use Drupal\webform\Utility\WebformDialogHelper;21use Drupal\webform\Utility\WebformElementHelper;22/**23 * Prepares variables for webform help.24 *25 * Default template: webform_help.html.twig.26 *27 * @param array $variables28 *   An associative array containing:29 *   - title: Help title.30 *   - content: Help content.31 */32function template_preprocess_webform_help(array &$variables) {33  /** @var \Drupal\webform\WebformHelpManagerInterface $help_manager */34  $help_manager = \Drupal::service('webform.help_manager');35  $help_info = $variables['info'];36  $variables += $help_info;37  $help = [];38  // Content.39  if (is_array($help_info['content'])) {40    $help['content'] = $help_info['content'];41  }42  else {43    $help['content'] = [44      '#markup' => $help_info['content'],45    ];46  }47  // Video.48  $video_info = (isset($help_info['video_id'])) ? $help_manager->getVideo($help_info['video_id']) : $help_info;49  if (isset($video_info['id'])) {50    $help['link'] = $help_manager->buildVideoLink($video_info['id']);51  }52  $variables['help'] = $help;53}54/**55 * Prepares variables for webform templates.56 *57 * Default template: webform.html.twig.58 *59 * @param array $variables60 *   An associative array containing:61 *   - element: An associative array containing the properties of the element.62 *     Properties used: #action, #method, #attributes, #webform_children.63 */64function template_preprocess_webform(array &$variables) {65  template_preprocess_form($variables);66}67/**68 * Prepares variables for webform actions templates.69 *70 * Default template: webform-actions.html.twig.71 *72 * @param array $variables73 *   An associative array containing:74 *   - element: An associative array containing the properties and buttons.75 *76 * @see \Drupal\webform\WebformSubmissionForm::actionsElement77 * @see \Drupal\webform\WebformSubmissionForm::actions78 */79function template_preprocess_webform_actions(array &$variables) {80  $element = $variables['element'];81  // Buttons include submit, previous, next, and draft.82  foreach (Element::children($element) as $key) {83    $variables[$key] = $element[$key];84  }85}86/**87 * Prepares variables for webform confirmation templates.88 *89 * Default template: webform-confirmation.html.twig.90 *91 * @param array $variables92 *   An associative array containing the following key:93 *   - webform: A webform.94 *   - webform_submission: A webform submission.95 *   - source_entity: A webform submission source entity.96 */97function template_preprocess_webform_confirmation(array &$variables) {98  /** @var \Drupal\webform\WebformInterface $webform */99  $webform = $variables['webform'];100  /** @var \Drupal\Core\Entity\EntityInterface $source_entity */101  $source_entity = $variables['source_entity'];102  /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */103  $webform_submission = $variables['webform_submission'];104  /** @var \Drupal\webform\WebformMessageManagerInterface $message_manager */105  $message_manager = \Drupal::service('webform.message_manager');106  $message_manager->setWebformSubmission($webform_submission);107  // Must set webform and source entity because webform submission could be108  // NULL.109  $message_manager->setWebform($webform);110  $message_manager->setSourceEntity($source_entity);111  // Assets: Add custom shared and webform specific CSS and JS.112  // @see webform_css_alter()113  // @see webform_js_alter()114  $assets = $webform->getAssets();115  foreach ($assets as $type => $value) {116    if ($value) {117      $variables['#attached']['library'][] = "webform/webform.assets.$type";118      $variables['#attached']['drupalSettings']['webform']['assets'][$type][$webform->id()] = Crypt::hashBase64($value);119    }120  }121  $settings = $webform->getSettings();122  // Set progress.123  if ($webform->getPages() && $settings['wizard_confirmation'] && ($settings['wizard_progress_bar'] || $settings['wizard_progress_pages'] || $settings['wizard_progress_percentage'])) {124    $variables['progress'] = [125      '#theme' => 'webform_progress',126      '#webform' => $webform,127      '#webform_submission' => $webform_submission,128      '#current_page' => 'webform_confirmation',129    ];130  }131  // Set message.132  $variables['message'] = $message_manager->build(WebformMessageManagerInterface::SUBMISSION_CONFIRMATION_MESSAGE);133  // Set attributes.134  $variables['attributes'] = new Attribute($settings['confirmation_attributes']);135  // Set back.136  $variables['back'] = $settings['confirmation_back'];137  $variables['back_label'] = $settings['confirmation_back_label'] ?: \Drupal::config('webform.settings')->get('settings.default_confirmation_back_label');138  $variables['back_attributes'] = new Attribute($settings['confirmation_back_attributes']);139  // Get query string parameters.140  $query = \Drupal::request()->query->all();141  // Add Ajax trigger to back link.142  // @see \Drupal\webform\WebformSubmissionForm::getCustomForm143  // @see Drupal.behaviors.webformConfirmationBackAjax (js/webform.ajax.js)144  $is_ajax = (!empty($query['ajax_form'])) ? TRUE : FALSE;145  if (!empty($is_ajax)) {146    $variables['back_attributes']->addClass('js-webform-confirmation-back-link-ajax');147  }148  // Apply all passed query string parameters to the 'Back to form' link.149  unset($query['webform_id'], $query['ajax_form'], $query['_wrapper_format'], $query['token'], $query['page']);150  $options = ($query) ? ['query' => $query] : [];151  // Set back_url.152  if ($source_entity && $source_entity->hasLinkTemplate('canonical')) {153    $source_entity = \Drupal::service('entity.repository')->getTranslationFromContext($source_entity);154    $variables['back_url'] = $source_entity->toUrl('canonical', $options)->toString();155  }156  elseif ($webform_submission) {157    $source_url = $webform_submission->getSourceUrl();158    $query = $source_url->getOption('query');159    unset($query['webform_id'], $query['ajax_form'], $query['_wrapper_format'], $query['token'], $query['page']);160    $source_url->setOption('query', $query);161    $variables['back_url'] = $source_url->toString();162  }163  else {164    $variables['back_url'] = $webform->toUrl('canonical', $options)->toString();165  }166  $webform->invokeHandlers('preprocessConfirmation', $variables);167}168/**169 * Prepares variables for webform submission navigation templates.170 *171 * Default template: webform-submission-navigation.html.twig.172 *173 * @param array $variables174 *   An associative array containing the following key:175 *   - webform_submission: A webform submission.176 *   - rel: Webform submission link template.177 *          (canonical, edit-form, resend-form, html, text, or yaml).178 */179function template_preprocess_webform_submission_navigation(array &$variables) {180  /** @var \Drupal\webform\WebformRequestInterface $request_handler */181  $request_handler = \Drupal::service('webform.request');182  /** @var \Drupal\webform\WebformSubmissionStorageInterface $webform_submission_storage */183  $webform_submission_storage = \Drupal::entityTypeManager()->getStorage('webform_submission');184  /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */185  $webform_submission = $variables['webform_submission'];186  $webform = $webform_submission->getWebform();187  // Webform id and title for context.188  $variables['webform_id'] = $webform->id();189  $variables['webform_title'] = $webform->label();190  // Get the route name, parameters, and source entity for the current page.191  // This ensures that the user stays within their current context as they are192  // paging through submission.193  $route_name = \Drupal::routeMatch()->getRouteName();194  $route_parameters = \Drupal::routeMatch()->getRawParameters()->all();195  $source_entity = $request_handler->getCurrentSourceEntity('webform_submission');196  if (strpos(\Drupal::routeMatch()->getRouteName(), 'webform.user.submission') !== FALSE) {197    $account = \Drupal::currentUser();198    $options = ['in_draft' => FALSE];199  }200  else {201    $account = NULL;202    $options = ['in_draft' => NULL];203  }204  if ($previous_submission = $webform_submission_storage->getPreviousSubmission($webform_submission, $source_entity, $account, $options)) {205    $variables['prev_url'] = Url::fromRoute($route_name, ['webform_submission' => $previous_submission->id()] + $route_parameters)->toString();206  }207  if ($next_submission = $webform_submission_storage->getNextSubmission($webform_submission, $source_entity, $account, $options)) {208    $variables['next_url'] = Url::fromRoute($route_name, ['webform_submission' => $next_submission->id()] + $route_parameters)->toString();209  }210  $variables['#attached']['library'][] = 'webform/webform.navigation';211  // Never cache navigation because previous and next submission will change212  // as submissions are added and deleted.213  $variables['#cache'] = ['max-age' => 0];214}215/**216 * Prepares variables for webform submission templates.217 *218 * Default template: webform-submission.html.twig.219 *220 * @param array $variables221 *   An associative array containing:222 *   - elements: An array of elements to display in view mode.223 *   - webform_submission: The webform submissions object.224 *   - view_mode: View mode; e.g., 'html', 'text', 'table', 'yaml', etc.225 */226function template_preprocess_webform_submission(array &$variables) {227  $variables['view_mode'] = $variables['elements']['#view_mode'];228  $variables['navigation'] = $variables['elements']['navigation'];229  $variables['information'] = $variables['elements']['information'];230  $variables['submission'] = $variables['elements']['submission'];231  $variables['webform_submission'] = $variables['elements']['#webform_submission'];232  if ($variables['webform_submission'] instanceof WebformSubmissionInterface) {233    $variables['webform'] = $variables['webform_submission']->getWebform();234  }235}236/**237 * Prepares variables for webform submission data templates.238 *239 * Default template: webform-submission-data.html.twig.240 *241 * @param array $variables242 *   An associative array containing:243 *   - data: An array of elements to display in view mode.244 *   - webform_submission: The webform submissions object.245 *   - view_mode: View mode; e.g., 'html', 'text', 'table', 'yaml', etc.246 */247function template_preprocess_webform_submission_data(array &$variables) {248  $variables['view_mode'] = $variables['elements']['#view_mode'];249  $variables['webform_submission'] = $variables['elements']['#webform_submission'];250  if ($variables['webform_submission'] instanceof WebformSubmissionInterface) {251    $variables['webform'] = $variables['webform_submission']->getWebform();252  }253}254/**255 * Prepares variables for webform submission information template.256 *257 * Default template: webform-submission-information.html.twig.258 *259 * @param array $variables260 *   An associative array containing the following key:261 *   - webform_submission: A webform submission.262 */263function template_preprocess_webform_submission_information(array &$variables) {264  /** @var \Drupal\webform\WebformSubmissionInterface $webform_submission */265  $webform_submission = $variables['webform_submission'];266  $webform = $webform_submission->getWebform();267  $variables['serial'] = $webform_submission->serial();268  $variables['sid'] = $webform_submission->id();269  $variables['uuid'] = $webform_submission->uuid();270  $variables['is_draft'] = $webform_submission->isDraft() ? t('Yes') : t('No');271  $variables['current_page'] = $webform_submission->getCurrentPageTitle();272  $variables['remote_addr'] = $webform_submission->getRemoteAddr();273  $variables['submitted_by'] = $webform_submission->getOwner()->toLink();274  $variables['webform'] = $webform->toLink();275  $variables['created'] = WebformDateHelper::format($webform_submission->getCreatedTime());276  $variables['completed'] = WebformDateHelper::format($webform_submission->getCompletedTime());277  $variables['changed'] = WebformDateHelper::format($webform_submission->getChangedTime());278  $variables['sticky'] = $webform_submission->isSticky() ? t('Yes') : '';279  $variables['locked'] = $webform_submission->isLocked() ? t('Yes') : '';280  $variables['notes'] = $webform_submission->getNotes();281  // @see \Drupal\Core\Field\Plugin\Field\FieldFormatter\LanguageFormatter::viewValue()282  $languages = \Drupal::languageManager()->getNativeLanguages();283  $langcode = $webform_submission->get('langcode')->value;284  $variables['language'] = isset($languages[$langcode]) ? $languages[$langcode]->getName() : $langcode;285  if ($source_url = $webform_submission->getSourceUrl()) {286    $variables['uri'] = Link::fromTextAndUrl($source_url->setAbsolute(FALSE)->toString(), $source_url);287  }288  if ($webform->getSetting('token_view')) {289    $token_view_url = $webform_submission->getTokenUrl('view');290    $variables['token_view'] = Link::fromTextAndUrl($token_view_url->setAbsolute(FALSE)->toString(), $token_view_url);291  }292  if ($webform->getSetting('token_update')) {293    $token_update_url = $webform_submission->getTokenUrl('update');294    $variables['token_update'] = Link::fromTextAndUrl($token_update_url->setAbsolute(FALSE)->toString(), $token_update_url);295  }296  if (($source_entity = $webform_submission->getSourceEntity()) && $source_entity->hasLinkTemplate('canonical')) {297    $variables['submitted_to'] = $source_entity->toLink();298  }299  $variables['submissions_view'] = FALSE;300  if ($webform->access('submission_view_any')) {301    $variables['submissions_view'] = TRUE;302  }303  elseif ($source_entity) {304    $entity_type = $source_entity->getEntityTypeId();305    if (\Drupal::currentUser()->hasPermission("view webform node submissions any $entity_type")) {306      $variables['submissions_view'] = TRUE;307    }308    elseif (\Drupal::currentUser()->hasPermission("view webform node submissions own $entity_type")309      && method_exists($source_entity, 'getOwnerId')310      && $source_entity->getOwnerId() == \Drupal::currentUser()->id()311    ) {312      $variables['submissions_view'] = TRUE;313    }314  }315  if ($webform_submission->access('delete')) {316    /** @var \Drupal\webform\WebformRequestInterface $request_handler */317    $request_handler = \Drupal::service('webform.request');318    $base_route_name = (strpos(\Drupal::routeMatch()->getRouteName(), 'webform.user.submission') !== FALSE) ? 'webform.user.submission.delete' : 'webform_submission.delete_form';319    $url = $request_handler->getUrl($webform_submission, $source_entity, $base_route_name);320    $variables['delete'] = [321      '#type' => 'link',322      '#title' => t('Delete submission'),323      '#url' => $url,324      '#attributes' => WebformDialogHelper::getModalDialogAttributes(WebformDialogHelper::DIALOG_NARROW, ['button', 'button--danger']),325    ];326    WebformDialogHelper::attachLibraries($variables['delete']);327  }328}329/**330 * Prepares variables for webform CodeMirror template.331 *332 * Default template: webform-codemirror.html.twig.333 *334 * @param array $variables335 *   An associative array containing the following key:336 *   - code: The code.337 *   - type: The type of code.338 */339function template_preprocess_webform_codemirror(array &$variables) {340  $variables['mode'] = WebformCodeMirror::getMode($variables['type']);341  if (is_string($variables['code'])) {342    // Encode all HTML entities include tags.343    $variables['code'] = Markup::create(htmlentities($variables['code']));344  }345}346/**347 * Prepares variables for webform element base HTML template.348 *349 * Default template: webform-element-base-html.html.twig.350 *351 * @param array $variables352 *   An associative array containing the following key:353 *   - element: The webform element.354 *   - value: The content for the element.355 *   - options Associative array of options for element.356 *     - multiline: Flag to determine if value spans multiple lines.357 *     - email: Flag to determine if element is for an email.358 */359function template_preprocess_webform_element_base_html(array &$variables) {360  $element = $variables['element'];361  // Set title.362  _template_progress_webform_set_title($variables);363  // Build form (item) element for HTML display.364  // @see form-element.html.twig365  // @see template_preprocess_form_element366  if (empty($variables['options']['email'])) {367    $type = $element['#type'];368    $attributes = (isset($element['#format_attributes'])) ? $element['#format_attributes'] : [];369    $attributes += ['class' => []];370    // Use wrapper attributes for the id instead of #id,371    // this stops the <label> from having a 'for' attribute.372    $attributes += [373      'id' => $element['#webform_id'],374    ];375    $attributes['class'][] = 'webform-element';376    $attributes['class'][] = 'webform-element-type-' . str_replace('_', '-', $type);377    $variables['item'] = [378      '#type' => 'item',379      '#title' => $variables['title'],380      '#name' => $element['#webform_key'],381      '#wrapper_attributes' => $attributes,382    ];383    if (is_array($variables['value'])) {384      $variables['item']['value'] = $variables['value'];385    }386    else {387      $variables['item']['#markup'] = $variables['value'];388    }389  }390  else {391    $variables['title'] = ['#markup' => $variables['title']];392  }393}394/**395 * Prepares variables for webform element base text template.396 *397 * Default template: webform-element-base-text.html.twig.398 *399 * @param array $variables400 *   An associative array containing the following key:401 *   - element: The webform element.402 *   - value: The content for the element.403 *   - options Associative array of options for element.404 *     - multiline: Flag to determine if value spans multiple lines.405 *     - email: Flag to determine if element is for an email.406 */407function template_preprocess_webform_element_base_text(array &$variables) {408  // Set title.409  _template_progress_webform_set_title($variables, TRUE);410}411/**412 * Set variables title to element #title or #admin_title.413 *414 * @param array $variables415 *   An associative array containing the following key:416 *   - element: The webform element.417 * @param bool $strip_tags418 *   Remove HTML tags from title.419 */420function _template_progress_webform_set_title(array &$variables, $strip_tags = FALSE) {421  $element = $variables['element'];422  // Set title.423  $variables['title'] = (WebformElementHelper::isTitleDisplayed($element)) ? $element['#title'] : NULL;424  if (empty($variables['title']) && !empty($element['#admin_title'])) {425    $variables['title'] = $element['#admin_title'];426  }427  // Strip all HTML tags from the title.428  if ($strip_tags) {429    $variables['title'] = strip_tags($variables['title']);430  }431}432/******************************************************************************/433// Progress templates.434/******************************************************************************/435/**436 * Prepares variables for webform 'wizard' progress template.437 *438 * Default template: webform-progress.html.twig.439 *440 * @param array $variables441 *   An associative array containing the following key:442 *   - webform: A webform.443 *   - current_page: The current wizard page.444 */445function template_preprocess_webform_progress(array &$variables) {446  /** @var \Drupal\webform\WebformLibrariesManagerInterface $libraries_manager */447  $libraries_manager = \Drupal::service('webform.libraries_manager');448  /** @var \Drupal\webform\WebformInterface $webform */449  $webform = $variables['webform'];450  $webform_submission = $variables['webform_submission'];451  $current_page = $variables['current_page'];452  $operation = $variables['operation'];453  $pages = $webform->getPages($operation, $webform_submission);454  $page_keys = array_keys($pages);455  $page_indexes = array_flip($page_keys);456  $current_index = $page_indexes[$current_page];457  $total = count($page_keys);458  if ($webform->getSetting('wizard_progress_bar')) {459    $variables['bar'] = [460      '#theme' => ($libraries_manager->isIncluded('progress-tracker')) ? 'webform_progress_tracker' : 'webform_progress_bar',461      '#webform' => $webform,462      '#webform_submission' => $webform_submission,463      '#current_page' => $current_page,464      '#operation' => $operation,465    ];466  }467  if ($webform->getSetting('wizard_progress_pages')) {468    $variables['summary'] = t('Page @start of @end', ['@start' => $current_index + 1, '@end' => $total]);469  }470  if ($webform->getSetting('wizard_progress_percentage')) {471    $variables['percentage'] = number_format(($current_index / ($total - 1)) * 100, 0) . '%';472  }473}474/**475 * Prepares variables for webform 'wizard' progress bar template.476 *477 * Default template: webform-progress-bar.html.twig.478 *479 * @param array $variables480 *   An associative array containing the following key:481 *   - webform: A webform.482 *   - current_page: The current wizard page.483 */484function template_preprocess_webform_progress_bar(array &$variables) {485  _template_preprocess_webform_progress($variables);486}487/**488 * Prepares variables for webform 'wizard' progress tracker template.489 *490 * Default template: webform-progress-tracker.html.twig.491 *492 * @param array $variables493 *   An associative array containing the following key:494 *   - webform: A webform.495 *   - current_page: The current wizard page.496 */497function template_preprocess_webform_progress_tracker(array &$variables) {498  _template_preprocess_webform_progress($variables);499}500/**501 * Prepares variables for webform 'wizard' progress bar & tracker template.502 *503 * @param array $variables504 *   An associative array containing the following key:505 *   - webform: A webform.506 *   - current_page: The current wizard page.507 */508function _template_preprocess_webform_progress(array &$variables) {509  /** @var \Drupal\webform\WebformInterface $webform */510  $webform = $variables['webform'];511  $webform_submission = $variables['webform_submission'];512  $current_page = $variables['current_page'];513  $operation = $variables['operation'];514  $pages = $webform->getPages($operation, $webform_submission);515  $page_keys = array_keys($pages);516  $page_indexes = array_flip($page_keys);517  $current_index = $page_indexes[$current_page];518  $variables['current_index'] = $current_index;519  // Reset the pages variable.520  $variables['progress'] = [];521  foreach ($pages as $key => $page) {522    $variables['progress'][] = [523      'name' => $key,524      'title' => (isset($page['#title'])) ? $page['#title'] : '',525    ];526  }527}528/******************************************************************************/529// Element templates.530/******************************************************************************/531/**532 * Prepares variables for Webform message templates.533 *534 * Default template: webform-message.html.twig.535 *536 * @param array $variables537 *   An associative array containing:538 *   - element: An associative array containing the properties of the element.539 *     Properties used: #id, #attributes, #children.540 *541 * @see template_preprocess_container()542 */543function template_preprocess_webform_message(array &$variables) {544  $variables['has_parent'] = FALSE;545  $element = $variables['element'];546  // Ensure #attributes is set.547  $element += ['#attributes' => []];548  // Special handling for webform elements.549  if (isset($element['#array_parents'])) {550    // Assign an html ID.551    if (!isset($element['#attributes']['id'])) {552      $element['#attributes']['id'] = $element['#id'];553    }554    $variables['has_parent'] = TRUE;555  }556  $variables['message'] = $element['#message'];557  $variables['attributes'] = $element['#attributes'];558  if (isset($element['#closed'])) {559    $variables['closed'] = $element['#closed'];560  }561}562/**563 * Prepares variables for Webform HTML Editor markup templates.564 *565 * Default template: webform-html-editor-markup.html.twig.566 *567 * @param array $variables568 *   An associative array containing:569 *   - markup: HTML markup.570 *   - allowed_tags: Allowed tags.571 */572function template_preprocess_webform_html_editor_markup(array &$variables) {573  $variables['content'] = [574    '#markup' => $variables['markup'],575    '#allowed_tags' => $variables['allowed_tags'],576  ];577}578/**579 * Prepares variables for Webform horizontal rule templates.580 *581 * Default template: webform-horizontal-rule.html.twig.582 *583 * @param array $variables584 *   An associative array containing:585 *   - element: An associative array containing the properties of the element.586 *     Properties used: #id, #attributes.587 */588function template_preprocess_webform_horizontal_rule(array &$variables) {589  $element = $variables['element'];590  if (!empty($element['#id'])) {591    $variables['attributes']['id'] = $element['#id'];592  }593}594/**595 * Prepares variables for webform section element templates.596 *597 * Default template: webform-section.html.twig.598 *599 * Copied from: template_preprocess_fieldset()600 *601 * @param array $variables602 *   An associative array containing:603 *   - element: An associative array containing the properties of the element.604 *     Properties used: #attributes, #children, #description, #id, #title,605 *     #value.606 */607function template_preprocess_webform_section(array &$variables) {608  $element = $variables['element'];609  Element::setAttributes($element, ['id']);610  RenderElement::setAttributes($element);611  $variables['attributes'] = isset($element['#attributes']) ? $element['#attributes'] : [];612  $variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL;613  $variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL;614  $variables['title_display'] = isset($element['#title_display']) ? $element['#title_display'] : NULL;615  $variables['title_tag'] = isset($element['#title_tag']) ? $element['#title_tag'] : 'h2';616  $variables['title_attributes'] = isset($element['#title_attributes']) ? $element['#title_attributes'] : [];617  $variables['children'] = $element['#children'];618  $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;619  // Allow markup in title.620  if (isset($element['#title']) && $element['#title'] !== '') {621    $variables['title'] = ['#markup' => $element['#title']];622  }623  // Add 'visually-hidden' class to title attributes.624  if ($variables['title_display'] == 'invisible') {625    $variables['title_attributes']['class'][] = 'visually-hidden';626  }627  $variables['title_attributes'] = new Attribute($variables['title_attributes']);628  if (!empty($element['#description'])) {629    $description_id = $element['#attributes']['id'] . '--description';630    $description_attributes['id'] = $description_id;631    $variables['description']['attributes'] = new Attribute($description_attributes);632    $variables['description']['content'] = $element['#description'];633    // Add the description's id to the fieldset aria attributes.634    $variables['attributes']['aria-describedby'] = $description_id;635  }636  // Suppress error messages.637  $variables['errors'] = NULL;638}639/******************************************************************************/640// Composite templates641/******************************************************************************/642/**643 * Prepares variables for composite element templates.644 *645 * @param array $variables646 *   An associative array containing:647 *   - element: An associative array containing the properties of the element.648 */649function _template_preprocess_webform_composite(array &$variables) {650  $element = $variables['element'];651  // Copy all accessible element children to content.652  foreach (Element::children($element) as $key) {653    if (!isset($element[$key]['#access']) || $element[$key]['#access']) {654      $variables['content'][$key] = $element[$key];655    }656  }657  // Set flexbox variable used for multi column element layout.658  $variables['flexbox'] = (isset($element['#flexbox'])) ? $element['#flexbox'] : FALSE;659}660/**661 * Prepares variables for address composite element templates.662 *663 * Default template: webform-element-address.html.twig.664 *665 * @param array $variables666 *   An associative array containing:667 *   - element: An associative array containing the properties of the element.668 */669function template_preprocess_webform_composite_address(array &$variables) {670  _template_preprocess_webform_composite($variables);671}672/**673 * Prepares variables for contact composite element templates.674 *675 * Default template: webform-element-contact.html.twig.676 *677 * @param array $variables678 *   An associative array containing:679 *   - element: An associative array containing the properties of the element.680 */681function template_preprocess_webform_composite_contact(array &$variables) {682  _template_preprocess_webform_composite($variables);683}684/**685 * Prepares variables for link composite element templates.686 *687 * Default template: webform-element-link.html.twig.688 *689 * @param array $variables690 *   An associative array containing:691 *   - element: An associative array containing the properties of the element.692 */693function template_preprocess_webform_composite_link(array &$variables) {694  $variables['content'] = $variables['element'];695}696/**697 * Prepares variables for location composite element templates.698 *699 * Default template: webform-element-location.html.twig.700 *701 * @param array $variables702 *   An associative array containing:703 *   - element: An associative array containing the properties of the element.704 */705function template_preprocess_webform_composite_location(array &$variables) {706  $variables['content'] = $variables['element'];707}708/**709 * Prepares variables for name composite element templates.710 *711 * Default template: webform-element-name.html.twig.712 *713 * @param array $variables714 *   An associative array containing:715 *   - element: An associative array containing the properties of the element.716 */717function template_preprocess_webform_composite_name(array &$variables) {718  _template_preprocess_webform_composite($variables);719}720/**721 * Prepares variables for telephone composite element templates.722 *723 * Default template: webform-element-telephone.html.twig.724 *725 * @param array $variables726 *   An associative array containing:727 *   - element: An associative array containing the properties of the element.728 */729function template_preprocess_webform_composite_telephone(array &$variables) {730  _template_preprocess_webform_composite($variables);731}732/******************************************************************************/733// Element templates734/******************************************************************************/735/**736 * Prepares variables for element help.737 *738 * Default template: webform-element-help.html.twig.739 *740 * @param array $variables741 *   An associative array containing the following key:742 *   - element: The webform element.743 *   - help: The help content.744 *   - attributes: The help attributes.745 */746function template_preprocess_webform_element_help(array &$variables) {747  $attributes = (isset($variables['attributes'])) ? $variables['attributes'] : [];748  $attributes['class'][] = 'webform-element-help';749  $attributes['role'] = 'tooltip';750  $attributes['tabindex'] = '0';751  $content = (is_array($variables['help'])) ? \Drupal::service('renderer')->render($variables['help']) : $variables['help'];752  $help = '';753  if (!empty($variables['help_title'])) {754    $help .= '<div class="webform-element-help--title">' . WebformHtmlEditor::stripTags($variables['help_title']) . '</div>';755  }756  $help .= '<div class="webform-element-help--content">' . WebformHtmlEditor::stripTags($content) . '</div>';757  $attributes['data-webform-help'] = $help;758  $variables['attributes'] = new Attribute($attributes);759}760/**761 * Prepares variables for element more.762 *763 * Default template: webform-element-more.html.twig.764 *765 * @param array $variables766 *   An associative array containing the following key:767 *   - element: The webform element.768 */769function template_preprocess_webform_element_more(array &$variables) {770  if (empty($variables['more_title'])) {771    $variables['more_title'] = \Drupal::config('webform.settings')->get('element.default_more_title');772  }773  if (!is_array($variables['more'])) {774    $variables['more'] = [775      '#markup' => $variables['more'],776      '#allowed_tags' => WebformHtmlEditor::getAllowedTags(),777    ];778  }779  $variables['attributes'] = new Attribute($variables['attributes']);780  // Make sure there is a unique id.781  if (empty($variables['id'])) {782    $variables['id'] = Html::getUniqueId('webform-element-more');783  }784  // Make sure attributes id is set.785  if (!isset($variables['attributes']['id'])) {786    $variables['attributes']['id'] = $variables['id'];787  }788}789/**790 * Prepares variables for a managed file element.791 *792 * @param array $variables793 *   An associative array containing the following key:794 *   - element: The webform element.795 *   - value: The content for the element.796 *   - options Associative array of options for element.797 *   - file: The element's File object.798 */799function template_preprocess_webform_element_managed_file(array &$variables) {800  if (!empty($variables['file'])) {801    /** @var \Drupal\file\FileInterface $file */802    $file = $variables['file'];803    $variables['uri'] = file_create_url($file->getFileUri());804    $variables['extension'] = strtolower(pathinfo($variables['uri'], PATHINFO_EXTENSION));805    $variables['type'] = \Drupal::service('file.mime_type.guesser')->guess($variables['uri']);806    $variables['file_link'] = [807      '#theme' => 'file_link',808      '#file' => $file,809    ];810  }811}812/**813 * Prepares variables for an audio file element.814 *815 * Default template: webform-element-audio-file.html.twig.816 *817 * @param array $variables818 *   An associative array containing the following key:819 *   - element: The webform element.820 *   - value: The content for the element.821 *   - options Associative array of options for element.822 *   - file: The element's File object.823 */824function template_preprocess_webform_element_audio_file(array &$variables) {825  template_preprocess_webform_element_managed_file($variables);826}827/**828 * Prepares variables for a document file element.829 *830 * Default template: webform-element-document-file.html.twig.831 *832 * @param array $variables833 *   An associative array containing the following key:834 *   - element: The webform element.835 *   - value: The content for the element.836 *   - options Associative array of options for element.837 *   - file: The element's File object.838 */839function template_preprocess_webform_element_document_file(array &$variables) {840  template_preprocess_webform_element_managed_file($variables);841}842/**843 * Prepares variables for an image file element.844 *845 * Default template: webform-element-image-file.html.twig.846 *847 * @param array $variables848 *   An associative array containing the following key:849 *   - element: The webform element.850 *   - value: The content for the element.851 *   - options Associative array of options for element.852 *   - file: The element's File object.853 *   - style_name: An image style name.854 *   - format: Image formatting (link or modal)855 */856function template_preprocess_webform_element_image_file(array &$variables) {857  if (!empty($variables['file'])) {858    /** @var \Drupal\file\FileInterface $file */859    $file = $variables['file'];860    $style_name = $variables['style_name'];861    $format = $variables['format'];862    $uri = $file->getFileUri();863    $url = Url::fromUri(file_create_url($uri));864    $extension = pathinfo($uri, PATHINFO_EXTENSION);865    $is_image = in_array($extension, ['gif', 'png', 'jpg', 'jpeg']);866    // Build image.867    if ($is_image && \Drupal::moduleHandler()->moduleExists('image') && $style_name && ImageStyle::load($style_name)) {868      $variables['image'] = [869        '#theme' => 'image_style',870        '#style_name' => $variables['style_name'],871      ];872    }873    else {874      // Note: The 'image' template uses root-relative paths.875      // The 'image' is preprocessed to use absolute URLs.876      // @see webform_preprocess_image().877      $variables['image'] = [878        '#theme' => 'image',879      ];880    }881    $variables['image'] += [882      '#uri' => $uri,883      '#attributes' => [884        'class' => ['webform-image-file'],885        'alt' => $file->getFilename(),886        'title' => $file->getFilename(),887      ],888    ];889    // For the Results table always display the file name as a tooltip.890    if (strpos(\Drupal::routeMatch()->getRouteName(), 'webform.results_submissions') !== FALSE) {891      $variables['attached']['library'][] = 'webform/webform.tooltip';892      $variables['image']['#attributes']['class'][] = 'js-webform-tooltip-link';893    }894    // Wrap 'image' in a link/modal.895    if ($format && $format != 'image') {896      $variables['image'] = [897        '#type' => 'link',898        '#title' => $variables['image'],899        '#url' => $url,900      ];901      switch ($format) {902        case 'modal':903          $variables['image'] += [904            '#attributes' => ['class' => ['js-webform-image-file-modal', 'webform-image-file-modal']],905            '#attached' => ['library' => ['webform/webform.element.image_file.modal']],906          ];907          break;908        case 'link':909          $variables['image'] += ['#attributes' => ['class' => ['webform-image-file-link']]];910          break;911      }912    }913  }914}915/**916 * Prepares variables for a video file element.917 *918 * Default template: webform-element-video-file.html.twig.919 *920 * @param array $variables921 *   An associative array containing the following key:922 *   - element: The webform element.923 *   - value: The content for the element.924 *   - options Associative array of options for element.925 *   - file: The element's File object.926 */927function template_preprocess_webform_element_video_file(array &$variables) {928  template_preprocess_webform_element_managed_file($variables);929}...Php.php
Source:Php.php  
1<?php declare(strict_types=1);2/*3 * This file is part of PHPUnit.4 *5 * (c) Sebastian Bergmann <sebastian@phpunit.de>6 *7 * For the full copyright and license information, please view the LICENSE8 * file that was distributed with this source code.9 */10namespace PHPUnit\TextUI\XmlConfiguration;11/**12 * @internal This class is not covered by the backward compatibility promise for PHPUnit13 * @psalm-immutable14 */15final class Php16{17    /**18     * @var DirectoryCollection19     */20    private $includePaths;21    /**22     * @var IniSettingCollection23     */24    private $iniSettings;25    /**26     * @var ConstantCollection27     */28    private $constants;29    /**30     * @var VariableCollection31     */32    private $globalVariables;33    /**34     * @var VariableCollection35     */36    private $envVariables;37    /**38     * @var VariableCollection39     */40    private $postVariables;41    /**42     * @var VariableCollection43     */44    private $getVariables;45    /**46     * @var VariableCollection47     */48    private $cookieVariables;49    /**50     * @var VariableCollection51     */52    private $serverVariables;53    /**54     * @var VariableCollection55     */56    private $filesVariables;57    /**58     * @var VariableCollection59     */60    private $requestVariables;61    public function __construct(DirectoryCollection $includePaths, IniSettingCollection $iniSettings, ConstantCollection $constants, VariableCollection $globalVariables, VariableCollection $envVariables, VariableCollection $postVariables, VariableCollection $getVariables, VariableCollection $cookieVariables, VariableCollection $serverVariables, VariableCollection $filesVariables, VariableCollection $requestVariables)62    {63        $this->includePaths     = $includePaths;64        $this->iniSettings      = $iniSettings;65        $this->constants        = $constants;66        $this->globalVariables  = $globalVariables;67        $this->envVariables     = $envVariables;68        $this->postVariables    = $postVariables;69        $this->getVariables     = $getVariables;70        $this->cookieVariables  = $cookieVariables;71        $this->serverVariables  = $serverVariables;72        $this->filesVariables   = $filesVariables;73        $this->requestVariables = $requestVariables;74    }75    public function includePaths(): DirectoryCollection76    {77        return $this->includePaths;78    }79    public function iniSettings(): IniSettingCollection80    {81        return $this->iniSettings;82    }83    public function constants(): ConstantCollection84    {85        return $this->constants;86    }87    public function globalVariables(): VariableCollection88    {89        return $this->globalVariables;90    }91    public function envVariables(): VariableCollection92    {93        return $this->envVariables;94    }95    public function postVariables(): VariableCollection96    {97        return $this->postVariables;98    }99    public function getVariables(): VariableCollection100    {101        return $this->getVariables;102    }103    public function cookieVariables(): VariableCollection104    {105        return $this->cookieVariables;106    }107    public function serverVariables(): VariableCollection108    {109        return $this->serverVariables;110    }111    public function filesVariables(): VariableCollection112    {113        return $this->filesVariables;114    }115    public function requestVariables(): VariableCollection116    {117        return $this->requestVariables;118    }119}...variables
Using AI Code Generation
1$test = new pts_test_profile('test');2$test->set_result_proportion('PASS', 1);3$test->set_result_proportion('FAIL', 0);4$test->set_result_proportion('SKIP', 0);5$test->set_result_proportion('NA', 0);6$test->set_result_proportion('NOTRUN', 0);7$test->set_result_proportion('ERROR', 0);8$test->set_result_proportion('WARN', 0);9$test->set_result_proportion('UNKNOWN', 0);10$test->set_result_proportion('MEAN', 0);11$test->set_result_proportion('MEDIAN', 0);12$test->set_result_proportion('STDEV', 0);13$test->set_result_proportion('VARIANCE', 0);14$test->set_result_proportion('COEFFICIENT', 0);15$test->set_result_proportion('PERCENTILE', 0);16$test->set_result_proportion('GEOMEAN', 0);17$test->set_result_proportion('MIN', 0);18$test->set_result_proportion('MAX', 0);19$test->set_result_proportion('SUM', 0);20$test->set_result_proportion('PRODUCT', 0);21$test->set_result_proportion('RANGE', 0);22$test->set_result_proportion('COUNT', 0);23$test->set_result_proportion('NONE', 0);24$test->set_result_proportion('ALL', 0);25$test->set_result_proportion('ALLPASS', 0);26$test->set_result_proportion('ALLFAIL', 0);27$test->set_result_proportion('ALLSKIP', 0);28$test->set_result_proportion('ALLNA', 0);29$test->set_result_proportion('ALLNOTRUN', 0);30$test->set_result_proportion('ALLERROR', 0);31$test->set_result_proportion('ALLWARN', 0);32$test->set_result_proportion('ALLUNKNOWN', 0);33$test->set_result_proportion('ALLMEAN', 0);34$test->set_result_proportion('ALLMEDIAN', 0);35$test->set_result_proportion('ALLSTDEV', 0);36$test->set_result_proportion('ALLVARIANCE', 0);variables
Using AI Code Generation
1$var = new pts_test_run_request();2$var->test_profile->set_test_installation_request('install');3$var->test_profile->set_test_installation_request('reinstall');4$var->test_profile->set_test_installation_request('uninstall');5$var->test_profile->set_test_installation_request('skip');6$var->test_profile->set_test_installation_request('force-install');7$var->test_profile->set_test_installation_request('force-reinstall');8$var->test_profile->set_test_installation_request('force-uninstall');9$var->test_profile->set_test_installation_request('force-skip');10$var->test_profile->set_test_installation_request('force-install');11$var->test_profile->set_test_installation_request('force-reinstall');12$var->test_profile->set_test_installation_request('force-uninstall');13$var->test_profile->set_test_installation_request('force-skip');14$var->test_profile->set_test_installation_request('force-install');15$var->test_profile->set_test_installation_request('force-reinstall');16$var->test_profile->set_test_installation_request('force-uninstall');17$var->test_profile->set_test_installation_request('force-skip');18$var->test_profile->set_test_installation_request('force-install');19$var->test_profile->set_test_installation_request('force-reinstall');20$var->test_profile->set_test_installation_request('force-uninstall');21$var->test_profile->set_test_installation_request('force-skip');22$var->test_profile->set_test_installation_request('force-install');23$var->test_profile->set_test_installation_request('force-reinstall');24$var->test_profile->set_test_installation_request('force-uninstall');25$var->test_profile->set_test_installation_request('force-skip');26$var->test_profile->set_test_installation_request('force-install');27$var->test_profile->set_test_installation_request('force-reinstall');28$var->test_profile->set_test_installation_request('force-uninstall');29$var->test_profile->set_test_installation_request('force-skip');30$var->test_profile->set_test_installation_request('force-install');31$var->test_profile->set_test_installation_request('force-reinstall');32$var->test_profile->set_test_installation_request('force-uninstall');variables
Using AI Code Generation
1$test = new pts_test_profile('test');2$test->set_result_proportion('PASS', 1);3$test->set_result_proportion('FAIL', 0);4$test->set_result_proportion('SKIP', 0);5$test->set_result_proportion('NA', 0);6$test->set_result_proportion('NOTRUN', 0);7$test->set_result_proportion('ERROR', 0);8$test->set_result_proportion('WARN', 0);9$test->set_result_proportion('UNKNOWN', 0);10$test->set_result_proportion('MEAN', 0);11$test->set_result_proportion('MEDIAN', 0);12$test->set_result_proportion('STDEV', 0);13$test->set_result_proportion('VARIANCE', 0);14$test->set_result_proportion('COEFFICIENT', 0);15$test->set_result_proportion('PERCENTILE', 0);16$test->set_result_proportion('GEOMEAN', 0);17$test->set_result_proportion('MIN', 0);18$test->set_result_proportion('MAX', 0);19$test->set_result_proportion('SUM', 0);20$test->set_result_proportion('PRODUCT', 0);21$test->set_result_proportion('RANGE', 0);22$test->set_result_proportion('COUNT', 0);23$test->set_result_proportion('NONE', 0);24$test->set_result_proportion('ALL', 0);25$test->set_result_proportion('ALLPASS', 0);26$test->set_result_proportion('ALLFAIL', 0);27$test->set_result_proportion('ALLSKIP', 0);28$test->set_result_proportion('ALLNA', 0);29$test->set_result_proportion('ALLNOTRUN', 0);30$test->set_result_proportion('ALLERROR', 0);31$test->set_result_proportion('ALLWARN', 0);32$test->set_result_proportion('ALLUNKNOWN', 0);33$test->set_result_proportion('ALLMEAN', 0);34$test->set_result_proportion('ALLMEDIAN', 0);35$test->set_result_proportion('ALLSTDEV', 0);36$test->set_result_proportion('ALLVARIANCE', 0);37$pts = new pts_openbenchmarking();38$pts->set_variable('test', 'test');39$pts->set_variable('test_version', 'test_version');40$pts->set_variable('test_profile', 'test_profile');41$pts->set_variable('test_profile_version', 'test_profile_version');42$pts->set_variable('test_profile_description', 'test_profile_description');43$pts->set_variable('test_profile_license', 'test_profile_license');44$pts->set_variable('test_profile_url', 'test_profile_url');45$pts->set_variable('test_profile_tags', 'test_profile_tags');46$pts->set_variable('test_profile_maintainer', 'test_profile_maintainer');47$pts->set_variable('test_profile_maintainer_url', 'test_profile_maintainer_url');48$pts>set_variable('_profile_display_format', 'test_profile_display_format');49$pts>set_variable('tet_profile_test_type', 'test_profile_test_type');50$pts->set_variable('test_profile_rn_tmes', 'st_profile_run_times');51pts->set_arible('test_profile_un_mode', 'test_profile_run_mode');52$pts->set_variable('test_profile_identifier','test_profile_identifier');53$pts->set_variable('test_profile_arguments', 'test_profile_arguments');54$pts->set_variable('test_profile_supported_platforms', 'test_profile_supported_platforms');55$pts->set_variable('test_profile_supported_architectures', 'test_profile_supported_architectures');56$pts->set_variable('test_profile_supported_operating_systems', 'test_profile_supported_operating_systems');57$pts->set_variable('test_profile_supported_devices', 'test_profile_supported_devices');58$pts->set_variable('test_profile_pre_install', 'test_profile_pre_install');59$pts->set_variable('test_profile_post_install', 'test_profile_post_install');60$pts->set_variable('test_profile_pre_run', 'test_profile_pre_run');61$pts->set_variable('test_profile_post_run', 'test_profile_post_run');62$pts->set_variable('test_profile_install', 'test_profile_install');63$pts->set_variable('test_profile_pre_install', 'test_profile_pre_install');64$pts->set_variable('test_profile_post_install', 'test_profile_post_install');65$pts->set_variable('test_profile_pre_run', 'test_profile_pre_run');66$pts->set_variable('test_profile_post_run', 'test_profile_post_run');67$pts->set_variable('test_profile_installvariables
Using AI Code Generation
1$var = new pts_test_run_request();2$var->test_profile->set_test_installation_request('install');3$var->test_profile->set_test_installation_request('reinstall');4$var->test_profile->set_test_installation_request('uninstall');5$var->test_profile->set_test_installation_request('skip');6$var->test_profile->set_test_installation_request('force-install');7$var->test_profile->set_test_installation_request('force-reinstall');8$var->test_profile->set_test_installation_request('force-uninstall');9$var->test_profile->set_test_installation_request('force-skip');10$var->test_profile->set_test_installation_request('force-install');11$var->test_profile->set_test_installation_request('force-reinstall');12$var->test_profile->set_test_installation_request('force-uninstall');13$var->test_profile->set_test_installation_request('force-skip');14$var->test_profile->set_test_installation_request('force-install');15$var->test_profile->set_test_installation_request('force-reinstall');16$var->test_profile->set_test_installation_request('force-uninstall');17$var->test_profile->set_test_installation_request('force-skip');18$var->test_profile->set_test_installation_request('force-install');19$var->test_profile->set_test_installation_request('force-reinstall');20$var->test_profile->set_test_installation_request('force-uninstall');21$var->test_profile->set_test_installation_request('force-skip');22$var->test_profile->set_test_installation_request('force-install');23$var->test_profile->set_test_installation_request('force-reinstall');24$var->test_profile->set_test_installation_request('force-uninstall');25$var->test_profile->set_test_installation_request('force-skip');26$var->test_profile->set_test_installation_request('force-install');27$var->test_profile->set_test_installation_request('force-reinstall');28$var->test_profile->set_test_installation_request('force-uninstall');29$var->test_profile->set_test_installation_request('force-skip');30$var->test_profile->set_test_installation_request('force-install');31$var->test_profile->set_test_installation_request('force-reinstall');32$var->test_profile->set_test_installation_request('force-uninstall');variables
Using AI Code Generation
1$var = new pts_test_run_manager();2$var->test_profile->set_result_proportion('PASS', 5);3$var->test_profile->set_result_proportion('FAIL', 5);4$var->test_profile->set_result_proportion('SKIP', 5);5$var->test_profile->set_result_proportion('BROKEN', 5);6$var->test_profile->set_result_proportion('NOT_RUN', 5);7$var->test_profile->set_result_proportion('NA', 5);8$var->test_profile->set_result_proportion('UNSTABLE', 5);9$var->test_profile->set_result_proportion('UNTESTED', 5);10$var->test_profile->set_result_proportion('UNKNOWN', 5);11$var->test_profile->set_result_proportion('ERROR', 5);12$var->test_profile->set_result_proportion('OTHER', 5);13$var->test_profile->set_result_proportion('TIMEOUT', 5);14$var->test_profile->set_result_proportion('EXCEPTION', 5);15$var->test_profile->set_result_proportion('CRASH', 5);16$var->test_profile->set_result_proportion('HANG', 5);17$var->test_profile->set_result_proportion('ABORT', 5);18$var->test_profile->set_result_proportion('LEAK', 5);19$var->test_profile->set_result_proportion('CORRUPT', 5);20$var->test_profile->set_result_proportion('INCOMPLETE', 5);21$var->test_profile->set_result_proportion('ALERT', 5);22$var->test_profile->set_result_proportion('SLOW', 5);23$var->test_profile->set_result_proportion('FAST', 5);variables
Using AI Code Generation
1$pts = new pts_client();2$pts->set_result_file_location('result_file.xml');3$pts->set_result_identifier('TestResult');4$pts->set_test_profile('pts/test1');5$pts->set_system_under_test('pts/test1', 'Ubuntu 16.04', 'Intel Core i7-4790', 'Intel HD Graphics 4600', '16GB DDR3-1600', 'Samsung 850 EVO 250GB');6$pts->set_result_proportion('PASS', 100);7$pts->test_install();8$pts->test_run();9$pts->test_results();10$pts->test_uninstall();11$pts->test_save();Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.
Test now for FreeGet 100 minutes of automation test minutes FREE!!
