1

The module is a small custom widget for the entity reference field. It creates a list of nodes that allows for multiple selections.

Is it possible to paginate the results of the query even though this is a widget for a field?

function outfit_builder_field_widget_form(&$form, &$form_state, $field, $instance, $langcode, $items, $delta, $element) {

///...Additional Code Removed

$query = db_select('node', 'n');
$query->addTag('node_access');
$query->join('field_data_' . $instance['widget']['settings']['image_field_' . $type], 'fd', 'fd.entity_id = n.nid');
$query->fields('n', array('title', 'nid'));
$query->fields('fd', array($instance['widget']['settings']['image_field_' . $type] . '_fid'));
$query->condition('n.type', $type, '=');
$query->condition('fd.delta', 0, '=');
$query->condition('n.status', 1, '=');
$result = $query->extend('PagerDefault')->limit(21)->execute();
foreach ($result as $node) {
  $options[$node->nid] = theme('image_style', array(
      'style_name'  => $instance['widget']['settings']['image_style'],
      'path'        => file_load($node->{$instance['widget']['settings']['image_field_' . $type] . '_fid'})->uri,
      'title'       => check_plain($node->title),
    )
  );
}

$element += array(
'#type'             => 'checkboxes',
'#options'          => $options,
'#attributes'       => array(
  'class' => array('item'),
),


return $element;

}

0

I figured it out. After you extend your query:

$result = $query->extend('PagerDefault')->limit(21)->execute();

You'll need to also include the pager

// Attach the pager theme
$element['pager_pager'] = array('#theme' => 'pager',);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.