You are here

function flexiform_flexiform_entity_getter_info in Flexiform 7

Implements hook_flexiform_entity_getter_info().

File

./flexiform.flexiform.inc, line 52
All the flexiform hooks.

Code

function flexiform_flexiform_entity_getter_info() {
  $getters = array();

  // Base entity getter.
  $getters['base_entity'] = array(
    'label' => 'Base Entity',
    'description' => 'The Base Entity for this Flexiform',
    'entity_types' => array_keys(entity_get_info()),
    'class' => 'FlexiformFormEntityBaseEntity',
  );

  // Load entity getter.
  $getters['load_entity'] = array(
    'label' => 'Load Entity from ID',
    'description' => 'Load the entity based on id.',
    'entity_types' => array_keys(entity_get_info()),
    'class' => 'FlexiformFormEntityLoad',
  );

  // New entity getter.
  $getters['new_entity'] = array(
    'label' => 'Create a New Entity',
    'description' => 'Create a new entity.',
    'entity_types' => array_keys(entity_get_info()),
    'class' => 'FlexiformFormEntityNew',
  );

  // User Getters
  $getters['user_current_user'] = array(
    'label' => 'Current User',
    'description' => 'Load the current user into the Form',
    'entity_types' => array(
      'user',
    ),
    'class' => 'FlexiformFormEntityCurrentUser',
  );

  // Profile2 Getters
  if (module_exists('profile2')) {
    $getters['profile2_profile_from_user'] = array(
      'label' => 'Profile2 from User',
      'description' => 'Load a Profile 2 Basede on a User',
      'params' => array(
        'user' => array(
          'entity_type' => 'user',
        ),
      ),
      'entity_types' => array(
        'profile2',
      ),
      'file' => 'profile2.flexiform.inc',
    );
  }

  // Party Getters.
  if (module_exists('party')) {

    // Getters for data sets.
    foreach (party_get_data_set_info() as $data_set_name => $info) {
      $getters[$data_set_name . '_from_party'] = array(
        'label' => t('@label data set', array(
          '@label' => $info['label'],
        )),
        'description' => t('Load a data set from a party.'),
        'data_set_name' => $data_set_name,
        'params' => array(
          'party' => array(
            'entity_type' => 'party',
          ),
        ),
        'entity_types' => array(
          $info['entity type'],
        ),
        'class' => 'FlexiformFormEntityPartyDataSet',
      );
    }

    // Party from user Getters
    $getters['party_from_user'] = array(
      'label' => 'Party from User',
      'description' => 'Load a Party Based on a User',
      'params' => array(
        'user' => array(
          'entity_type' => 'user',
        ),
      ),
      'entity_types' => array(
        'party',
      ),
      'class' => 'FlexiformFormEntityPartyFromUser',
    );
  }

  // Build entity reference getters.
  if (module_exists('entityreference')) {
    $fields = db_select('field_config', 'fc')
      ->condition('type', 'entityreference')
      ->fields('fc', array(
      'field_name',
    ))
      ->execute()
      ->fetchCol();
    foreach ($fields as $field_name) {

      // Get all the info we need.
      $field = field_info_field($field_name);
      $target_entity_type = $field['settings']['target_type'];
      $target_entity_info = entity_get_info($target_entity_type);

      // Build a getter for each entity_type this field is present on.
      foreach ($field['bundles'] as $base_entity_type => $bundles) {
        $base_entity_info = entity_get_info($base_entity_type);

        // Prepare replacements for the label.
        $label_replacements = array(
          '@target' => $target_entity_info['label'],
          '@base' => $base_entity_info['label'],
          '@field' => $field_name,
        );

        // Build getter info.
        $getters["entityreference__{$field_name}__{$base_entity_type}"] = array(
          'label' => t('@target from @base via @field', $label_replacements),
          'description' => t('Load an entity via an entityreference field'),
          'field_name' => $field_name,
          'params' => array(
            'base' => array(
              'entity_type' => $base_entity_type,
            ),
          ),
          'entity_types' => array(
            $target_entity_type,
          ),
          'class' => 'FlexiformFormEntityEntityReference',
        );
      }
    }
  }

  // Build field collection getters.
  if (module_exists('field_collection')) {
    $fields = db_select('field_config', 'fc')
      ->condition('type', 'field_collection')
      ->fields('fc', array(
      'field_name',
    ))
      ->execute()
      ->fetchCol();
    foreach ($fields as $field_name) {
      $field = field_info_field($field_name);

      // Build a getter for each entity_type this field is present on.
      foreach ($field['bundles'] as $base_entity_type => $bundles) {
        $base_entity_info = entity_get_info($base_entity_type);

        // Prepare replacements for the label.
        $label_replacements = array(
          '@base' => $base_entity_info['label'],
          '@field' => $field_name,
        );
        $getters["field_collection__{$field_name}__{$base_entity_type}"] = array(
          'label' => t('Field Collection Item: @field from @base', $label_replacements),
          'description' => t('Load the field collection item'),
          'field_name' => $field_name,
          'params' => array(
            'base' => array(
              'entity_type' => $base_entity_type,
            ),
          ),
          'entity_types' => array(
            'field_collection_item',
          ),
          'class' => 'FlexiformFormEntityFieldCollection',
        );
      }
    }
  }

  // Build reply module getters.
  if (module_exists('reply')) {
    $fields = db_select('field_config', 'fc')
      ->condition('type', 'reply')
      ->fields('fc', array(
      'field_name',
    ))
      ->execute()
      ->fetchCol();
    foreach ($fields as $field_name) {
      $field = field_info_field($field_name);
      foreach ($field['bundles'] as $base_entity_type => $bundles) {
        $base_entity_info = entity_get_info($base_entity_type);

        // Prepare replacements for the label.
        $label_replacements = array(
          '@base' => $base_entity_info['label'],
          '@field' => $field_name,
        );
        $getters["reply_new__{$field_name}__{$base_entity_type}"] = array(
          'label' => t('New Reply: @field from @base', $label_replacements),
          'description' => t('Get a new reply on the entity.'),
          'field_name' => $field_name,
          'params' => array(
            'base' => array(
              'entity_type' => $base_entity_type,
            ),
          ),
          'entity_types' => array(
            'reply',
          ),
          'class' => 'FlexifromFormEntityNewReply',
        );
      }
    }
  }
  if (module_exists('commerce_line_item')) {
    $getters['commerce_line_item_new'] = array(
      'label' => t('New Line Item for Order'),
      'description' => t('Get a new line item for the order.'),
      'params' => array(
        'base' => array(
          'entity_type' => 'commerce_order',
        ),
      ),
      'entity_types' => array(
        'commerce_line_item',
      ),
      'class' => 'FlexiformFormEntityNewCommerceLineItem',
    );
  }
  if (module_exists('commerce_order')) {
    $getters['commerce_order_user'] = array(
      'label' => t('User from Order'),
      'description' => t('Get a user from the order.'),
      'params' => array(
        'base' => array(
          'entity_type' => 'commerce_order',
        ),
      ),
      'entity_types' => array(
        'user',
      ),
      'class' => 'FlexiformFormEntityCommerceOrderUser',
    );
  }
  return $getters;
}