$type))); // Get the available embedding themes $themes = embed_get_info(); // Remap from an array keyed on theme to one keyed on type $themes = embed_remap_info($themes); // Filter to get only those themes for the specified type $themes = $themes[$type]; // TODO : Need a function to sort these by title so it looks pretty // Cross reference system.admin.inc | system_themes_form() // Define the default theme setting $info = array( 'title' => t('Embed'), 'description' => t('This is the default handler of the embed module and it is available for all objects. It will embed the object using regular HTML. However, not all browers implement the <object> tag correctly it may not work in all cases, and the results are likely to be inconsistent between different browsers.'), 'multiple values' => EMBED_HANDLE_CORE, 'resource' => '', 'resource available' => '', 'operations' => '', ); // Put the default setting at the start of the array so it always comes first $form[] = array( 'info' => array( '#type' => 'value', '#value' => $info, ), ); // Put an entry in the options array ready for the radio buttons $options[] = ''; // Build array of options ready for the selector foreach ($themes AS $theme => $info) { // Add defaults that might not be declared in hook_embed_info() $info += array( 'description' => '', 'resource' => '', 'resource available' => '', 'download' => '', 'private' => FALSE, 'multiple values' => EMBED_HANDLE_CORE, 'operations' => '', ); // Only list this theme if it isn't private if (!$info['private']) { // Pick an appropriate message about the status of any resources that are needed $info['resource available'] = t('N/A'); // Check if a resource is needed if ($info['resource']) { // Assume the resource is available until it is discovered to be otherwise $info['resource available'] = t('Available'); // Check if the resource is present and change status message accordingly if (!file_exists($info['resource'])) { $info['resource available'] = t('Missing'); } } // Put the array of information in to the form ready to be rendered $form[$theme]['info'] = array( '#type' => 'value', '#value' => $info, ); // Add an option for this theme $options[$theme] = ''; } } // Put the option buttons on the form $form["embed_$type"] = array( '#type' => 'radios', '#options' => $options, '#default_value' => variable_get("embed_$type", 0), ); // We need to store the type for the theme to use $form['embed_type'] = array( '#type' => 'hidden', '#value' => $type, ); // Add custom form handler so it triggers first $form['#submit'][] = 'embed_admin_settings_submit'; // Add standard buttons and system settings submit handler $form = system_settings_form($form); // Over-ride the standard theme with the custom one needed to render the table $form['#theme'] = 'embed_admin_settings'; // Return the form return $form; } /** * Theme callback for the embed_admin_settings form. * * @param $form * An associative array containing the structure of the form. * * @see embed_admin_settings() */ function theme_embed_admin_settings($form) { // Add swf API admin css to enable the error class in the table drupal_add_css(drupal_get_path('module', 'embed') . '/embed.admin.css', 'module', 'all', FALSE); // Get the type $type = $form['embed_type']['#value']; // Iterate over child elements of the form foreach (element_children($form) as $key) { // Only show elements that describe themes and are not configured as private if (!isset($form[$key]['info']['#value']['title']) || !empty($form[$key]['info']['#value']['private'])) { continue; } // Fetch info $info = $form[$key]['info']['#value']; // Build an appropriate shared file message and set a status icon $resource = ''; $status_icon = 'misc/watchdog-ok.png'; $class = ''; if ($info['resource'] && ($info['resource available'] == t('Missing'))) { $resource .= '
' . t('This theme requires %resource which is not currently available.', array('%resource' => $info['resource'])) . '
'; $resource .= $info['download'] ? '
' . t('The required resource(s) can be downloaded from @url and must be installed before this theme can be used.', array('!url' => $info['download'], '@url' => $info['download'])) . '
' : ''; $status_icon = 'misc/watchdog-error.png'; $class = 'error'; } // Set the icon image $status_icon = theme('image', $status_icon, $info['resource available'], $info['resource available']); // Build a row $row = array(); $row[] = array('data' => drupal_render($form["embed_$type"][$key]), 'align' => 'center', 'class' => $class); $row[] = array('data' => '

' . $info['title'] . '

' . $info['description'] . '
' . $resource, 'class' => $class); $row[] = array('data' => $info['multiple values'] == EMBED_HANDLE_CORE ? t('Core') : t('Module'), 'class' => $class); $row[] = array('data' => $status_icon, 'align' => 'center', 'class' => $class); $row[] = array('data' => $info['operations'] ? l(t('configure'), $info['operations']) : '', 'class' => $class); // Add the row to the array of rows $rows[] = $row; } // Build a table $header = array(t('Default'), t('Description'), t('Multiple values'), t('Status'), t('Operations')); $output = theme('table', $header, $rows); // Render the rest of the form $output .= drupal_render_children($form); // Return the result return $output; } /** * Additional submit handler for the embed_admin_settings form. * * When the API settings are changed it is necessary to flush the page and filter caches to ensure * that users see content with the new embedding method. * * In addition, since table data was passed via the form API it is necessary to unset the 'info' * element as that shouldn't be stored when system_settings_form_submit() is called next. * * @see embed_admin_settings() */ function embed_admin_settings_submit($form, &$form_state) { // Unset info as we don't want to store this unset($form_state['values']['info'], $form_state['values']['embed_type']); // Flush all caches so the new method is picked up drupal_flush_all_caches(); } /** * Menu callback: display a simple message when there are no custom object handlers. */ function embed_admin_no_settings() { // Add message to show no custom handlers are present $form['message'] = array( '#type' => 'markup', '#value' => t('No custom object handlers have been installed yet.'), ); // Return the form return $form; }