Permalink

I've been using your technique here and have discovered one thing. It pertains to exports/downloads of captured form results. You can expect that the assigned 'options callback' function to be called EVERY TIME form result is gathered together to be assembled into a .csv/.xls file. The continuous calls to views_get_view() can get very expensive and RAM consuming. But it's trivial to work around.

function _demo_get_view_options() {
$items = &drupal_static(__FUNCTION__);
if (!isset($items)) {
$view = views_get_view('my_sample_view', true);
$view->execute();
$items = array();

foreach ($view->result as $item) {
$full_node = node_load($item->nid);
$items[$item->nid] = $full_node->title;
}

return $items;
}

With the use of drupal_static(), views_get_view() will get called once for a single page view/result export loop because it's results are cached in memory (this isn't a MySQL/memcache thing in this case).

Let me know what you think.

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.