I'm sure this is easy for jQuery experts, but I am a backend and cannot find a better way to do this. I have two arrays in Drupal, one of them is a list of view names, and the other is an array containing a list of displays for each view. Here's the code to populate two arrays:
$views = views_get_all_views();
$viewnames = array();
$viewdisplays = array();
foreach ($views as $view) {
$viewnames[$view->name] = $view->name;
foreach ($view->display as $k) {
$id = $k->id;
$title = $k->display_title;
$viewdisplays[$view->name]['id'] = $id;
$viewdisplays[$view->name]['title'] = $title;
}
}
Here is a snippet of the form I'm working with:
$form['view'] = array(
'#type' => 'select',
'#title' => t('Select the view to be used for display'),
'#options' => $viewnames,
);
$form['view_display'] = array(
'#type' => 'select',
'#title' => t('Select the display of the gallery view to be used'),
'#options' => array(),
);
What I want to do is dynamically populate the view_display select box with the appropriate values. If the user selected "My favorite view" from the "view", I want to display the $ viewdisplays ['My Favorite View'] array as the #options field in the view_display field.
source
share