You are here

function _captcha_search_buttons in CAPTCHA 8

Same name and namespace in other branches
  1. 6.2 captcha.inc \_captcha_search_buttons()
  2. 7 captcha.inc \_captcha_search_buttons()

Helper function for searching the buttons in a form.

Parameters

array $form: The form to search button elements in.

Return value

array Array of paths to the buttons. A path is an array of keys leading to the button, the last item in the path is the weight of the button element (or NULL if undefined).

1 call to _captcha_search_buttons()
_captcha_get_captcha_placement in ./captcha.inc
Helper function to get placement information for a given form_id.

File

./captcha.inc, line 296
General CAPTCHA functionality and helper functions.

Code

function _captcha_search_buttons(array $form) {
  $buttons = [];
  foreach (Element::children($form, FALSE) as $key) {

    // Look for submit or button type elements.
    if (isset($form[$key]['#type']) && ($form[$key]['#type'] == 'submit' || $form[$key]['#type'] == 'button')) {
      $weight = isset($form[$key]['#weight']) ? $form[$key]['#weight'] : NULL;
      $buttons[] = [
        'path' => [],
        'key' => $key,
        'weight' => $weight,
      ];
    }

    // Process children recursively.
    $children_buttons = _captcha_search_buttons($form[$key]);
    foreach ($children_buttons as $b) {
      $b['path'] = array_merge([
        $key,
      ], $b['path']);
      $buttons[] = $b;
    }
  }
  return $buttons;
}