You are here

function flexiform_embed_entity_elements in Flexiform 7

Add elements for an entity to the form based on settings in the $elements array.

_state

Parameters

$entity_namespace: The namespace for this entity in this form

$flexiform: The flexiform object.

$entity: The entity object

$elements array: An array of elementss to be included in the form. Keyed by element_name.

$form:

File

includes/flexiform.flexiform.inc, line 299
flexiform.flexiform.inc Helper function for embedding the fields into the flexiform in an arbitrary order

Code

function flexiform_embed_entity_elements($entity_namespace, $flexiform, $entity, $elements, &$form, &$form_state) {

  // Set up our form bits
  if (!isset($form['#parents'])) {
    $form['#parents'] = array();
  }

  // All the fields for this entity need to end up with the correct parents
  // so set the #parents here to be the entity namespace and unset it after the
  // loop.
  array_push($form['#parents'], $entity_namespace);

  // Iterate over the fields
  foreach ($elements as $element_name => $settings) {
    $element_namespace = FlexiformElement::makeElementNamespace($settings['type'], $entity_namespace, $element_name);
    $element = FlexiformElement::getElement($flexiform, $settings['type'], $element_namespace, $settings);
    $form += $element
      ->form($form, $form_state, $entity);
  }
  array_pop($form['#parents']);
}