2005-10-07 06:11:12 +00:00
|
|
|
<?php
|
2005-11-01 09:58:01 +00:00
|
|
|
|
2012-02-19 03:41:24 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Functions for form and batch generation and processing.
|
|
|
|
*/
|
|
|
|
|
2012-12-17 21:54:13 +00:00
|
|
|
use Drupal\Component\Utility\NestedArray;
|
Issue #1825952 by Fabianx, joelpittet, bdragon, heddn, chx, xjm, pwolanin, mikey_p, ti2m, bfr, dags, cilefen, scor, mgifford: Turn on twig autoescape by default
2014-07-18 09:05:22 +00:00
|
|
|
use Drupal\Component\Utility\SafeMarkup;
|
2013-10-07 05:34:09 +00:00
|
|
|
use Drupal\Component\Utility\String;
|
2014-03-05 20:22:39 +00:00
|
|
|
use Drupal\Component\Utility\UrlHelper;
|
Issue #2152209 by longwave, joelpittet, steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_fieldset() to Twig.
2014-03-07 22:26:17 +00:00
|
|
|
use Drupal\Component\Utility\Xss;
|
2013-01-15 15:35:31 +00:00
|
|
|
use Drupal\Core\Database\Database;
|
2014-07-31 00:50:42 +00:00
|
|
|
use Drupal\Core\Form\FormStateInterface;
|
2014-05-05 23:07:47 +00:00
|
|
|
use Drupal\Core\Form\OptGroup;
|
2014-03-31 17:37:55 +00:00
|
|
|
use Drupal\Core\Render\Element;
|
2012-09-04 13:32:47 +00:00
|
|
|
use Drupal\Core\Template\Attribute;
|
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
2012-07-07 20:21:18 +00:00
|
|
|
|
2007-07-29 17:28:23 +00:00
|
|
|
/**
|
2012-02-19 03:41:24 +00:00
|
|
|
* Fetches a form from the cache.
|
2013-10-25 22:54:34 +00:00
|
|
|
*
|
2014-02-20 13:49:37 +00:00
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
|
|
|
* Use \Drupal::formBuilder()->getCache().
|
|
|
|
*
|
2014-08-28 21:38:22 +00:00
|
|
|
* @see \Drupal\Core\Form\FormCacheInterface::getCache().
|
2007-07-29 17:28:23 +00:00
|
|
|
*/
|
2014-07-31 00:50:42 +00:00
|
|
|
function form_get_cache($form_build_id, FormStateInterface $form_state) {
|
2013-10-25 22:54:34 +00:00
|
|
|
return \Drupal::formBuilder()->getCache($form_build_id, $form_state);
|
2007-07-29 17:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-19 03:41:24 +00:00
|
|
|
* Stores a form in the cache.
|
2013-10-25 22:54:34 +00:00
|
|
|
*
|
2014-02-20 13:49:37 +00:00
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
|
|
|
* Use \Drupal::formBuilder()->setCache().
|
|
|
|
*
|
2014-08-28 21:38:22 +00:00
|
|
|
* @see \Drupal\Core\Form\FormCacheInterface::setCache().
|
2007-07-29 17:28:23 +00:00
|
|
|
*/
|
2014-08-04 11:21:15 +00:00
|
|
|
function form_set_cache($form_build_id, $form, FormStateInterface $form_state) {
|
2013-10-25 22:54:34 +00:00
|
|
|
\Drupal::formBuilder()->setCache($form_build_id, $form, $form_state);
|
2009-12-05 14:33:55 +00:00
|
|
|
}
|
|
|
|
|
2006-08-31 14:59:28 +00:00
|
|
|
/**
|
2010-03-04 09:07:27 +00:00
|
|
|
* Retrieves, populates, and processes a form.
|
|
|
|
*
|
2014-02-20 13:49:37 +00:00
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
|
|
|
* Use \Drupal::formBuilder()->submitForm().
|
|
|
|
*
|
|
|
|
* @see \Drupal\Core\Form\FormBuilderInterface::submitForm().
|
2006-08-31 14:59:28 +00:00
|
|
|
*/
|
2014-07-31 00:50:42 +00:00
|
|
|
function drupal_form_submit($form_arg, FormStateInterface $form_state) {
|
2013-10-25 22:54:34 +00:00
|
|
|
\Drupal::formBuilder()->submitForm($form_arg, $form_state);
|
2006-08-31 14:59:28 +00:00
|
|
|
}
|
|
|
|
|
2006-08-18 18:58:47 +00:00
|
|
|
/**
|
2009-09-21 06:44:14 +00:00
|
|
|
* Processes a form submission.
|
|
|
|
*
|
2014-02-20 13:49:37 +00:00
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
|
|
|
* Use \Drupal::formBuilder()->processForm().
|
|
|
|
*
|
|
|
|
* @see \Drupal\Core\Form\FormBuilderInterface::processForm().
|
2005-10-07 06:11:12 +00:00
|
|
|
*/
|
2014-07-31 00:50:42 +00:00
|
|
|
function drupal_process_form($form_id, &$form, FormStateInterface $form_state) {
|
2013-10-25 22:54:34 +00:00
|
|
|
\Drupal::formBuilder()->processForm($form_id, $form, $form_state);
|
2006-07-22 19:26:58 +00:00
|
|
|
}
|
|
|
|
|
2007-05-14 13:43:38 +00:00
|
|
|
/**
|
2012-02-19 03:41:24 +00:00
|
|
|
* Executes custom validation and submission handlers for a given form.
|
|
|
|
*
|
2014-02-20 13:49:37 +00:00
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
2014-05-14 20:18:01 +00:00
|
|
|
* Use either \Drupal::service('form_submitter')->executeSubmitHandlers() or
|
2014-05-05 23:07:47 +00:00
|
|
|
* \Drupal::service('form_validator')->executeValidateHandlers().
|
2014-02-20 13:49:37 +00:00
|
|
|
*
|
2014-05-14 20:18:01 +00:00
|
|
|
* @see \Drupal\Core\Form\FormSubmitterInterface::executeSubmitHandlers()
|
2014-05-05 23:07:47 +00:00
|
|
|
* @see \Drupal\Core\Form\FormValidatorInterface::executeValidateHandlers()
|
2007-05-14 13:43:38 +00:00
|
|
|
*/
|
2014-07-31 00:50:42 +00:00
|
|
|
function form_execute_handlers($type, &$form, FormStateInterface $form_state) {
|
2014-05-05 23:07:47 +00:00
|
|
|
if ($type == 'submit') {
|
2014-05-14 20:18:01 +00:00
|
|
|
\Drupal::service('form_submitter')->executeSubmitHandlers($form, $form_state);
|
2014-05-05 23:07:47 +00:00
|
|
|
}
|
|
|
|
elseif ($type == 'validate') {
|
|
|
|
\Drupal::service('form_validator')->executeValidateHandlers($form, $form_state);
|
|
|
|
}
|
2007-05-14 13:43:38 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 06:11:12 +00:00
|
|
|
/**
|
2012-02-19 03:41:24 +00:00
|
|
|
* Flags an element as having an error.
|
2013-10-25 22:54:34 +00:00
|
|
|
*
|
2014-02-20 13:49:37 +00:00
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
2014-08-04 10:19:36 +00:00
|
|
|
* Use $form_state->setError().
|
2014-02-20 13:49:37 +00:00
|
|
|
*
|
2014-08-04 10:19:36 +00:00
|
|
|
* @see \Drupal\Core\Form\FormStateInterface::setError().
|
2005-10-07 06:11:12 +00:00
|
|
|
*/
|
2014-07-31 00:50:42 +00:00
|
|
|
function form_error(&$element, FormStateInterface $form_state, $message = '') {
|
2014-08-04 10:19:36 +00:00
|
|
|
$form_state->setError($element, $message);
|
2005-10-07 06:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-19 03:41:24 +00:00
|
|
|
* Builds and processes all elements in the structured form array.
|
|
|
|
*
|
2014-02-20 13:49:37 +00:00
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
|
|
|
* Use \Drupal::formBuilder()->doBuildForm().
|
|
|
|
*
|
|
|
|
* @see \Drupal\Core\Form\FormBuilderInterface::doBuildForm().
|
2005-10-07 06:11:12 +00:00
|
|
|
*/
|
2014-07-31 00:50:42 +00:00
|
|
|
function form_builder($form_id, &$element, FormStateInterface $form_state) {
|
2013-10-25 22:54:34 +00:00
|
|
|
return \Drupal::formBuilder()->doBuildForm($form_id, $element, $form_state);
|
2007-07-29 17:28:23 +00:00
|
|
|
}
|
|
|
|
|
2009-10-15 11:47:25 +00:00
|
|
|
/**
|
|
|
|
* Removes internal Form API elements and buttons from submitted form values.
|
|
|
|
*
|
|
|
|
* This function can be used when a module wants to store all submitted form
|
|
|
|
* values, for example, by serializing them into a single database column. In
|
|
|
|
* such cases, all internal Form API values and all form button elements should
|
|
|
|
* not be contained, and this function allows to remove them before the module
|
|
|
|
* proceeds to storage. Next to button elements, the following internal values
|
|
|
|
* are removed:
|
|
|
|
* - form_id
|
|
|
|
* - form_token
|
|
|
|
* - form_build_id
|
|
|
|
* - op
|
|
|
|
*
|
2011-05-08 19:50:38 +00:00
|
|
|
* @param $form_state
|
2014-07-31 00:50:42 +00:00
|
|
|
* The current state of the form, including submitted form values.
|
2009-10-15 11:47:25 +00:00
|
|
|
*/
|
2014-07-31 00:50:42 +00:00
|
|
|
function form_state_values_clean(FormStateInterface $form_state) {
|
2009-10-15 11:47:25 +00:00
|
|
|
// Remove internal Form API values.
|
2014-08-08 16:25:54 +00:00
|
|
|
$form_state
|
|
|
|
->unsetValue('form_id')
|
|
|
|
->unsetValue('form_token')
|
|
|
|
->unsetValue('form_build_id')
|
|
|
|
->unsetValue('op');
|
2009-10-15 11:47:25 +00:00
|
|
|
|
|
|
|
// Remove button values.
|
2010-03-26 18:58:12 +00:00
|
|
|
// form_builder() collects all button elements in a form. We remove the button
|
|
|
|
// value separately for each button element.
|
|
|
|
foreach ($form_state['buttons'] as $button) {
|
|
|
|
// Remove this button's value from the submitted form values by finding
|
|
|
|
// the value corresponding to this button.
|
|
|
|
// We iterate over the #parents of this button and move a reference to
|
2014-08-08 16:25:54 +00:00
|
|
|
// each parent in $form_state->getValues(). For example, if #parents is:
|
2010-03-26 18:58:12 +00:00
|
|
|
// array('foo', 'bar', 'baz')
|
2014-08-08 16:25:54 +00:00
|
|
|
// then the corresponding $form_state->getValues() part will look like this:
|
2010-03-26 18:58:12 +00:00
|
|
|
// array(
|
|
|
|
// 'foo' => array(
|
|
|
|
// 'bar' => array(
|
|
|
|
// 'baz' => 'button_value',
|
|
|
|
// ),
|
|
|
|
// ),
|
|
|
|
// )
|
|
|
|
// We start by (re)moving 'baz' to $last_parent, so we are able unset it
|
|
|
|
// at the end of the iteration. Initially, $values will contain a
|
2014-08-08 16:25:54 +00:00
|
|
|
// reference to $form_state->getValues(), but in the iteration we move the
|
|
|
|
// reference to $form_state->getValue('foo'), and finally to
|
|
|
|
// $form_state->getValue(array('foo', 'bar')), which is the level where we
|
|
|
|
// can unset 'baz' (that is stored in $last_parent).
|
2010-03-26 18:58:12 +00:00
|
|
|
$parents = $button['#parents'];
|
|
|
|
$last_parent = array_pop($parents);
|
2011-11-03 07:32:28 +00:00
|
|
|
$key_exists = NULL;
|
2014-08-08 16:25:54 +00:00
|
|
|
$values = &NestedArray::getValue($form_state->getValues(), $parents, $key_exists);
|
2011-11-03 07:32:28 +00:00
|
|
|
if ($key_exists && is_array($values)) {
|
|
|
|
unset($values[$last_parent]);
|
2009-10-15 11:47:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-04-15 21:52:44 +00:00
|
|
|
/**
|
2012-02-19 03:41:24 +00:00
|
|
|
* Changes submitted form values during form validation.
|
2006-04-15 21:52:44 +00:00
|
|
|
*
|
2014-02-20 13:49:37 +00:00
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
2014-08-04 17:23:18 +00:00
|
|
|
* Use $form_state->setValueForElement().
|
2014-02-20 13:49:37 +00:00
|
|
|
*
|
2014-08-04 17:23:18 +00:00
|
|
|
* @see \Drupal\Core\Form\FormStateInterface::setValueForElement().
|
2006-04-15 21:52:44 +00:00
|
|
|
*/
|
2014-07-31 00:50:42 +00:00
|
|
|
function form_set_value($element, $value, FormStateInterface $form_state) {
|
2014-08-04 17:23:18 +00:00
|
|
|
$form_state->setValueForElement($element, $value);
|
2006-04-15 21:52:44 +00:00
|
|
|
}
|
|
|
|
|
2010-06-26 18:11:27 +00:00
|
|
|
/**
|
|
|
|
* Allows PHP array processing of multiple select options with the same value.
|
|
|
|
*
|
|
|
|
* Used for form select elements which need to validate HTML option groups
|
|
|
|
* and multiple options which may return the same value. Associative PHP arrays
|
|
|
|
* cannot handle these structures, since they share a common key.
|
|
|
|
*
|
|
|
|
* @param $array
|
|
|
|
* The form options array to process.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* An array with all hierarchical elements flattened to a single array.
|
|
|
|
*
|
2014-02-20 13:49:37 +00:00
|
|
|
* @deprecated in Drupal 8.x-dev, will be removed before Drupal 8.0.
|
2014-05-05 23:07:47 +00:00
|
|
|
* Use \Drupal\Core\Form\OptGroup::flattenOptions().
|
2010-06-26 18:11:27 +00:00
|
|
|
*/
|
2013-11-23 05:13:32 +00:00
|
|
|
function form_options_flatten($array) {
|
2014-05-05 23:07:47 +00:00
|
|
|
return OptGroup::flattenOptions($array);
|
2006-01-06 07:15:47 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 06:11:12 +00:00
|
|
|
/**
|
Issue #2152225 by longwave, JeroenT, steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_select() to Twig
2014-03-07 21:51:16 +00:00
|
|
|
* Prepares variables for select element templates.
|
|
|
|
*
|
|
|
|
* Default template: select.html.twig.
|
2010-04-13 15:23:03 +00:00
|
|
|
*
|
|
|
|
* 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.
|
2005-10-07 06:11:12 +00:00
|
|
|
*
|
2009-10-09 01:00:08 +00:00
|
|
|
* @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.
|
2005-10-07 06:11:12 +00:00
|
|
|
*/
|
Issue #2152225 by longwave, JeroenT, steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_select() to Twig
2014-03-07 21:51:16 +00:00
|
|
|
function template_preprocess_select(&$variables) {
|
2009-10-09 01:00:08 +00:00
|
|
|
$element = $variables['element'];
|
2014-03-31 17:37:55 +00:00
|
|
|
Element::setAttributes($element, array('id', 'name', 'size'));
|
2014-08-28 21:35:24 +00:00
|
|
|
Element\RenderElement::setAttributes($element, array('form-select'));
|
2010-09-16 20:14:49 +00:00
|
|
|
|
Issue #2152225 by longwave, JeroenT, steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_select() to Twig
2014-03-07 21:51:16 +00:00
|
|
|
$variables['attributes'] = $element['#attributes'];
|
|
|
|
$variables['options'] = form_select_options($element);
|
2006-01-19 09:22:16 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 08:15:36 +00:00
|
|
|
/**
|
2012-02-19 03:41:24 +00:00
|
|
|
* Converts a select form element's options array into HTML.
|
2009-08-19 08:15:36 +00:00
|
|
|
*
|
|
|
|
* @param $element
|
|
|
|
* An associative array containing the properties of the element.
|
|
|
|
* @param $choices
|
|
|
|
* Mixed: Either an associative array of items to list as choices, or an
|
|
|
|
* object with an 'option' member that is an associative array. This
|
|
|
|
* parameter is only used internally and should not be passed.
|
2012-02-19 03:41:24 +00:00
|
|
|
*
|
2009-08-19 08:15:36 +00:00
|
|
|
* @return
|
|
|
|
* An HTML string of options for the select form element.
|
|
|
|
*/
|
2006-01-19 09:22:16 +00:00
|
|
|
function form_select_options($element, $choices = NULL) {
|
|
|
|
if (!isset($choices)) {
|
2013-02-06 12:03:07 +00:00
|
|
|
if (empty($element['#options'])) {
|
|
|
|
return '';
|
|
|
|
}
|
2006-01-19 09:22:16 +00:00
|
|
|
$choices = $element['#options'];
|
|
|
|
}
|
2006-04-11 11:33:15 +00:00
|
|
|
// array_key_exists() accommodates the rare event where $element['#value'] is NULL.
|
2006-01-13 07:44:59 +00:00
|
|
|
// isset() fails in this situation.
|
|
|
|
$value_valid = isset($element['#value']) || array_key_exists('#value', $element);
|
2010-09-16 20:14:49 +00:00
|
|
|
$value_is_array = $value_valid && is_array($element['#value']);
|
2014-02-14 17:05:59 +00:00
|
|
|
// Check if the element is multiple select and no value has been selected.
|
|
|
|
$empty_value = (empty($element['#value']) && !empty($element['#multiple']));
|
2006-01-19 09:22:16 +00:00
|
|
|
$options = '';
|
|
|
|
foreach ($choices as $key => $choice) {
|
2005-10-07 06:11:12 +00:00
|
|
|
if (is_array($choice)) {
|
2014-07-18 07:51:59 +00:00
|
|
|
$options .= '<optgroup label="' . String::checkPlain($key) . '">';
|
2006-01-19 09:22:16 +00:00
|
|
|
$options .= form_select_options($element, $choice);
|
|
|
|
$options .= '</optgroup>';
|
2005-10-07 06:11:12 +00:00
|
|
|
}
|
2014-06-07 10:24:02 +00:00
|
|
|
elseif (is_object($choice) && isset($choice->option)) {
|
2006-10-20 20:55:03 +00:00
|
|
|
$options .= form_select_options($element, $choice->option);
|
|
|
|
}
|
2005-10-07 06:11:12 +00:00
|
|
|
else {
|
2010-05-06 05:59:31 +00:00
|
|
|
$key = (string) $key;
|
2014-02-14 17:05:59 +00:00
|
|
|
$empty_choice = $empty_value && $key == '_none';
|
|
|
|
if ($value_valid && ((!$value_is_array && (string) $element['#value'] === $key || ($value_is_array && in_array($key, $element['#value']))) || $empty_choice)) {
|
2006-01-06 07:15:47 +00:00
|
|
|
$selected = ' selected="selected"';
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$selected = '';
|
|
|
|
}
|
2013-10-07 05:34:09 +00:00
|
|
|
$options .= '<option value="' . String::checkPlain($key) . '"' . $selected . '>' . String::checkPlain($choice) . '</option>';
|
2005-10-07 06:11:12 +00:00
|
|
|
}
|
|
|
|
}
|
Issue #1825952 by Fabianx, joelpittet, bdragon, heddn, chx, xjm, pwolanin, mikey_p, ti2m, bfr, dags, cilefen, scor, mgifford: Turn on twig autoescape by default
2014-07-18 09:05:22 +00:00
|
|
|
return SafeMarkup::set($options);
|
2005-10-07 06:11:12 +00:00
|
|
|
}
|
|
|
|
|
2006-12-29 00:19:58 +00:00
|
|
|
/**
|
2012-02-19 03:41:24 +00:00
|
|
|
* Returns the indexes of a select element's options matching a given key.
|
2007-01-05 19:08:30 +00:00
|
|
|
*
|
|
|
|
* This function is useful if you need to modify the options that are
|
2007-01-23 19:17:55 +00:00
|
|
|
* already in a form element; for example, to remove choices which are
|
2007-01-05 19:08:30 +00:00
|
|
|
* not valid because of additional filters imposed by another module.
|
|
|
|
* One example might be altering the choices in a taxonomy selector.
|
|
|
|
* To correctly handle the case of a multiple hierarchy taxonomy,
|
|
|
|
* #options arrays can now hold an array of objects, instead of a
|
|
|
|
* direct mapping of keys to labels, so that multiple choices in the
|
|
|
|
* selector can have the same key (and label). This makes it difficult
|
|
|
|
* to manipulate directly, which is why this helper function exists.
|
|
|
|
*
|
|
|
|
* This function does not support optgroups (when the elements of the
|
|
|
|
* #options array are themselves arrays), and will return FALSE if
|
|
|
|
* arrays are found. The caller must either flatten/restore or
|
|
|
|
* manually do their manipulations in this case, since returning the
|
|
|
|
* index is not sufficient, and supporting this would make the
|
|
|
|
* "helper" too complicated and cumbersome to be of any help.
|
|
|
|
*
|
|
|
|
* As usual with functions that can return array() or FALSE, do not
|
|
|
|
* forget to use === and !== if needed.
|
2006-12-29 00:19:58 +00:00
|
|
|
*
|
|
|
|
* @param $element
|
2007-01-05 19:08:30 +00:00
|
|
|
* The select element to search.
|
2006-12-29 00:19:58 +00:00
|
|
|
* @param $key
|
|
|
|
* The key to look for.
|
2012-02-19 03:41:24 +00:00
|
|
|
*
|
2006-12-29 00:19:58 +00:00
|
|
|
* @return
|
2007-01-05 19:08:30 +00:00
|
|
|
* An array of indexes that match the given $key. Array will be
|
|
|
|
* empty if no elements were found. FALSE if optgroups were found.
|
2006-12-29 00:19:58 +00:00
|
|
|
*/
|
2007-01-05 19:08:30 +00:00
|
|
|
function form_get_options($element, $key) {
|
|
|
|
$keys = array();
|
|
|
|
foreach ($element['#options'] as $index => $choice) {
|
|
|
|
if (is_array($choice)) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-10-12 04:30:09 +00:00
|
|
|
elseif (is_object($choice)) {
|
2007-01-05 19:08:30 +00:00
|
|
|
if (isset($choice->option[$key])) {
|
|
|
|
$keys[] = $index;
|
|
|
|
}
|
|
|
|
}
|
2008-10-12 04:30:09 +00:00
|
|
|
elseif ($index == $key) {
|
2007-01-05 19:08:30 +00:00
|
|
|
$keys[] = $index;
|
2006-12-29 00:19:58 +00:00
|
|
|
}
|
|
|
|
}
|
2007-01-05 19:08:30 +00:00
|
|
|
return $keys;
|
2006-12-29 00:19:58 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 06:11:12 +00:00
|
|
|
/**
|
Issue #2152209 by longwave, joelpittet, steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_fieldset() to Twig.
2014-03-07 22:26:17 +00:00
|
|
|
* Prepares variables for fieldset element templates.
|
2005-10-07 06:11:12 +00:00
|
|
|
*
|
Issue #2152209 by longwave, joelpittet, steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_fieldset() to Twig.
2014-03-07 22:26:17 +00:00
|
|
|
* Default template: fieldset.html.twig.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
2009-10-09 01:00:08 +00:00
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties of the element.
|
Issue #2152209 by longwave, joelpittet, steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_fieldset() to Twig.
2014-03-07 22:26:17 +00:00
|
|
|
* Properties used: #attributes, #children, #description, #id, #title,
|
|
|
|
* #value.
|
2005-10-07 06:11:12 +00:00
|
|
|
*/
|
Issue #2152209 by longwave, joelpittet, steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_fieldset() to Twig.
2014-03-07 22:26:17 +00:00
|
|
|
function template_preprocess_fieldset(&$variables) {
|
2009-10-09 01:00:08 +00:00
|
|
|
$element = $variables['element'];
|
2014-03-31 17:37:55 +00:00
|
|
|
Element::setAttributes($element, array('id'));
|
2014-08-28 21:35:24 +00:00
|
|
|
Element\RenderElement::setAttributes($element, array('form-wrapper'));
|
Issue #2152209 by longwave, joelpittet, steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_fieldset() to Twig.
2014-03-07 22:26:17 +00:00
|
|
|
$variables['attributes'] = $element['#attributes'];
|
|
|
|
$variables['attributes']['class'][] = 'form-item';
|
|
|
|
$variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL;
|
|
|
|
$variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL;
|
|
|
|
$variables['children'] = $element['#children'];
|
2013-01-17 20:43:29 +00:00
|
|
|
$legend_attributes = array();
|
|
|
|
if (isset($element['#title_display']) && $element['#title_display'] == 'invisible') {
|
2013-06-17 19:58:27 +00:00
|
|
|
$legend_attributes['class'][] = 'visually-hidden';
|
2013-01-17 20:43:29 +00:00
|
|
|
}
|
Issue #2152209 by longwave, joelpittet, steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_fieldset() to Twig.
2014-03-07 22:26:17 +00:00
|
|
|
$variables['legend']['attributes'] = new Attribute($legend_attributes);
|
|
|
|
$variables['legend']['title'] = (isset($element['#title']) && $element['#title'] !== '') ? Xss::filterAdmin($element['#title']) : '';
|
2014-05-08 13:40:44 +00:00
|
|
|
$legend_span_attributes = array('class' => array('fieldset-legend'));
|
|
|
|
if (!empty($element['#required'])) {
|
|
|
|
$legend_span_attributes['class'][] = 'form-required';
|
|
|
|
$variables['legend_span']['attributes'] = new Attribute($legend_span_attributes);
|
|
|
|
}
|
2014-02-20 11:40:28 +00:00
|
|
|
if (!empty($element['#description'])) {
|
Issue #2152209 by longwave, joelpittet, steveoliver, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_fieldset() to Twig.
2014-03-07 22:26:17 +00:00
|
|
|
$description_id = $element['#attributes']['id'] . '--description';
|
|
|
|
$description_attributes = array(
|
|
|
|
'class' => 'description',
|
|
|
|
'id' => $description_id,
|
|
|
|
);
|
|
|
|
$variables['description']['attributes'] = new Attribute($description_attributes);
|
|
|
|
$variables['description']['content'] = $element['#description'];
|
|
|
|
|
|
|
|
// Add the description's id to the fieldset aria attributes.
|
|
|
|
$variables['attributes']['aria-describedby'] = $description_id;
|
2009-11-16 05:11:01 +00:00
|
|
|
}
|
2005-10-07 06:11:12 +00:00
|
|
|
}
|
|
|
|
|
2012-11-27 07:06:47 +00:00
|
|
|
/**
|
Issue #2152207 by steveoliver, joelpittet, gnuget, idflood, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_details() to Twig
2014-02-07 04:26:52 +00:00
|
|
|
* Prepares variables for details element templates.
|
2012-11-27 07:06:47 +00:00
|
|
|
*
|
Issue #2152207 by steveoliver, joelpittet, gnuget, idflood, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_details() to Twig
2014-02-07 04:26:52 +00:00
|
|
|
* Default template: details.html.twig.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
2012-11-27 07:06:47 +00:00
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties of the element.
|
2014-02-26 18:38:09 +00:00
|
|
|
* Properties used: #attributes, #children, #open,
|
2014-02-21 17:36:27 +00:00
|
|
|
* #description, #id, #title, #value, #optional.
|
2012-11-27 07:06:47 +00:00
|
|
|
*/
|
Issue #2152207 by steveoliver, joelpittet, gnuget, idflood, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_details() to Twig
2014-02-07 04:26:52 +00:00
|
|
|
function template_preprocess_details(&$variables) {
|
2012-11-27 07:06:47 +00:00
|
|
|
$element = $variables['element'];
|
Issue #2152207 by steveoliver, joelpittet, gnuget, idflood, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_details() to Twig
2014-02-07 04:26:52 +00:00
|
|
|
$variables['attributes'] = $element['#attributes'];
|
|
|
|
$variables['summary_attributes'] = new Attribute();
|
2012-11-27 07:06:47 +00:00
|
|
|
if (!empty($element['#title'])) {
|
Issue #2152207 by steveoliver, joelpittet, gnuget, idflood, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_details() to Twig
2014-02-07 04:26:52 +00:00
|
|
|
$variables['summary_attributes']['role'] = 'button';
|
2013-01-03 01:58:48 +00:00
|
|
|
if (!empty($element['#attributes']['id'])) {
|
Issue #2152207 by steveoliver, joelpittet, gnuget, idflood, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_details() to Twig
2014-02-07 04:26:52 +00:00
|
|
|
$variables['summary_attributes']['aria-controls'] = $element['#attributes']['id'];
|
2013-01-03 01:58:48 +00:00
|
|
|
}
|
2014-02-26 18:38:09 +00:00
|
|
|
$variables['summary_attributes']['aria-expanded'] = !empty($element['#attributes']['open']);
|
Issue #2152207 by steveoliver, joelpittet, gnuget, idflood, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_details() to Twig
2014-02-07 04:26:52 +00:00
|
|
|
$variables['summary_attributes']['aria-pressed'] = $variables['summary_attributes']['aria-expanded'];
|
2012-11-27 07:06:47 +00:00
|
|
|
}
|
Issue #2152207 by steveoliver, joelpittet, gnuget, idflood, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_details() to Twig
2014-02-07 04:26:52 +00:00
|
|
|
$variables['title'] = (!empty($element['#title'])) ? $element['#title'] : '';
|
|
|
|
$variables['description'] = (!empty($element['#description'])) ? $element['#description'] : '';
|
|
|
|
$variables['children'] = (isset($element['#children'])) ? $element['#children'] : '';
|
|
|
|
$variables['value'] = (isset($element['#value'])) ? $element['#value'] : '';
|
2012-11-27 07:06:47 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 06:11:12 +00:00
|
|
|
/**
|
Issue #2152221 by IshaDakota, steveoliver, joelpittet, InternetDevels, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_radios() to Twig
2014-03-25 20:38:11 +00:00
|
|
|
* Prepares variables for radios templates.
|
2005-10-07 06:11:12 +00:00
|
|
|
*
|
Issue #2152221 by IshaDakota, steveoliver, joelpittet, InternetDevels, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_radios() to Twig
2014-03-25 20:38:11 +00:00
|
|
|
* Default template: radios.html.twig.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
2009-10-09 01:00:08 +00:00
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties of the element.
|
|
|
|
* Properties used: #title, #value, #options, #description, #required,
|
|
|
|
* #attributes, #children.
|
2005-10-07 06:11:12 +00:00
|
|
|
*/
|
Issue #2152221 by IshaDakota, steveoliver, joelpittet, InternetDevels, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_radios() to Twig
2014-03-25 20:38:11 +00:00
|
|
|
function template_preprocess_radios(&$variables) {
|
2009-10-09 01:00:08 +00:00
|
|
|
$element = $variables['element'];
|
Issue #2152221 by IshaDakota, steveoliver, joelpittet, InternetDevels, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_radios() to Twig
2014-03-25 20:38:11 +00:00
|
|
|
$variables['attributes'] = array();
|
2010-09-16 20:14:49 +00:00
|
|
|
if (isset($element['#id'])) {
|
Issue #2152221 by IshaDakota, steveoliver, joelpittet, InternetDevels, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_radios() to Twig
2014-03-25 20:38:11 +00:00
|
|
|
$variables['attributes']['id'] = $element['#id'];
|
2010-03-26 12:16:18 +00:00
|
|
|
}
|
Issue #2152221 by IshaDakota, steveoliver, joelpittet, InternetDevels, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_radios() to Twig
2014-03-25 20:38:11 +00:00
|
|
|
$variables['attributes']['class'][] = 'form-radios';
|
2009-08-22 14:34:23 +00:00
|
|
|
if (!empty($element['#attributes']['class'])) {
|
Issue #2152221 by IshaDakota, steveoliver, joelpittet, InternetDevels, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_radios() to Twig
2014-03-25 20:38:11 +00:00
|
|
|
$variables['attributes']['class'] = array_merge($variables['attributes']['class'], $element['#attributes']['class']);
|
2006-12-12 10:01:38 +00:00
|
|
|
}
|
2012-04-12 07:29:31 +00:00
|
|
|
if (isset($element['#attributes']['title'])) {
|
Issue #2152221 by IshaDakota, steveoliver, joelpittet, InternetDevels, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_radios() to Twig
2014-03-25 20:38:11 +00:00
|
|
|
$variables['attributes']['title'] = $element['#attributes']['title'];
|
2012-04-12 07:29:31 +00:00
|
|
|
}
|
Issue #2152221 by IshaDakota, steveoliver, joelpittet, InternetDevels, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_radios() to Twig
2014-03-25 20:38:11 +00:00
|
|
|
$variables['children'] = $element['#children'];
|
2006-01-02 08:35:59 +00:00
|
|
|
}
|
|
|
|
|
2005-10-07 06:11:12 +00:00
|
|
|
/**
|
Issue #2152201 by Salah Messaoud, Manuel Garcia, steveoliver, joelpittet, burgerboydaddy, katy5289, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_checkboxes() to Twig
2014-04-16 03:52:59 +00:00
|
|
|
* Prepares variables for checkboxes templates.
|
2005-10-07 06:11:12 +00:00
|
|
|
*
|
Issue #2152201 by Salah Messaoud, Manuel Garcia, steveoliver, joelpittet, burgerboydaddy, katy5289, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_checkboxes() to Twig
2014-04-16 03:52:59 +00:00
|
|
|
* Default template: checkboxes.html.twig.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
2009-10-09 01:00:08 +00:00
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties of the element.
|
|
|
|
* Properties used: #children, #attributes.
|
2005-10-07 06:11:12 +00:00
|
|
|
*/
|
Issue #2152201 by Salah Messaoud, Manuel Garcia, steveoliver, joelpittet, burgerboydaddy, katy5289, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_checkboxes() to Twig
2014-04-16 03:52:59 +00:00
|
|
|
function template_preprocess_checkboxes(&$variables) {
|
2009-10-09 01:00:08 +00:00
|
|
|
$element = $variables['element'];
|
Issue #2152201 by Salah Messaoud, Manuel Garcia, steveoliver, joelpittet, burgerboydaddy, katy5289, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_checkboxes() to Twig
2014-04-16 03:52:59 +00:00
|
|
|
$variables['attributes'] = array();
|
2010-09-16 20:14:49 +00:00
|
|
|
if (isset($element['#id'])) {
|
Issue #2152201 by Salah Messaoud, Manuel Garcia, steveoliver, joelpittet, burgerboydaddy, katy5289, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_checkboxes() to Twig
2014-04-16 03:52:59 +00:00
|
|
|
$variables['attributes']['id'] = $element['#id'];
|
2010-03-26 12:16:18 +00:00
|
|
|
}
|
Issue #2152201 by Salah Messaoud, Manuel Garcia, steveoliver, joelpittet, burgerboydaddy, katy5289, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_checkboxes() to Twig
2014-04-16 03:52:59 +00:00
|
|
|
$variables['attributes']['class'] = array();
|
|
|
|
$variables['attributes']['class'][] = 'form-checkboxes';
|
2009-08-22 14:34:23 +00:00
|
|
|
if (!empty($element['#attributes']['class'])) {
|
Issue #2152201 by Salah Messaoud, Manuel Garcia, steveoliver, joelpittet, burgerboydaddy, katy5289, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_checkboxes() to Twig
2014-04-16 03:52:59 +00:00
|
|
|
$variables['attributes']['class'] = array_merge($variables['attributes']['class'], $element['#attributes']['class']);
|
2006-12-12 10:01:38 +00:00
|
|
|
}
|
2012-04-12 07:29:31 +00:00
|
|
|
if (isset($element['#attributes']['title'])) {
|
Issue #2152201 by Salah Messaoud, Manuel Garcia, steveoliver, joelpittet, burgerboydaddy, katy5289, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_checkboxes() to Twig
2014-04-16 03:52:59 +00:00
|
|
|
$variables['attributes']['title'] = $element['#attributes']['title'];
|
2012-04-12 07:29:31 +00:00
|
|
|
}
|
Issue #2152201 by Salah Messaoud, Manuel Garcia, steveoliver, joelpittet, burgerboydaddy, katy5289, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_checkboxes() to Twig
2014-04-16 03:52:59 +00:00
|
|
|
$variables['children'] = $element['#children'];
|
2009-02-03 18:55:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-28 21:35:24 +00:00
|
|
|
* Prepares variables for vertical tabs templates.
|
|
|
|
*
|
|
|
|
* Default template: vertical-tabs.html.twig.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties and children of
|
|
|
|
* the details element. Properties used: #children.
|
2009-02-03 18:55:32 +00:00
|
|
|
*
|
|
|
|
*/
|
2014-08-28 21:35:24 +00:00
|
|
|
function template_preprocess_vertical_tabs(&$variables) {
|
|
|
|
$element = $variables['element'];
|
|
|
|
$variables['children'] = (!empty($element['#children'])) ? $element['#children'] : '';
|
2005-10-07 06:11:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-27 06:23:35 +00:00
|
|
|
/**
|
2014-08-28 21:35:24 +00:00
|
|
|
* Prepares variables for input templates.
|
|
|
|
*
|
|
|
|
* Default template: input.html.twig.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties of the element.
|
|
|
|
* Properties used: #attributes.
|
2012-03-27 06:23:35 +00:00
|
|
|
*/
|
2014-08-28 21:35:24 +00:00
|
|
|
function template_preprocess_input(&$variables) {
|
|
|
|
$element = $variables['element'];
|
|
|
|
$variables['children'] = $element['#children'];
|
2012-03-27 06:23:35 +00:00
|
|
|
}
|
|
|
|
|
2010-10-28 02:20:14 +00:00
|
|
|
/**
|
2014-08-28 21:35:24 +00:00
|
|
|
* Prepares variables for form templates.
|
|
|
|
*
|
|
|
|
* Default template: form.html.twig.
|
|
|
|
*
|
|
|
|
* @param $variables
|
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties of the element.
|
|
|
|
* Properties used: #action, #method, #attributes, #children
|
2010-10-28 02:20:14 +00:00
|
|
|
*/
|
2014-08-28 21:35:24 +00:00
|
|
|
function template_preprocess_form(&$variables) {
|
|
|
|
$element = $variables['element'];
|
|
|
|
if (isset($element['#action'])) {
|
|
|
|
$element['#attributes']['action'] = UrlHelper::stripDangerousProtocols($element['#action']);
|
2010-10-28 02:20:14 +00:00
|
|
|
}
|
2014-08-28 21:35:24 +00:00
|
|
|
Element::setAttributes($element, array('method', 'id'));
|
|
|
|
if (empty($element['#attributes']['accept-charset'])) {
|
|
|
|
$element['#attributes']['accept-charset'] = "UTF-8";
|
2010-10-28 02:20:14 +00:00
|
|
|
}
|
2014-08-28 21:35:24 +00:00
|
|
|
$variables['attributes'] = $element['#attributes'];
|
|
|
|
$variables['children'] = $element['#children'];
|
2010-10-28 02:20:14 +00:00
|
|
|
}
|
|
|
|
|
2012-02-19 03:41:24 +00:00
|
|
|
/**
|
2014-08-28 21:35:24 +00:00
|
|
|
* Prepares variables for textarea templates.
|
|
|
|
*
|
|
|
|
* Default template: textarea.html.twig.
|
|
|
|
*
|
|
|
|
* @param array $variables
|
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties of the element.
|
|
|
|
* Properties used: #title, #value, #description, #rows, #cols,
|
|
|
|
* #placeholder, #required, #attributes, #resizable
|
|
|
|
*
|
2012-02-19 03:41:24 +00:00
|
|
|
*/
|
2014-08-28 21:35:24 +00:00
|
|
|
function template_preprocess_textarea(&$variables) {
|
|
|
|
$element = $variables['element'];
|
|
|
|
Element::setAttributes($element, array('id', 'name', 'rows', 'cols', 'placeholder'));
|
|
|
|
Element\RenderElement::setAttributes($element, array('form-textarea'));
|
|
|
|
$variables['wrapper_attributes'] = new Attribute(array(
|
|
|
|
'class' => array('form-textarea-wrapper'),
|
|
|
|
));
|
2010-11-07 21:46:09 +00:00
|
|
|
|
2014-08-28 21:35:24 +00:00
|
|
|
// Add resizable behavior.
|
|
|
|
if (!empty($element['#resizable'])) {
|
|
|
|
$element['#attributes']['class'][] = 'resize-' . $element['#resizable'];
|
2005-12-29 03:59:30 +00:00
|
|
|
}
|
|
|
|
|
Issue #2152229 by steveoliver, rteijeiro, joelpittet, JeroenT, InternetDevels, michamilz, burgerboydaddy, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_textarea() to Twig
2014-02-04 17:28:23 +00:00
|
|
|
$variables['attributes'] = new Attribute($element['#attributes']);
|
|
|
|
|
|
|
|
$variables['value'] = String::checkPlain($element['#value']);
|
2005-10-07 06:11:12 +00:00
|
|
|
}
|
|
|
|
|
2006-05-02 09:26:33 +00:00
|
|
|
/**
|
2010-04-13 15:23:03 +00:00
|
|
|
* Returns HTML for a form element.
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
* Prepares variables for form element templates.
|
|
|
|
*
|
|
|
|
* Default template: form-element.html.twig.
|
2006-05-02 09:26:33 +00:00
|
|
|
*
|
2010-07-31 04:01:51 +00:00
|
|
|
* Each form element is wrapped in a DIV container having the following CSS
|
|
|
|
* classes:
|
|
|
|
* - form-item: Generic for all form elements.
|
|
|
|
* - form-type-#type: The internal element #type.
|
|
|
|
* - form-item-#name: The internal form element #name (usually derived from the
|
|
|
|
* $form structure and set via form_builder()).
|
|
|
|
* - form-disabled: Only set if the form element is #disabled.
|
|
|
|
*
|
|
|
|
* In addition to the element itself, the DIV contains a label for the element
|
|
|
|
* based on the optional #title_display property, and an optional #description.
|
2009-12-02 15:09:16 +00:00
|
|
|
*
|
|
|
|
* The optional #title_display property can have these values:
|
|
|
|
* - before: The label is output before the element. This is the default.
|
|
|
|
* The label includes the #title and the required marker, if #required.
|
|
|
|
* - after: The label is output after the element. For example, this is used
|
2014-09-10 21:56:14 +00:00
|
|
|
* for radio and checkbox #type elements. If the #title is empty but the field
|
|
|
|
* is #required, the label will contain only the required marker.
|
2010-04-07 04:39:59 +00:00
|
|
|
* - invisible: Labels are critical for screen readers to enable them to
|
|
|
|
* properly navigate through forms but can be visually distracting. This
|
|
|
|
* property hides the label for everyone except screen readers.
|
2009-12-02 15:09:16 +00:00
|
|
|
* - attribute: Set the title attribute on the element to create a tooltip
|
|
|
|
* but output no label element. This is supported only for checkboxes
|
2014-08-28 21:35:24 +00:00
|
|
|
* and radios in
|
|
|
|
* \Drupal\Core\Render\Element\CompositeFormElementTrait::preRenderCompositeFormElement().
|
|
|
|
* It is used where a visual label is not needed, such as a table of
|
|
|
|
* checkboxes where the row and column provide the context. The tooltip will
|
|
|
|
* include the title and required marker.
|
2009-12-02 15:09:16 +00:00
|
|
|
*
|
|
|
|
* If the #title property is not set, then the label and any required marker
|
|
|
|
* will not be output, regardless of the #title_display or #required values.
|
|
|
|
* This can be useful in cases such as the password_confirm element, which
|
|
|
|
* creates children elements that have their own labels and required markers,
|
|
|
|
* but the parent element should have neither. Use this carefully because a
|
|
|
|
* field without an associated label can cause accessibility challenges.
|
|
|
|
*
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
* @param array $variables
|
2009-10-09 01:00:08 +00:00
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties of the element.
|
2009-12-02 15:09:16 +00:00
|
|
|
* Properties used: #title, #title_display, #description, #id, #required,
|
|
|
|
* #children, #type, #name.
|
2006-05-02 09:26:33 +00:00
|
|
|
*/
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
function template_preprocess_form_element(&$variables) {
|
2010-09-16 20:14:49 +00:00
|
|
|
$element = &$variables['element'];
|
2007-11-13 14:04:08 +00:00
|
|
|
|
2010-09-16 20:14:49 +00:00
|
|
|
// This function is invoked as theme wrapper, but the rendered form element
|
|
|
|
// may not necessarily have been processed by form_builder().
|
|
|
|
$element += array(
|
|
|
|
'#title_display' => 'before',
|
|
|
|
);
|
|
|
|
|
2013-01-17 20:43:29 +00:00
|
|
|
// Take over any #wrapper_attributes defined by the element.
|
|
|
|
// @todo Temporary hack for #type 'item'.
|
|
|
|
// @see http://drupal.org/node/1829202
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['attributes'] = array();
|
2013-01-17 20:43:29 +00:00
|
|
|
if (isset($element['#wrapper_attributes'])) {
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['attributes'] = $element['#wrapper_attributes'];
|
2013-01-17 20:43:29 +00:00
|
|
|
}
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
|
2010-05-01 00:19:35 +00:00
|
|
|
// Add element #id for #type 'item'.
|
|
|
|
if (isset($element['#markup']) && !empty($element['#id'])) {
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['attributes']['id'] = $element['#id'];
|
2010-05-01 00:19:35 +00:00
|
|
|
}
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
|
2009-06-14 08:04:25 +00:00
|
|
|
// Add element's #type and #name as class to aid with JS/CSS selectors.
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['attributes']['class'][] = 'form-item';
|
2009-06-14 08:04:25 +00:00
|
|
|
if (!empty($element['#type'])) {
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['attributes']['class'][] = 'form-type-' . strtr($element['#type'], '_', '-');
|
2009-06-14 08:04:25 +00:00
|
|
|
}
|
|
|
|
if (!empty($element['#name'])) {
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['attributes']['class'][] = 'form-item-' . strtr($element['#name'], array(' ' => '-', '_' => '-', '[' => '-', ']' => ''));
|
2009-06-14 08:04:25 +00:00
|
|
|
}
|
2010-07-31 04:01:51 +00:00
|
|
|
// Add a class for disabled elements to facilitate cross-browser styling.
|
|
|
|
if (!empty($element['#attributes']['disabled'])) {
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['attributes']['class'][] = 'form-disabled';
|
2010-07-31 04:01:51 +00:00
|
|
|
}
|
2009-06-14 08:04:25 +00:00
|
|
|
|
2014-05-08 13:40:44 +00:00
|
|
|
// If #title is not set, we don't display any label.
|
2009-12-02 15:09:16 +00:00
|
|
|
if (!isset($element['#title'])) {
|
|
|
|
$element['#title_display'] = 'none';
|
|
|
|
}
|
2014-07-07 14:57:04 +00:00
|
|
|
// If #title_dislay is not some of the visible options, add a CSS class.
|
|
|
|
if ($element['#title_display'] != 'before' && $element['#title_display'] != 'after') {
|
|
|
|
$variables['attributes']['class'][] = 'form-no-label';
|
|
|
|
}
|
|
|
|
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['prefix'] = isset($element['#field_prefix']) ? $element['#field_prefix'] : NULL;
|
|
|
|
$variables['suffix'] = isset($element['#field_suffix']) ? $element['#field_suffix'] : NULL;
|
2006-05-02 09:26:33 +00:00
|
|
|
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['description'] = NULL;
|
2006-05-02 09:26:33 +00:00
|
|
|
if (!empty($element['#description'])) {
|
2014-08-12 03:03:40 +00:00
|
|
|
$variables['description_display'] = $element['#description_display'];
|
|
|
|
$description_attributes = array('class' => array('description'));
|
|
|
|
if ($element['#description_display'] === 'invisible') {
|
|
|
|
$description_attributes['class'][] = 'visually-hidden';
|
|
|
|
}
|
2012-04-05 07:09:10 +00:00
|
|
|
if (!empty($element['#id'])) {
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$description_attributes['id'] = $element['#id'] . '--description';
|
2012-04-05 07:09:10 +00:00
|
|
|
}
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['description']['attributes'] = new Attribute($description_attributes);
|
|
|
|
$variables['description']['content'] = $element['#description'];
|
2006-05-02 09:26:33 +00:00
|
|
|
}
|
|
|
|
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
// Add label_display and label variables to template.
|
|
|
|
$variables['label_display'] = $element['#title_display'];
|
|
|
|
$variables['label'] = array('#theme' => 'form_element_label');
|
|
|
|
$variables['label'] += array_intersect_key($element, array_flip(array('#id', '#required', '#title', '#title_display')));
|
2006-05-02 09:26:33 +00:00
|
|
|
|
Issue #2152213 by steveoliver, joelpittet, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand: Convert theme_form_element() to Twig
2014-02-04 13:24:34 +00:00
|
|
|
$variables['children'] = $element['#children'];
|
2005-10-07 06:11:12 +00:00
|
|
|
}
|
2006-01-24 10:15:03 +00:00
|
|
|
|
2009-12-02 15:09:16 +00:00
|
|
|
/**
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
* Prepares variables for form label templates.
|
2009-12-02 15:09:16 +00:00
|
|
|
*
|
|
|
|
* Form element labels include the #title and a #required marker. The label is
|
|
|
|
* associated with the element itself by the element #id. Labels may appear
|
2012-02-19 03:41:24 +00:00
|
|
|
* before or after elements, depending on theme_form_element() and
|
|
|
|
* #title_display.
|
2009-12-02 15:09:16 +00:00
|
|
|
*
|
|
|
|
* This function will not be called for elements with no labels, depending on
|
|
|
|
* #title_display. For elements that have an empty #title and are not required,
|
|
|
|
* this function will output no label (''). For required elements that have an
|
|
|
|
* empty #title, this will output the required marker alone within the label.
|
|
|
|
* The label will use the #id to associate the marker with the field that is
|
|
|
|
* required. That is especially important for screenreader users to know
|
|
|
|
* which field is required.
|
|
|
|
*
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
* @param array $variables
|
2009-12-02 15:09:16 +00:00
|
|
|
* An associative array containing:
|
|
|
|
* - element: An associative array containing the properties of the element.
|
|
|
|
* Properties used: #required, #title, #id, #value, #description.
|
|
|
|
*/
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
function template_preprocess_form_element_label(&$variables) {
|
2009-12-02 15:09:16 +00:00
|
|
|
$element = $variables['element'];
|
|
|
|
// If title and required marker are both empty, output no label.
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
$variables['title'] = (isset($element['#title']) && $element['#title'] !== '') ? Xss::filterAdmin($element['#title']) : '';
|
|
|
|
$variables['attributes'] = array();
|
2010-04-07 04:39:59 +00:00
|
|
|
// Style the label as class option to display inline with the element.
|
2009-12-02 15:09:16 +00:00
|
|
|
if ($element['#title_display'] == 'after') {
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
$variables['attributes']['class'][] = 'option';
|
2009-12-02 15:09:16 +00:00
|
|
|
}
|
2010-04-07 04:39:59 +00:00
|
|
|
// Show label only to screen readers to avoid disruption in visual flows.
|
|
|
|
elseif ($element['#title_display'] == 'invisible') {
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
$variables['attributes']['class'][] = 'visually-hidden';
|
2010-04-07 04:39:59 +00:00
|
|
|
}
|
|
|
|
|
2014-02-27 19:52:40 +00:00
|
|
|
// A #for property of a dedicated #type 'label' element as precedence.
|
|
|
|
if (!empty($element['#for'])) {
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
$variables['attributes']['for'] = $element['#for'];
|
2014-02-27 19:52:40 +00:00
|
|
|
// A custom #id allows the referenced form input element to refer back to
|
|
|
|
// the label element; e.g., in the 'aria-labelledby' attribute.
|
|
|
|
if (!empty($element['#id'])) {
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
$variables['attributes']['id'] = $element['#id'];
|
2014-02-27 19:52:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Otherwise, point to the #id of the form input element.
|
|
|
|
elseif (!empty($element['#id'])) {
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
$variables['attributes']['for'] = $element['#id'];
|
2009-12-02 15:09:16 +00:00
|
|
|
}
|
|
|
|
|
2014-05-08 13:40:44 +00:00
|
|
|
// For required elements a 'form-required' class is appended to the
|
|
|
|
// label attributes.
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
$variables['required'] = FALSE;
|
2014-05-08 13:40:44 +00:00
|
|
|
if (!empty($element['#required'])) {
|
Issue #2152215 by joelpittet, mr.baileys, benjifisher, martin107, rteijeiro, hussainweb, shanethehat, jenlampton, kpa, AnythonyR, EVIIILJ, kgoel, Cottser, dsdeiz, hanpersand, bayousoft: Convert theme_form_element_label() to Twig
2014-06-12 17:20:10 +00:00
|
|
|
$variables['required'] = TRUE;
|
|
|
|
$variables['attributes']['class'][] = 'form-required';
|
2014-05-08 13:40:44 +00:00
|
|
|
}
|
2009-12-02 15:09:16 +00:00
|
|
|
}
|
|
|
|
|
2007-05-04 09:41:37 +00:00
|
|
|
/**
|
|
|
|
* @defgroup batch Batch operations
|
|
|
|
* @{
|
2012-02-19 03:41:24 +00:00
|
|
|
* Creates and processes batch operations.
|
2011-01-03 18:03:54 +00:00
|
|
|
*
|
2007-05-04 09:41:37 +00:00
|
|
|
* Functions allowing forms processing to be spread out over several page
|
|
|
|
* requests, thus ensuring that the processing does not get interrupted
|
|
|
|
* because of a PHP timeout, while allowing the user to receive feedback
|
|
|
|
* on the progress of the ongoing operations.
|
|
|
|
*
|
|
|
|
* The API is primarily designed to integrate nicely with the Form API
|
2010-06-15 15:52:04 +00:00
|
|
|
* workflow, but can also be used by non-Form API scripts (like update.php)
|
2007-05-04 09:41:37 +00:00
|
|
|
* or even simple page callbacks (which should probably be used sparingly).
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* $batch = array(
|
|
|
|
* 'title' => t('Exporting'),
|
|
|
|
* 'operations' => array(
|
2013-07-11 17:29:02 +00:00
|
|
|
* array('my_function_1', array($account->id(), 'story')),
|
2007-05-04 09:41:37 +00:00
|
|
|
* array('my_function_2', array()),
|
|
|
|
* ),
|
|
|
|
* 'finished' => 'my_finished_callback',
|
2009-11-07 14:44:04 +00:00
|
|
|
* 'file' => 'path_to_file_containing_myfunctions',
|
2007-05-04 09:41:37 +00:00
|
|
|
* );
|
|
|
|
* batch_set($batch);
|
2011-07-28 19:29:53 +00:00
|
|
|
* // Only needed if not inside a form _submit handler.
|
|
|
|
* // Setting redirect in batch_process.
|
|
|
|
* batch_process('node/1');
|
2007-05-04 09:41:37 +00:00
|
|
|
* @endcode
|
|
|
|
*
|
2009-11-07 14:44:04 +00:00
|
|
|
* Note: if the batch 'title', 'init_message', 'progress_message', or
|
|
|
|
* 'error_message' could contain any user input, it is the responsibility of
|
2008-10-14 11:01:08 +00:00
|
|
|
* the code calling batch_set() to sanitize them first with a function like
|
2014-04-07 15:01:20 +00:00
|
|
|
* \Drupal\Component\Utility\String::checkPlain() or
|
|
|
|
* \Drupal\Component\Utility\Xss::filter(). Furthermore, if the batch operation
|
|
|
|
* returns any user input in the 'results' or 'message' keys of $context, it
|
|
|
|
* must also sanitize them first.
|
2008-10-14 11:01:08 +00:00
|
|
|
*
|
2014-02-13 00:46:08 +00:00
|
|
|
* Sample callback_batch_operation():
|
2007-05-04 09:41:37 +00:00
|
|
|
* @code
|
|
|
|
* // Simple and artificial: load a node of a given type for a given user
|
|
|
|
* function my_function_1($uid, $type, &$context) {
|
|
|
|
* // The $context array gathers batch context information about the execution (read),
|
|
|
|
* // as well as 'return values' for the current operation (write)
|
|
|
|
* // The following keys are provided :
|
|
|
|
* // 'results' (read / write): The array of results gathered so far by
|
2007-07-02 14:41:37 +00:00
|
|
|
* // the batch processing, for the current operation to append its own.
|
2007-05-04 09:41:37 +00:00
|
|
|
* // 'message' (write): A text message displayed in the progress page.
|
|
|
|
* // The following keys allow for multi-step operations :
|
|
|
|
* // 'sandbox' (read / write): An array that can be freely used to
|
|
|
|
* // store persistent data between iterations. It is recommended to
|
|
|
|
* // use this instead of $_SESSION, which is unsafe if the user
|
|
|
|
* // continues browsing in a separate window while the batch is processing.
|
|
|
|
* // 'finished' (write): A float number between 0 and 1 informing
|
|
|
|
* // the processing engine of the completion level for the operation.
|
2007-05-07 10:15:57 +00:00
|
|
|
* // 1 (or no value explicitly set) means the operation is finished
|
|
|
|
* // and the batch processing can continue to the next operation.
|
|
|
|
*
|
2012-08-21 15:38:04 +00:00
|
|
|
* $nodes = entity_load_multiple_by_properties('node', array('uid' => $uid, 'type' => $type));
|
|
|
|
* $node = reset($nodes);
|
2013-10-07 05:34:09 +00:00
|
|
|
* $context['results'][] = $node->id() . ' : ' . String::checkPlain($node->label());
|
|
|
|
* $context['message'] = String::checkPlain($node->label());
|
2007-05-04 09:41:37 +00:00
|
|
|
* }
|
|
|
|
*
|
2013-05-26 20:18:10 +00:00
|
|
|
* // A more advanced example is a multi-step operation that loads all rows,
|
|
|
|
* // five by five.
|
2007-05-04 09:41:37 +00:00
|
|
|
* function my_function_2(&$context) {
|
|
|
|
* if (empty($context['sandbox'])) {
|
|
|
|
* $context['sandbox']['progress'] = 0;
|
2013-05-26 20:18:10 +00:00
|
|
|
* $context['sandbox']['current_id'] = 0;
|
|
|
|
* $context['sandbox']['max'] = db_query('SELECT COUNT(DISTINCT id) FROM {example}')->fetchField();
|
2007-05-04 09:41:37 +00:00
|
|
|
* }
|
|
|
|
* $limit = 5;
|
2013-05-26 20:18:10 +00:00
|
|
|
* $result = db_select('example')
|
|
|
|
* ->fields('example', array('id'))
|
|
|
|
* ->condition('id', $context['sandbox']['current_id'], '>')
|
|
|
|
* ->orderBy('id')
|
2009-03-14 16:27:58 +00:00
|
|
|
* ->range(0, $limit)
|
|
|
|
* ->execute();
|
|
|
|
* foreach ($result as $row) {
|
2013-11-06 02:12:47 +00:00
|
|
|
* $context['results'][] = $row->id . ' : ' . String::checkPlain($row->title);
|
2007-05-04 09:41:37 +00:00
|
|
|
* $context['sandbox']['progress']++;
|
2013-05-26 20:18:10 +00:00
|
|
|
* $context['sandbox']['current_id'] = $row->id;
|
2013-11-06 02:12:47 +00:00
|
|
|
* $context['message'] = String::checkPlain($row->title);
|
2007-05-04 09:41:37 +00:00
|
|
|
* }
|
|
|
|
* if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
|
|
|
|
* $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
*
|
2014-02-13 00:46:08 +00:00
|
|
|
* Sample callback_batch_finished():
|
2007-05-04 09:41:37 +00:00
|
|
|
* @code
|
|
|
|
* function batch_test_finished($success, $results, $operations) {
|
2011-06-01 08:39:51 +00:00
|
|
|
* // The 'success' parameter means no fatal PHP errors were detected. All
|
|
|
|
* // other error management should be handled using 'results'.
|
2007-05-04 09:41:37 +00:00
|
|
|
* if ($success) {
|
2007-11-12 19:06:33 +00:00
|
|
|
* $message = format_plural(count($results), 'One post processed.', '@count posts processed.');
|
2007-05-04 09:41:37 +00:00
|
|
|
* }
|
|
|
|
* else {
|
|
|
|
* $message = t('Finished with an error.');
|
|
|
|
* }
|
|
|
|
* drupal_set_message($message);
|
2007-07-02 14:41:37 +00:00
|
|
|
* // Providing data for the redirected page is done through $_SESSION.
|
2007-05-04 09:41:37 +00:00
|
|
|
* foreach ($results as $result) {
|
|
|
|
* $items[] = t('Loaded node %title.', array('%title' => $result));
|
|
|
|
* }
|
2009-06-02 06:58:17 +00:00
|
|
|
* $_SESSION['my_batch_results'] = $items;
|
2007-05-04 09:41:37 +00:00
|
|
|
* }
|
|
|
|
* @endcode
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2012-04-10 17:58:43 +00:00
|
|
|
* Adds a new batch.
|
|
|
|
*
|
|
|
|
* Batch operations are added as new batch sets. Batch sets are used to spread
|
|
|
|
* processing (primarily, but not exclusively, forms processing) over several
|
|
|
|
* page requests. This helps to ensure that the processing is not interrupted
|
|
|
|
* due to PHP timeouts, while users are still able to receive feedback on the
|
|
|
|
* progress of the ongoing operations. Combining related operations into
|
|
|
|
* distinct batch sets provides clean code independence for each batch set,
|
|
|
|
* ensuring that two or more batches, submitted independently, can be processed
|
|
|
|
* without mutual interference. Each batch set may specify its own set of
|
|
|
|
* operations and results, produce its own UI messages, and trigger its own
|
|
|
|
* 'finished' callback. Batch sets are processed sequentially, with the progress
|
|
|
|
* bar starting afresh for each new set.
|
|
|
|
*
|
|
|
|
* @param $batch_definition
|
|
|
|
* An associative array defining the batch, with the following elements (all
|
|
|
|
* are optional except as noted):
|
2014-02-13 00:46:08 +00:00
|
|
|
* - operations: (required) Array of operations to be performed, where each
|
|
|
|
* item is an array consisting of the name of an implementation of
|
|
|
|
* callback_batch_operation() and an array of parameter.
|
2009-11-07 14:44:04 +00:00
|
|
|
* Example:
|
|
|
|
* @code
|
|
|
|
* array(
|
2014-02-13 00:46:08 +00:00
|
|
|
* array('callback_batch_operation_1', array($arg1)),
|
|
|
|
* array('callback_batch_operation_2', array($arg2_1, $arg2_2)),
|
2009-11-07 14:44:04 +00:00
|
|
|
* )
|
|
|
|
* @endcode
|
2012-04-10 17:58:43 +00:00
|
|
|
* - title: A safe, translated string to use as the title for the progress
|
|
|
|
* page. Defaults to t('Processing').
|
|
|
|
* - init_message: Message displayed while the processing is initialized.
|
2009-11-07 14:44:04 +00:00
|
|
|
* Defaults to t('Initializing.').
|
2012-04-10 17:58:43 +00:00
|
|
|
* - progress_message: Message displayed while processing the batch. Available
|
|
|
|
* placeholders are @current, @remaining, @total, @percentage, @estimate and
|
|
|
|
* @elapsed. Defaults to t('Completed @current of @total.').
|
|
|
|
* - error_message: Message displayed if an error occurred while processing
|
2009-11-07 14:44:04 +00:00
|
|
|
* the batch. Defaults to t('An error has occurred.').
|
2014-02-13 00:46:08 +00:00
|
|
|
* - finished: Name of an implementation of callback_batch_finished(). This is
|
|
|
|
* executed after the batch has completed. This should be used to perform
|
|
|
|
* any result massaging that may be needed, and possibly save data in
|
|
|
|
* $_SESSION for display after final page redirection.
|
2012-04-10 17:58:43 +00:00
|
|
|
* - file: Path to the file containing the definitions of the 'operations' and
|
|
|
|
* 'finished' functions, for instance if they don't reside in the main
|
|
|
|
* .module file. The path should be relative to base_path(), and thus should
|
|
|
|
* be built using drupal_get_path().
|
|
|
|
* - css: Array of paths to CSS files to be used on the progress page.
|
|
|
|
* - url_options: options passed to url() when constructing redirect URLs for
|
|
|
|
* the batch.
|
Issue #1825952 by Fabianx, joelpittet, bdragon, heddn, chx, xjm, pwolanin, mikey_p, ti2m, bfr, dags, cilefen, scor, mgifford: Turn on twig autoescape by default
2014-07-18 09:05:22 +00:00
|
|
|
* - safe_strings: Internal use only. Used to store and retrieve strings
|
|
|
|
* marked as safe between requests.
|
2007-05-04 09:41:37 +00:00
|
|
|
*/
|
|
|
|
function batch_set($batch_definition) {
|
|
|
|
if ($batch_definition) {
|
|
|
|
$batch =& batch_get();
|
2010-01-08 06:36:34 +00:00
|
|
|
|
|
|
|
// Initialize the batch if needed.
|
2007-05-04 09:41:37 +00:00
|
|
|
if (empty($batch)) {
|
|
|
|
$batch = array(
|
|
|
|
'sets' => array(),
|
2010-01-08 06:36:34 +00:00
|
|
|
'has_form_submits' => FALSE,
|
2007-05-04 09:41:37 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2010-01-08 06:36:34 +00:00
|
|
|
// Base and default properties for the batch set.
|
2007-05-04 09:41:37 +00:00
|
|
|
$init = array(
|
|
|
|
'sandbox' => array(),
|
|
|
|
'results' => array(),
|
|
|
|
'success' => FALSE,
|
2010-01-08 06:36:34 +00:00
|
|
|
'start' => 0,
|
2009-01-12 06:23:57 +00:00
|
|
|
'elapsed' => 0,
|
2007-05-04 09:41:37 +00:00
|
|
|
);
|
|
|
|
$defaults = array(
|
2013-06-17 13:35:07 +00:00
|
|
|
'title' => t('Processing'),
|
|
|
|
'init_message' => t('Initializing.'),
|
|
|
|
'progress_message' => t('Completed @current of @total.'),
|
|
|
|
'error_message' => t('An error has occurred.'),
|
2008-06-24 21:51:03 +00:00
|
|
|
'css' => array(),
|
2007-05-04 09:41:37 +00:00
|
|
|
);
|
|
|
|
$batch_set = $init + $batch_definition + $defaults;
|
|
|
|
|
2010-01-08 06:36:34 +00:00
|
|
|
// Tweak init_message to avoid the bottom of the page flickering down after
|
|
|
|
// init phase.
|
2007-05-04 09:41:37 +00:00
|
|
|
$batch_set['init_message'] .= '<br/> ';
|
2010-01-08 06:36:34 +00:00
|
|
|
|
|
|
|
// The non-concurrent workflow of batch execution allows us to save
|
|
|
|
// numberOfItems() queries by handling our own counter.
|
2007-05-04 09:41:37 +00:00
|
|
|
$batch_set['total'] = count($batch_set['operations']);
|
2010-01-08 06:36:34 +00:00
|
|
|
$batch_set['count'] = $batch_set['total'];
|
2007-05-04 09:41:37 +00:00
|
|
|
|
2010-01-08 06:36:34 +00:00
|
|
|
// Add the set to the batch.
|
|
|
|
if (empty($batch['id'])) {
|
|
|
|
// The batch is not running yet. Simply add the new set.
|
|
|
|
$batch['sets'][] = $batch_set;
|
2007-05-04 09:41:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2010-01-08 06:36:34 +00:00
|
|
|
// The set is being added while the batch is running. Insert the new set
|
|
|
|
// right after the current one to ensure execution order, and store its
|
|
|
|
// operations in a queue.
|
|
|
|
$index = $batch['current_set'] + 1;
|
|
|
|
$slice1 = array_slice($batch['sets'], 0, $index);
|
|
|
|
$slice2 = array_slice($batch['sets'], $index);
|
|
|
|
$batch['sets'] = array_merge($slice1, array($batch_set), $slice2);
|
|
|
|
_batch_populate_queue($batch, $index);
|
2007-05-04 09:41:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-07 14:44:04 +00:00
|
|
|
* Processes the batch.
|
2007-05-06 05:47:52 +00:00
|
|
|
*
|
2008-10-15 14:17:27 +00:00
|
|
|
* This function is generally not needed in form submit handlers;
|
|
|
|
* Form API takes care of batches that were set during form submission.
|
2007-05-04 09:41:37 +00:00
|
|
|
*
|
|
|
|
* @param $redirect
|
|
|
|
* (optional) Path to redirect to when the batch has finished processing.
|
|
|
|
* @param $url
|
2007-07-02 14:41:37 +00:00
|
|
|
* (optional - should only be used for separate scripts like update.php)
|
2007-05-04 09:41:37 +00:00
|
|
|
* URL of the batch processing page.
|
2009-10-03 20:17:46 +00:00
|
|
|
* @param $redirect_callback
|
|
|
|
* (optional) Specify a function to be called to redirect to the progressive
|
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
|
|
|
* processing page.
|
|
|
|
*
|
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse|null
|
|
|
|
* A redirect response if the batch is progressive. No return value otherwise.
|
2007-05-04 09:41:37 +00:00
|
|
|
*/
|
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
|
|
|
function batch_process($redirect = NULL, $url = 'batch', $redirect_callback = NULL) {
|
2007-05-04 09:41:37 +00:00
|
|
|
$batch =& batch_get();
|
|
|
|
|
|
|
|
if (isset($batch)) {
|
|
|
|
// Add process information
|
|
|
|
$process_info = array(
|
|
|
|
'current_set' => 0,
|
|
|
|
'progressive' => TRUE,
|
2009-10-03 20:17:46 +00:00
|
|
|
'url' => $url,
|
2009-10-27 04:12:39 +00:00
|
|
|
'url_options' => array(),
|
2012-04-29 15:16:27 +00:00
|
|
|
'source_url' => current_path(),
|
2014-08-07 20:43:27 +00:00
|
|
|
'batch_redirect' => $redirect,
|
2014-08-21 16:53:03 +00:00
|
|
|
'theme' => \Drupal::theme()->getActiveTheme()->getName(),
|
2009-10-03 20:17:46 +00:00
|
|
|
'redirect_callback' => $redirect_callback,
|
2007-05-04 09:41:37 +00:00
|
|
|
);
|
|
|
|
$batch += $process_info;
|
|
|
|
|
2010-01-08 06:36:34 +00:00
|
|
|
// The batch is now completely built. Allow other modules to make changes
|
|
|
|
// to the batch so that it is easier to reuse batch processes in other
|
2010-01-25 10:38:35 +00:00
|
|
|
// environments.
|
2014-02-24 10:10:52 +00:00
|
|
|
\Drupal::moduleHandler()->alter('batch', $batch);
|
2009-10-03 20:17:46 +00:00
|
|
|
|
2010-01-08 06:36:34 +00:00
|
|
|
// Assign an arbitrary id: don't rely on a serial column in the 'batch'
|
|
|
|
// table, since non-progressive batches skip database storage completely.
|
|
|
|
$batch['id'] = db_next_id();
|
|
|
|
|
|
|
|
// Move operations to a job queue. Non-progressive batches will use a
|
|
|
|
// memory-based queue.
|
|
|
|
foreach ($batch['sets'] as $key => $batch_set) {
|
|
|
|
_batch_populate_queue($batch, $key);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initiate processing.
|
2007-05-04 09:41:37 +00:00
|
|
|
if ($batch['progressive']) {
|
2010-01-08 06:36:34 +00:00
|
|
|
// Now that we have a batch id, we can generate the redirection link in
|
|
|
|
// the generic error message.
|
2013-06-17 13:35:07 +00:00
|
|
|
$batch['error_message'] = t('Please continue to <a href="@error_url">the error page</a>', array('@error_url' => url($url, array('query' => array('id' => $batch['id'], 'op' => 'finished')))));
|
2010-01-08 06:36:34 +00:00
|
|
|
|
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
|
|
|
// Clear the way for the redirection to the batch processing page, by
|
|
|
|
// saving and unsetting the 'destination', if there is any.
|
2013-09-16 03:58:06 +00:00
|
|
|
$request = \Drupal::request();
|
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
|
|
|
if ($request->query->has('destination')) {
|
|
|
|
$batch['destination'] = $request->query->get('destination');
|
|
|
|
$request->query->remove('destination');
|
2007-05-04 09:41:37 +00:00
|
|
|
}
|
2007-07-20 05:44:13 +00:00
|
|
|
|
Issue #1825952 by Fabianx, joelpittet, bdragon, heddn, chx, xjm, pwolanin, mikey_p, ti2m, bfr, dags, cilefen, scor, mgifford: Turn on twig autoescape by default
2014-07-18 09:05:22 +00:00
|
|
|
// Store safe strings.
|
|
|
|
// @todo Ensure we are not storing an excessively large string list in:
|
|
|
|
// https://www.drupal.org/node/2295823
|
|
|
|
$batch['safe_strings'] = SafeMarkup::getAll();
|
|
|
|
|
2010-01-08 06:36:34 +00:00
|
|
|
// Store the batch.
|
2013-09-16 03:58:06 +00:00
|
|
|
\Drupal::service('batch.storage')->create($batch);
|
2007-07-20 05:44:13 +00:00
|
|
|
|
2009-06-02 06:58:17 +00:00
|
|
|
// Set the batch number in the session to guarantee that it will stay alive.
|
|
|
|
$_SESSION['batches'][$batch['id']] = TRUE;
|
|
|
|
|
2010-01-08 06:36:34 +00:00
|
|
|
// Redirect for processing.
|
Issue #1668866 by ParisLiakos, aspilicious, tim.plunkett, pdrake, g.oechsler, dawehner, Berdir, corvus_ch, damiankloip, disasm, marcingy, neclimdul: Replace drupal_goto() with RedirectResponse.
2013-06-19 16:07:30 +00:00
|
|
|
$options = array('query' => array('op' => 'start', 'id' => $batch['id']));
|
|
|
|
if (($function = $batch['redirect_callback']) && function_exists($function)) {
|
|
|
|
$function($batch['url'], $options);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$options['absolute'] = TRUE;
|
|
|
|
return new RedirectResponse(url($batch['url'], $options));
|
|
|
|
}
|
2007-05-04 09:41:37 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Non-progressive execution: bypass the whole progressbar workflow
|
|
|
|
// and execute the batch in one pass.
|
2013-05-09 09:25:10 +00:00
|
|
|
require_once __DIR__ . '/batch.inc';
|
2007-05-04 09:41:37 +00:00
|
|
|
_batch_process();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-11-07 14:44:04 +00:00
|
|
|
* Retrieves the current batch.
|
2007-05-04 09:41:37 +00:00
|
|
|
*/
|
|
|
|
function &batch_get() {
|
2009-11-21 14:06:46 +00:00
|
|
|
// Not drupal_static(), because Batch API operates at a lower level than most
|
|
|
|
// use-cases for resetting static variables, and we specifically do not want a
|
|
|
|
// global drupal_static_reset() resetting the batch information. Functions
|
|
|
|
// that are part of the Batch API and need to reset the batch information may
|
|
|
|
// call batch_get() and manipulate the result by reference. Functions that are
|
|
|
|
// not part of the Batch API can also do this, but shouldn't.
|
|
|
|
static $batch = array();
|
2007-05-04 09:41:37 +00:00
|
|
|
return $batch;
|
|
|
|
}
|
|
|
|
|
2010-01-08 06:36:34 +00:00
|
|
|
/**
|
|
|
|
* Populates a job queue with the operations of a batch set.
|
|
|
|
*
|
2012-03-12 03:07:39 +00:00
|
|
|
* Depending on whether the batch is progressive or not, the
|
|
|
|
* Drupal\Core\Queue\Batch or Drupal\Core\Queue\BatchMemory handler classes will
|
|
|
|
* be used.
|
2010-01-08 06:36:34 +00:00
|
|
|
*
|
|
|
|
* @param $batch
|
|
|
|
* The batch array.
|
|
|
|
* @param $set_id
|
|
|
|
* The id of the set to process.
|
2012-02-19 03:41:24 +00:00
|
|
|
*
|
2010-01-08 06:36:34 +00:00
|
|
|
* @return
|
|
|
|
* The name and class of the queue are added by reference to the batch set.
|
|
|
|
*/
|
|
|
|
function _batch_populate_queue(&$batch, $set_id) {
|
|
|
|
$batch_set = &$batch['sets'][$set_id];
|
|
|
|
|
|
|
|
if (isset($batch_set['operations'])) {
|
|
|
|
$batch_set += array(
|
|
|
|
'queue' => array(
|
|
|
|
'name' => 'drupal_batch:' . $batch['id'] . ':' . $set_id,
|
2012-03-12 03:07:39 +00:00
|
|
|
'class' => $batch['progressive'] ? 'Drupal\Core\Queue\Batch' : 'Drupal\Core\Queue\BatchMemory',
|
2010-01-08 06:36:34 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$queue = _batch_queue($batch_set);
|
|
|
|
$queue->createQueue();
|
|
|
|
foreach ($batch_set['operations'] as $operation) {
|
|
|
|
$queue->createItem($operation);
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($batch_set['operations']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a queue object for a batch set.
|
|
|
|
*
|
|
|
|
* @param $batch_set
|
|
|
|
* The batch set.
|
2012-02-19 03:41:24 +00:00
|
|
|
*
|
2010-01-08 06:36:34 +00:00
|
|
|
* @return
|
|
|
|
* The queue object.
|
|
|
|
*/
|
|
|
|
function _batch_queue($batch_set) {
|
|
|
|
static $queues;
|
|
|
|
|
2010-09-26 23:31:36 +00:00
|
|
|
if (!isset($queues)) {
|
2010-01-08 06:36:34 +00:00
|
|
|
$queues = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($batch_set['queue'])) {
|
|
|
|
$name = $batch_set['queue']['name'];
|
|
|
|
$class = $batch_set['queue']['class'];
|
|
|
|
|
|
|
|
if (!isset($queues[$class][$name])) {
|
2013-01-15 15:35:31 +00:00
|
|
|
$queues[$class][$name] = new $class($name, Database::getConnection());
|
2010-01-08 06:36:34 +00:00
|
|
|
}
|
|
|
|
return $queues[$class][$name];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-04 09:41:37 +00:00
|
|
|
/**
|
|
|
|
* @} End of "defgroup batch".
|
|
|
|
*/
|