diff --git a/graphapi.module b/graphapi.module index 24930a7..ed87abb 100644 --- a/graphapi.module +++ b/graphapi.module @@ -358,25 +358,25 @@ function graphapi_theme() { } /** - * Dispatch the graph to the correct engine + * Dispatch the graph to the correct engine. + * + * If no engine is given we fallback to the first available. * * @param type $vars * @return type */ function theme_graphapi_dispatch($vars) { $engines = graphapi_views_formats(); + // No need to render when no engines available if (empty($engines)) { graphapi_no_engines_found(); + return ""; } - $engine = isset($vars['config']['engine']) ? $vars['config']['engine'] : ''; - if (isset($engines[$engine])) { - $theme = $engine . "_graphapi"; - return theme($theme, $vars); - } - elseif (!empty($engine)) { - return t("Graph API render engine !engine not found.", array('!engine' => $engine)); - } - return t("Graph API render engine not specified."); + $engine = $vars['config']['engine']; + // Fall back to first engine if necessary. + $engine = isset($engines[$engine]) ? $engine : key($engines); + $theme = $engine . "_graphapi"; + return theme($theme, $vars); } function graphapi_no_engines_found() { diff --git a/modules/graphapi_demo/graphapi_demo.module b/modules/graphapi_demo/graphapi_demo.module index fa9ac18..50f135c 100644 --- a/modules/graphapi_demo/graphapi_demo.module +++ b/modules/graphapi_demo/graphapi_demo.module @@ -34,13 +34,10 @@ function graphapi_demo_page($engine = NULL) { $engines = graphapi_get_engines(); if (empty($engines)) { graphapi_no_engines_found(); + return ""; } - if (is_null($engine) && count($engines)) { - $engine = key($engines); - } - if (isset($engine)) { - return graphapi_demo_engine($engine); - } + $engine = empty($engine) ? key($engines) : $engine; + return graphapi_demo_engine($engine); } function graphapi_demo_engine($engine) {