You are here

function ctools_content_get_available_types in Chaos Tool Suite (ctools) 6

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

Get an array of all available content types that can be fed into the display editor for the add content list.

Parameters

$context: If a context is provided, content that requires that context can apepar.

$has_content: Whether or not the display will have incoming content

$allowed_types: An array of allowed content types (pane types) keyed by content_type . '-' . sub_type

$default_types: A default allowed/denied status for content that isn't known about

File

includes/content.inc, line 675
Contains the tools to handle pluggable content that can be used by other applications such as Panels or Dashboard.

Code

function ctools_content_get_available_types($contexts = NULL, $has_content = FALSE, $allowed_types = NULL, $default_types = NULL) {
  $plugins = ctools_get_content_types();
  $available = array();
  foreach ($plugins as $id => $plugin) {
    foreach (ctools_content_get_subtypes($plugin) as $subtype_id => $subtype) {

      // exclude items that require content if we're saying we don't
      // provide it.
      if (!empty($subtype['requires content']) && !$has_content) {
        continue;
      }

      // Check to see if the content type can be used in this context.
      if (!empty($subtype['required context'])) {
        if (!ctools_context_match_requirements($contexts, $subtype['required context'])) {
          continue;
        }
      }

      // Check to see if the passed-in allowed types allows this content.
      if ($allowed_types) {
        $key = $id . '-' . $subtype_id;
        if (!isset($allowed_types[$key])) {
          $allowed_types[$key] = isset($default_types[$id]) ? $default_types[$id] : $default_types['other'];
        }
        if (!$allowed_types[$key]) {
          continue;
        }
      }

      // If we made it through all the tests, then we can use this content.
      $available[$id][$subtype_id] = $subtype;
    }
  }
  return $available;
}