You are here

function icon_filter_preprocess_field in Icon API 8

Same name and namespace in other branches
  1. 7 modules/icon_filter/icon_filter.module \icon_filter_preprocess_field()

Implements hook_field_prepare_view().

Processes fields to attach bundle resources (if necessary).

File

modules/icon_filter/icon_filter.module, line 69
icon_filter.module Provides a filter for text fields to replace an icon token with icon markup.

Code

function icon_filter_preprocess_field(&$variables) {
  $element =& $variables['element'];
  if (!empty($element['#formatter'])) {
    foreach ($element['#items'] as &$item) {

      // Some modules don't store the items as an array. Skip those here.
      if (!is_array($item)) {
        continue;
      }
      if (!empty($item['format']) && ($filters = filter_list_format($item['format'])) && !empty($filters['icon']->status)) {
        if (preg_match_all(ICON_FILTER_REGEX, $item['value'], $matches, PREG_SET_ORDER)) {
          foreach ($matches as $match) {
            if (!isset($icons[$match[0]]) && ($bundle = icon_bundle_load($match[1]))) {
              icon_process_attached($bundle);
            }
          }
        }
      }
    }
  }
}