You are here

function manualcrop_supported_widgets in Manual Crop 7

Returns an array of supported widget types or checks if a type is supported.

Parameters

$widget_type: If set, this function will return a boolean indicating if $widget_type is supported.

$settings: Only include widgets that support these setting(s).

Return value

Array of widget types.

5 calls to manualcrop_supported_widgets()
manualcrop_field_widget_form_alter in ./manualcrop.module
Implements hook_field_widget_form_alter().
manualcrop_field_widget_info_alter in ./manualcrop.module
Implements hook_field_widget_info_alter().
manualcrop_field_widget_settings_form in ./manualcrop.admin.inc
Add the Manual Crop field widget settings.
manualcrop_form_field_ui_field_edit_form_alter in ./manualcrop.admin.inc
Implements hook_form_FORM_ID_alter().
_manualcrop_update_style_name_in_field_widget in ./manualcrop.helpers.inc
Update or remove a style name in all Manual Crop field widgets.

File

./manualcrop.helpers.inc, line 19
Helper functions for the Manual Crop module.

Code

function manualcrop_supported_widgets($widget_type = NULL, $settings = array()) {
  $widgets =& drupal_static(__FUNCTION__);
  if (!isset($widgets)) {

    // Collect information about the supported widgets.
    $widgets = module_invoke_all('manualcrop_supported_widgets');
    drupal_alter('manualcrop_supported_widgets', $widgets);
  }

  // Make sure $settings contains only valid entries.
  if (!empty($settings)) {
    if (!is_array($settings)) {
      $settings = array(
        $settings,
      );
    }
    $widget_settings = manualcrop_manualcrop_supported_widgets();
    $widget_settings = $widget_settings['image_image'];
    $settings = array_intersect($settings, $widget_settings);
  }
  if (empty($settings)) {

    // No settings required.
    $result = array_keys($widgets);
  }
  else {

    // Filter all widgets that don't support the required settings.
    $result = array();
    foreach ($widgets as $name => $widget_settings) {
      if (!count(array_diff($settings, $widget_settings))) {
        $result[] = $name;
      }
    }
  }
  if (!empty($widget_type)) {
    return in_array($widget_type, $result);
  }
  else {
    return $result;
  }
}