You are here

function relation_rules_fetch_endpoint_type_options in Relation 8

Same name and namespace in other branches
  1. 8.2 relation.rules.inc \relation_rules_fetch_endpoint_type_options()
  2. 7 relation.rules.inc \relation_rules_fetch_endpoint_type_options()

Returns the options list of available endpoint entity types for the chosen relation type.

2 string references to 'relation_rules_fetch_endpoint_type_options'
relation_rules_fetch_endpoint_info_alter in ./relation.rules.inc
Info alter callback for the fetch_endpoint action.
relation_rules_load_related_info_alter in ./relation.rules.inc
Info alter callback for the load_related action.

File

./relation.rules.inc, line 284
Implements the Rules module API for Relation.

Code

function relation_rules_fetch_endpoint_type_options(RulesAbstractPlugin $element, $param_name = NULL) {
  $options = $types = array();

  // The parameter is optional.
  if ($param_name = 'entity_type_op') {
    $options[''] = t('--All types--');
  }
  $all_entity_types = rules_entity_type_options();
  if (!empty($element->settings['relation_type'])) {
    $types[] = $element->settings['relation_type'];
  }
  elseif ($wrapper = $element
    ->applyDataSelector($element->settings['relation:select'])) {

    // If we can: limit the list of entity types to those relative to the selected relation type.
    if (($info = $wrapper
      ->info()) && !empty($info['bundle'])) {
      $types[] = $info['bundle'];
    }
  }
  foreach (RelationType::loadMultiple() as $relation_type) {

    // Add the allowed source entity types to the list.
    if (!empty($relation_type->source_bundles)) {
      foreach ($relation_type->source_bundles as $source_bundle) {
        list($entity_type, ) = explode(':', $source_bundle, 2);
        $options[$entity_type] = $all_entity_types[$entity_type];
      }
    }

    // Add the allowed target entity types to the list.
    if (!empty($relation_type->target_bundles)) {
      foreach ($relation_type->target_bundles as $target_bundle) {
        list($entity_type, ) = explode(':', $target_bundle, 2);
        $options[$entity_type] = $all_entity_types[$entity_type];
      }
    }
  }
  return $options;
}