Skip to content
Snippets Groups Projects
Select Git revision
  • 381b05e5f1fc0e2022bd85cad90645a2a30693cf
  • 11.x default protected
  • 11.2.x protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
  • 10.4.5 protected
  • 11.0.13 protected
41 results

CommentManager.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    form.inc 38.98 KiB
    <?php
    
    /**
     * @file
     * Functions for form and batch generation and processing.
     */
    
    use Drupal\Component\Utility\UrlHelper;
    use Drupal\Core\Render\Element;
    use Drupal\Core\Render\Element\RenderElement;
    use Drupal\Core\Template\Attribute;
    use Drupal\Core\Url;
    use Symfony\Component\HttpFoundation\RedirectResponse;
    
    /**
     * Prepares variables for select element templates.
     *
     * Default template: select.html.twig.
     *
     * It is possible to group options together; to do this, change the format of
     * $options to an associative array in which the keys are group labels, and the
     * values are associative arrays in the normal $options format.
     *
     * @param $variables
     *   An associative array containing:
     *   - element: An associative array containing the properties of the element.
     *     Properties used: #title, #value, #options, #description, #extra,
     *     #multiple, #required, #name, #attributes, #size.
     */
    function template_preprocess_select(&$variables) {
      $element = $variables['element'];
      Element::setAttributes($element, ['id', 'name', 'size']);
      RenderElement::setAttributes($element, ['form-select']);
    
      $variables['attributes'] = $element['#attributes'];
      $variables['options'] = form_select_options($element);
    }
    
    /**
     * Converts an options form element into a structured array for output.
     *
     * This function calls itself recursively to obtain the values for each optgroup
     * within the list of options and when the function encounters an object with
     * an 'options' property inside $element['#options'].
     *
     * @param array $element
     *   An associative array containing the following key-value pairs:
     *   - #multiple: Optional Boolean indicating if the user may select more than
     *     one item.
     *   - #options: An associative array of options to render as HTML. Each array
     *     value can be a string, an array, or an object with an 'option' property:
     *     - A string or integer key whose value is a translated string is
     *       interpreted as a single HTML option element. Do not use placeholders
     *       that sanitize data: doing so will lead to double-escaping. Note that
     *       the key will be visible in the HTML and could be modified by malicious
     *       users, so don't put sensitive information in it.
     *     - A translated string key whose value is an array indicates a group of
     *       options. The translated string is used as the label attribute for the
     *       optgroup. Do not use placeholders to sanitize data: doing so will lead
     *       to double-escaping. The array should contain the options you wish to
     *       group and should follow the syntax of $element['#options'].
     *     - If the function encounters a string or integer key whose value is an
     *       object with an 'option' property, the key is ignored, the contents of
     *       the option property are interpreted as $element['#options'], and the
     *       resulting HTML is added to the output.
     *   - #value: Optional integer, string, or array representing which option(s)
     *     to pre-select when the list is first displayed. The integer or string
     *     must match the key of an option in the '#options' list. If '#multiple' is
     *     TRUE, this can be an array of integers or strings.
     * @param array|null $choices