You are here

function webform_get_cid in Webform 7.4

Same name and namespace in other branches
  1. 5.2 webform.module \webform_get_cid()
  2. 5 webform.module \webform_get_cid()
  3. 6.3 webform.module \webform_get_cid()
  4. 6.2 webform.module \webform_get_cid()
  5. 7.3 webform.module \webform_get_cid()

Given a component's form_key and optionally its parent's cid, get its cid(s).

Parameters

object $node: A fully loaded webform node object.

string $form_key: The form key for which to find the cid(s).

int|null $pid: The cid of the parent component.

Return value

int|int[] The cid of the component or an array of component ids.

2 calls to webform_get_cid()
WebformComponentsTestCase::testWebformComponents in tests/WebformComponentsTestCase.test
Webform module component tests.
_webform_client_form_submit_flatten in ./webform.module
Flattens a submitted values back into a single flat array representation.

File

./webform.module, line 4290
This module provides a simple way to create forms and questionnaires.

Code

function webform_get_cid($node, $form_key, $pid = NULL) {
  if ($pid === NULL) {
    $cids = array();
    foreach ($node->webform['components'] as $cid => $component) {
      if ((string) $component['form_key'] === (string) $form_key) {
        $cids[] = $cid;
      }
    }
    return $cids;
  }
  else {
    foreach ($node->webform['components'] as $cid => $component) {
      if ((string) $component['form_key'] === (string) $form_key && $component['pid'] == $pid) {
        return $cid;
      }
    }
  }
}