You are here

function hook_flexiform_element_info in Flexiform 7

Define elements for use in flexiforms.

Elements should be defined in a multi-dimensional array keyed by entity type, bundle and name. The whole definition for an element will be passed to the element constructor so it is possible to store other settings in this array as necessary.

Return value

A multidimensional array of elements keyed by entity_type, bundle and an element_name that must be unique for that entity-bundle. Each element definition should be an array with the following keys:

  • label: The human readable label for the element, this can usually be overridden once the element is in a form.
  • class: The Element class to use for the rendering of the element.
  • group: (optional) What group should the element appear in when being selected to be added to the form. Defaults to 'Other'.
1 function implements hook_flexiform_element_info()

Note: this list is generated by pattern matching, so it may include some functions that are not actually implementations of this hook.

flexiform_flexiform_element_info in ./flexiform.flexiform.inc
Implements hook_flexiform_element_info().
1 invocation of hook_flexiform_element_info()
flexiform_get_element_info in ./flexiform.module
Get information about flexiform elements.

File

./flexiform.api.php, line 206
API documentation for Flexiform.

Code

function hook_flexiform_element_info() {
  $elements = array();

  // Get the element for all nested flexiforms.
  $forms = db_select('flexiform', 'f')
    ->fields('f', array(
    'label',
    'form',
    'base_entity',
    'base_entity_bundle',
  ))
    ->execute()
    ->fetchAllAssoc('form');
  foreach ($forms as $form) {
    $elements[$form->base_entity][$form->base_entity_bundle]['flexiform:' . $form->form] = array(
      'label' => $form->label,
      'class' => 'FlexiformElementFlexiform',
      'type' => 'form',
      'group' => 'Flexiform',
      'form' => $form->form,
    );
  }

  // Get all the field elements.
  $fields_info = field_info_instances();
  foreach ($fields_info as $entity_type => $entity_fields) {
    foreach ($entity_fields as $bundle => $bundle_fields) {
      foreach ($bundle_fields as $field_name => $instance) {
        $elements[$entity_type][$bundle]['field:' . $field_name] = array(
          'label' => $instance['label'],
          'class' => 'FlexiformElementField',
          'type' => 'field',
          'group' => 'Field',
          'field_name' => $field_name,
        );
      }
    }
  }
  return $elements;
}