You are here

function _crumbs_element_object in Crumbs, the Breadcrumbs suite 7.2

Lazy-create an object representing the form element. This allows to use methods instead of procedural callbacks.

There will be one instance per element, so the object can actually hold some state information.

This mechanic would even make sense as a reusable module, but for now we just have it crumbs-specific.

Parameters

array $element:

Return value

crumbs_Admin_ElementObject_WeightsAbstract

Throws

Exception

File

includes/crumbs.callbacks.inc, line 159

Code

function _crumbs_element_object(&$element) {
  if (!isset($element['#crumbs_element_object'])) {
    switch ($element['#type']) {
      case 'crumbs_weights_tabledrag':
        $obj = new crumbs_Admin_ElementObject_WeightsTabledrag($element);
        break;
      case 'crumbs_weights_textual':
        $obj = new crumbs_Admin_ElementObject_WeightsTextual($element);
        break;
      case 'crumbs_weights_expansible':
        $obj = new crumbs_Admin_ElementObject_WeightsExpansible($element);
        break;
      default:
        throw new Exception('Unknown element type "' . $element['#type'] . '".');
    }
    $element['#crumbs_element_object'] = $obj;
  }
  return $element['#crumbs_element_object'];
}