function ctools_entity_field_value_ctools_access_summary

Provide a summary description based upon the checked entity_bundle.

1 string reference to 'ctools_entity_field_value_ctools_access_summary'
entity_field_value.inc in plugins/access/entity_field_value.inc

File

plugins/access/entity_field_value.inc, line 276

Code

function ctools_entity_field_value_ctools_access_summary($conf, $context, $plugin) {
    list($parent, $entity_type, $bundle_type, $field_name) = explode(':', $plugin['name']);
    $instances = field_info_instances($entity_type, $bundle_type);
    $instance = $instances[$field_name];
    $field = field_info_field_by_id($instance['field_id']);
    $entity_info = entity_get_info($entity_type);
    $entity = (object) array(
        $entity_info['entity keys']['bundle'] => $bundle_type,
    );
    $keys = array();
    $value_keys = array();
    $keyed_elements = array();
    foreach ($field['columns'] as $column => $attributes) {
        $conf_key = _field_sql_storage_columnname($field_name, $column);
        $keyed_elements["@{$column}_value"] = array();
        if (isset($conf[$conf_key])) {
            if (is_array($conf[$conf_key])) {
                $i = 0;
                foreach ($conf[$conf_key] as $conf_value) {
                    if (!is_array($conf_value)) {
                        $entity->{$field_name}[LANGUAGE_NONE][$i][$column] = $conf_value;
                        $keyed_elements["@{$column}_value"][$i] = array(
                            '#markup' => $conf_value,
                        );
                    }
                    elseif (isset($conf_value[$column])) {
                        $entity->{$field_name}[LANGUAGE_NONE][$i][$column] = $conf_value[$column];
                        $keyed_elements["@{$column}_value"][$i] = array(
                            '#markup' => $conf_value[$column],
                        );
                    }
                    $i++;
                }
            }
            else {
                $entity->{$field_name}[LANGUAGE_NONE][0][$column] = $conf[$conf_key];
                $keyed_elements["@{$column}_value"][0] = array(
                    '#markup' => $conf[$conf_key],
                );
            }
        }
        $keys['@' . $column] = $column;
        $value_keys[] = "@{$column}_value";
    }
    $elements = array();
    $items = isset($entity->{$field_name}[LANGUAGE_NONE]) ? $entity->{$field_name}[LANGUAGE_NONE] : array();
    $view_mode = 'full';
    ctools_include('fields');
    $display = field_get_display($instance, $view_mode, $entity);
    if (!isset($display['module'])) {
        $display['module'] = $field['module'];
    }
    if (isset($display['module'])) {
        // Choose simple formatter for well known cases.
        switch ($display['module']) {
            case 'text':
                $display['type'] = 'text_default';
                break;
            case 'list':
                $display['type'] = 'list_default';
                if ($field['type'] == 'list_boolean') {
                    $allowed_values = list_allowed_values($field, $instance, $entity_type, $entity);
                    foreach ($items as $item) {
                        if (isset($allowed_values[$item['value']])) {
                            if ($allowed_values[$item['value']] == '') {
                                $display['type'] = 'list_key';
                                break;
                            }
                        }
                        else {
                            $display['type'] = 'list_key';
                        }
                    }
                }
                break;
            case 'taxonomy':
                $display['type'] = 'taxonomy_term_reference_plain';
                break;
            case 'entityreference':
                $display['type'] = 'entityreference_label';
                break;
            default:
                // Use field instance formatter setting.
                break;
        }
        $function = $display['module'] . '_field_formatter_view';
        if (function_exists($function)) {
            $entity_group = array(
                0 => $entity,
            );
            $item_group = array(
                0 => $items,
            );
            $instance_group = array(
                0 => $instance,
            );
            field_default_prepare_view($entity_type, $entity_group, $field, $instance_group, LANGUAGE_NONE, $item_group, $display);
            $elements = $function($entity_type, $entity, $field, $instance, LANGUAGE_NONE, $item_group[0], $display);
        }
    }
    if (count($elements) > 0) {
        foreach ($field['columns'] as $column => $attributes) {
            if (count($field['columns']) == 1) {
                $keyed_elements["@{$column}_value"] = $elements;
            }
        }
    }
    $values = array();
    foreach ($value_keys as $key) {
        $output = array();
        $elements = $keyed_elements[$key];
        if (is_array($elements)) {
            foreach ($elements as $element_key => $element) {
                if (is_numeric($element_key)) {
                    $value_str = strip_tags(drupal_render($element));
                    if (strlen($value_str) > 0) {
                        $output[] = $value_str;
                    }
                }
            }
        }
        else {
            $value_str = strip_tags(drupal_render($elements));
            if (strlen($value_str) > 0) {
                $output[] = $value_str;
            }
        }
        $value = implode(', ', $output);
        if ($value !== '') {
            $values[$key] = implode(', ', $output);
        }
    }
    $string = '';
    $value_count = count($values);
    foreach ($keys as $key_name => $column) {
        if (isset($values[$key_name . '_value'])) {
            $string .= $value_count > 1 ? " @{$column} = @{$column}_value" : "@{$column}_value";
        }
    }
    return t('@field is set to "!value"', array(
        '@field' => $instance['label'],
        '!value' => format_string($string, array_merge($keys, $values)),
    ));
}