diff --git a/plugins/content_types/entity_context/entity_field.inc b/plugins/content_types/entity_context/entity_field.inc index d729d65..1b54983 100644 --- a/plugins/content_types/entity_context/entity_field.inc +++ b/plugins/content_types/entity_context/entity_field.inc @@ -7,7 +7,7 @@ $plugin = array( 'title' => t('Entity field'), - 'defaults' => array('label' => 'title', 'formatter' => ''), + 'defaults' => array('label' => 'title', 'formatter' => '', 'limit' => ''), 'content type' => 'ctools_entity_field_content_type_content_type', ); @@ -117,6 +117,14 @@ function ctools_entity_field_content_type_render($subtype, $conf, $panel_args, $ $field_output = field_view_field($entity_type, $entity, $field_name, $field_settings, $language); + // Check limit. + if (!empty($conf['limit']) && is_numeric($conf['limit'])) { + $count = count($field_output['#items']); + if ($count > $conf['limit']) { + $field_output['#items'] = array_slice($field_output['#items'], 0, $conf['limit']); + } + } + // Build the content type block. $block = new stdClass(); $block->module = 'entity_field'; @@ -166,12 +174,23 @@ function ctools_entity_field_content_type_formatter_options($form, &$form_state) '#default_value' => $conf['formatter'], ); + if (isset($field['cardinality']) && $field['cardinality'] != 1) { + $form['limit'] = array( + '#type' => 'textfield', + '#title' => t('Limit'), + '#size' => 3, + '#description' => t('Enter a number to limit the number of items to display. Leave empty to display all.'), + '#default_value' => $conf['limit'], + ); + } + return $form; } function ctools_entity_field_content_type_formatter_options_submit($form, &$form_state) { $form_state['conf']['formatter'] = $form_state['values']['formatter']; $form_state['conf']['label'] = $form_state['values']['label']; + $form_state['conf']['limit'] = $form_state['values']['limit']; } function ctools_entity_field_content_type_formatter_styles($form, &$form_state) {