You are here

function patterns_tagmodules_filter in Patterns 7.2

Same name and namespace in other branches
  1. 7 includes/tagmodules.inc \patterns_tagmodules_filter()

Filters out information from a tagmodules index and returns the results in a new array.

Select information based on the tag (e.g. node, vocabulary, etc.), or on the key (e.g. PATTERNS_CREATE), or on a combination of both.

Parameters

array $tagmodules Associative array of tagmodules:

mixed $tag (optional) Forces to return information only: from this tag. Defaults NULL.

mixed $key (optional) Forces to return information only: from the tags containing this key. Defaults NULL.

Return value

array $tagmodules The filtered tagmodules array

2 calls to patterns_tagmodules_filter()
patterns_export_page1 in patterns_export/patterns_export.module
patterns_implement_action in includes/core/common.inc
Setup and run an action.

File

includes/tagmodules.inc, line 124
Functions related to build and retrieve information from the *tagmodules* and *moduletags* indexes.

Code

function patterns_tagmodules_filter($tagmodules, $tag = NULL, $key = NULL) {
  if (empty($tagmodules)) {
    return array();
  }

  // Part of tag
  if (!empty($tag) && !empty($key)) {
    return $tagmodules[$tag][$key];
  }

  // Full tag
  if (!empty($tag)) {
    return $tagmodules[$tag];
  }

  // All the values of key=$key from all tags
  if (!empty($key)) {
    $out = array();
    foreach ($tagmodules as $tagname => $value) {
      if (isset($value[$key])) {
        $out[$value['module']][$tagname] = $value[$key];
      }
    }
    return $out;
  }
}