comparison core/includes/form.inc @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children af1871eacc83
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
233 * Default template: details.html.twig. 233 * Default template: details.html.twig.
234 * 234 *
235 * @param array $variables 235 * @param array $variables
236 * An associative array containing: 236 * An associative array containing:
237 * - element: An associative array containing the properties of the element. 237 * - element: An associative array containing the properties of the element.
238 * Properties used: #attributes, #children, #open, 238 * Properties used: #attributes, #children, #description, #required,
239 * #description, #id, #title, #value, #optional. 239 * #summary_attributes, #title, #value.
240 */ 240 */
241 function template_preprocess_details(&$variables) { 241 function template_preprocess_details(&$variables) {
242 $element = $variables['element']; 242 $element = $variables['element'];
243 $variables['attributes'] = $element['#attributes']; 243 $variables['attributes'] = $element['#attributes'];
244 $variables['summary_attributes'] = new Attribute(); 244 $variables['summary_attributes'] = new Attribute($element['#summary_attributes']);
245 if (!empty($element['#title'])) { 245 if (!empty($element['#title'])) {
246 $variables['summary_attributes']['role'] = 'button'; 246 $variables['summary_attributes']['role'] = 'button';
247 if (!empty($element['#attributes']['id'])) { 247 if (!empty($element['#attributes']['id'])) {
248 $variables['summary_attributes']['aria-controls'] = $element['#attributes']['id']; 248 $variables['summary_attributes']['aria-controls'] = $element['#attributes']['id'];
249 } 249 }
250 $variables['summary_attributes']['aria-expanded'] = !empty($element['#attributes']['open']) ? 'true' : 'false'; 250 $variables['summary_attributes']['aria-expanded'] = !empty($element['#attributes']['open']) ? 'true' : 'false';
251 $variables['summary_attributes']['aria-pressed'] = $variables['summary_attributes']['aria-expanded']; 251 $variables['summary_attributes']['aria-pressed'] = $variables['summary_attributes']['aria-expanded'];
252 } 252 }
253 $variables['title'] = (!empty($element['#title'])) ? $element['#title'] : ''; 253 $variables['title'] = (!empty($element['#title'])) ? $element['#title'] : '';
254 // If the element title is a string, wrap it a render array so that markup
255 // will not be escaped (but XSS-filtered).
256 if (is_string($variables['title']) && $variables['title'] !== '') {
257 $variables['title'] = ['#markup' => $variables['title']];
258 }
254 $variables['description'] = (!empty($element['#description'])) ? $element['#description'] : ''; 259 $variables['description'] = (!empty($element['#description'])) ? $element['#description'] : '';
255 $variables['children'] = (isset($element['#children'])) ? $element['#children'] : ''; 260 $variables['children'] = (isset($element['#children'])) ? $element['#children'] : '';
256 $variables['value'] = (isset($element['#value'])) ? $element['#value'] : ''; 261 $variables['value'] = (isset($element['#value'])) ? $element['#value'] : '';
257 $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL; 262 $variables['required'] = !empty($element['#required']) ? $element['#required'] : NULL;
258 263
637 * $message = \Drupal::translation()->formatPlural(count($results), 'One post processed.', '@count posts processed.'); 642 * $message = \Drupal::translation()->formatPlural(count($results), 'One post processed.', '@count posts processed.');
638 * } 643 * }
639 * else { 644 * else {
640 * $message = t('Finished with an error.'); 645 * $message = t('Finished with an error.');
641 * } 646 * }
642 * drupal_set_message($message); 647 * \Drupal::messenger()->addMessage($message);
643 * // Providing data for the redirected page is done through $_SESSION. 648 * // Providing data for the redirected page is done through $_SESSION.
644 * foreach ($results as $result) { 649 * foreach ($results as $result) {
645 * $items[] = t('Loaded node %title.', array('%title' => $result)); 650 * $items[] = t('Loaded node %title.', array('%title' => $result));
646 * } 651 * }
647 * $_SESSION['my_batch_results'] = $items; 652 * $_SESSION['my_batch_results'] = $items;
772 * 777 *
773 * This function is generally not needed in form submit handlers; 778 * This function is generally not needed in form submit handlers;
774 * Form API takes care of batches that were set during form submission. 779 * Form API takes care of batches that were set during form submission.
775 * 780 *
776 * @param \Drupal\Core\Url|string $redirect 781 * @param \Drupal\Core\Url|string $redirect
777 * (optional) Either path or Url object to redirect to when the batch has 782 * (optional) Either a path or Url object to redirect to when the batch has
778 * finished processing. Note that to simply force a batch to (conditionally) 783 * finished processing. For example, to redirect users to the home page, use
779 * redirect to a custom location after it is finished processing but to 784 * '<front>'. If you wish to allow standard form API batch handling to occur
780 * otherwise allow the standard form API batch handling to occur, it is not 785 * and force the user to be redirected to a custom location after the batch
781 * necessary to call batch_process() and use this parameter. Instead, make 786 * has finished processing, you do not need to use batch_process() and this
782 * the batch 'finished' callback return an instance of 787 * parameter. Instead, make the batch 'finished' callback return an instance
783 * \Symfony\Component\HttpFoundation\RedirectResponse, which will be used 788 * of \Symfony\Component\HttpFoundation\RedirectResponse, which will be used
784 * automatically by the standard batch processing pipeline (and which takes 789 * automatically by the standard batch processing pipeline (and which takes
785 * precedence over this parameter). 790 * precedence over this parameter). If this parameter is omitted and no
786 * User will be redirected to the page that started the batch if this argument 791 * redirect response was returned by the 'finished' callback, the user will
787 * is omitted and no redirect response was returned by the 'finished' 792 * be redirected to the page that started the batch. Any query arguments will
788 * callback. Any query arguments will be automatically persisted. 793 * be automatically persisted.
789 * @param \Drupal\Core\Url $url 794 * @param \Drupal\Core\Url $url
790 * (optional) URL of the batch processing page. Should only be used for 795 * (optional) URL of the batch processing page. Should only be used for
791 * separate scripts like update.php. 796 * separate scripts like update.php.
792 * @param $redirect_callback 797 * @param $redirect_callback
793 * (optional) Specify a function to be called to redirect to the progressive 798 * (optional) Specify a function to be called to redirect to the progressive