You are here

function synonyms_behavior_get in Synonyms 7

Load function for existing implementations of synonyms behaviors.

Parameters

string $behavior: Name of the synonyms behavior whose existing implementations should be loaded. Basically it has to be name of a ctools plugin of "behavior" type.

string $entity_type: Behavior implementations of what entity type should be looked up

string|array $bundle: Behavior implementations of what bundle(-s) should be looked up. If you want to look up only a single bundle, provide a string. If you want to look up multiple bundles at a time, provide an array of bundles. Empty array here would mean to include all bundles that are known within provided $entity_type

bool $only_enabled: Optional filter to limit the search for existing implementations only to those that are currently enabled

Return value

array Array of loaded existing synonyms behavior implementations. The underlying array will have the following structure:

  • behavior: (string) Behavior name of this behavior implementation, i.e. name of a ctools plugin of "behavior" type
  • entity_type: (string) Entity type to which this behavior implementation applies
  • bundle: (string) Bundle name to which this behavior implementation applies
  • provider: (string) Machine name of this synonyms behavior implementation
  • label: (string) Human friendly name of this synonyms behavior implementation
  • class: (string) Name of PHP class that implements behavior interface
  • settings: (mixed) Behavior settings, its internal structure depends on the type of behavior. If this value is NULL, it means the behavior implementation is currently disabled
  • object: (SynonymsBehavior) If the synonyms behavior implementation is enabled, this property will contain a fully initialized object that corresponds to this behavior implementation. This object is ready for use: to query for synonyms or invoke any other methods behavior interface declares
  • module: (string) Name of the module that provides this synonyms behavior implementation
19 calls to synonyms_behavior_get()
SynonymsProviderPropertyWebTestCase::setUp in synonyms_provider_property/synonyms_provider_property.test
SetUp method.
SynonymsWebTestCase::setUp in ./synonyms.test
SetUp method.
synonyms_autocomplete_entity in ./synonyms.pages.inc
Page callback: Outputs JSON for entity autocomplete suggestions.
synonyms_autocomplete_entity_validate in ./synonyms.module
Form element validate handler.
synonyms_autocomplete_taxonomy_term in ./synonyms.pages.inc
Page callback: Outputs JSON for taxonomy autocomplete suggestions.

... See full list

File

./synonyms.module, line 938
Provide synonyms feature for Drupal entities.

Code

function synonyms_behavior_get($behavior, $entity_type, $bundle, $only_enabled = FALSE) {
  $behavior_implementations = array();
  $enabled_behavior_implementations = array();
  $query = db_select('synonyms_settings', 's');
  $query
    ->fields('s');
  $query
    ->condition('behavior', $behavior);
  $query
    ->condition('entity_type', $entity_type);
  $query
    ->condition('bundle', synonyms_bundle_normalize($entity_type, $bundle));
  $result = $query
    ->execute();
  foreach ($result as $row) {
    $row = (array) $row;
    if ($only_enabled) {
      $behavior_implementations[] = $row;
    }
    else {
      $enabled_behavior_implementations[$row['bundle']][$row['provider']] = $row;
    }
  }
  if (!$only_enabled) {
    foreach (synonyms_bundle_normalize($entity_type, $bundle) as $bundle_name) {
      foreach (synonyms_behavior_implementation_info($entity_type, $bundle_name, $behavior) as $provider_info) {
        if (isset($enabled_behavior_implementations[$bundle_name][$provider_info['provider']])) {
          $provider_info['settings_serialized'] = $enabled_behavior_implementations[$bundle_name][$provider_info['provider']]['settings_serialized'];
        }
        $behavior_implementations[] = $provider_info;
      }
    }
  }
  return synonyms_behavior_settings_unpack($behavior_implementations);
}