예제 #1
0
 function test_foundation_css_injection()
 {
     // check if foundation css file is included in css drupal list :
     // we look for a {themename}/css/app.css ( included by foundation plugin)
     // or a files/okcdesign/{themename}/user_app.css included by foundation_ui plugin.
     $styles = drupal_add_css();
     $foundation_css = drupal_get_path('theme', variable_get('theme_default')) . '/css/app.css';
     // if foundation_ui is enabled && its generated file is readable, we load user_app.css instead.
     if (theme_plugin_is_enabled('foundation_ui')) {
         $user_foundation_css = variable_get('file_public_path', conf_path() . '/files') . '/okcdesign/' . variable_get('theme_default', 'okcdesign') . '/user_app.css';
         if (is_readable($user_foundation_css)) {
             $foundation_css = $user_foundation_css;
         }
     }
     $this->assertArrayHasKey($foundation_css, $styles, "foundation app.css not injected in Drupal ! ");
 }
예제 #2
0
 function __construct()
 {
     // find the number of columns of current grid.
     // take the number of columns set in _settings.scss if there is one.
     // if we find nothing in _settings.scss, take the settings saved by our plugin configuration form.
     // If form has not been saved yet, let's say there is 12 columns which is default value in foudation.
     $settings = $this->get_foundation_settings();
     // is user defined custom settings for foundation via foundation_ui plugin, take this value.
     $total_columns = theme_plugin_get_setting('foundation_ui', 'total-columns');
     if ($total_columns && theme_plugin_is_enabled('foundation_ui')) {
         $this->total_columns = $total_columns;
     } elseif (is_numeric($settings['total_columns'])) {
         $this->total_columns = $settings['total_columns'];
     } else {
         $this->total_columns = theme_plugin_get_setting(__CLASS__, 'total_columns', 12);
     }
 }
예제 #3
0
 /**
  * Adjust drupal html headers and add css & js required by foundation
  */
 function hook_html_head_alter(&$head_elements)
 {
     // by default, we will load this file
     $foundation_css = $this->default_theme_path . '/css/app.css';
     // if foundation_ui is enabled && its generated file is readable, we load user_app.css instead.
     if (theme_plugin_is_enabled('foundation_ui')) {
         $user_app_css = variable_get('file_public_path', conf_path() . '/files') . '/okcdesign/' . variable_get('theme_default', 'okcdesign') . '/user_app.css';
         if (is_readable($user_app_css)) {
             $foundation_css = $user_app_css;
         }
     }
     drupal_add_css($foundation_css);
     // for other files, use okcdesign files to not duplicate theme, for easier maintenance of all subthemes.
     drupal_add_js($this->base_theme_path . '/js/app.js');
     drupal_add_js($this->base_theme_path . '/' . $this->vendors_directory . '/modernizr/modernizr.js');
     drupal_add_js($this->base_theme_path . '/' . $this->vendors_directory . '/foundation/js/foundation.min.js');
     // HTML5 charset declaration.
     $head_elements['system_meta_content_type']['#attributes'] = array('charset' => 'utf-8');
     // Optimize mobile viewport.
     $head_elements['mobile_viewport'] = array('#type' => 'html_tag', '#tag' => 'meta', '#attributes' => array('name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0'));
     // Remove image toolbar in IE.
     $head_elements['ie_image_toolbar'] = array('#type' => 'html_tag', '#tag' => 'meta', '#attributes' => array('http-equiv' => 'ImageToolbar', 'content' => 'false'));
 }
예제 #4
0
/**
 * Get all enabled plugins.
 * @return array
 */
function theme_plugin_get_enabled_plugins()
{
    $enabled = array();
    $plugins = theme_get_plugins();
    foreach ($plugins as $id => $datas) {
        if (theme_plugin_is_enabled($id)) {
            $enabled[$id] = $id;
        }
    }
    return $enabled;
}
 function test_theme_plugin_get_enabled_plugins()
 {
     // Always do our test on okcdesign rather than default active theme.
     // this if for theme_get_setting function
     $GLOBALS['theme_key'] = 'okcdesign';
     $plugins = theme_get_plugins();
     // disable all plugins
     $theme_settings = variable_get("theme_okcdesign_settings");
     foreach ($plugins as $plugin_id => $datas) {
         $theme_settings["theme_plugin_{$plugin_id}"] = 0;
     }
     variable_set("theme_okcdesign_settings", $theme_settings);
     drupal_static_reset('theme_get_setting');
     // each plugin should be disabled now...
     foreach ($plugins as $plugin_id => $datas) {
         $this->assertFalse(theme_plugin_is_enabled($plugin_id));
     }
     $this->assertEmpty(theme_plugin_get_enabled_plugins());
     // re-enable only required plugins :
     $theme_settings = variable_get("theme_okcdesign_settings");
     $required_plugins = $this->requiredPlugins();
     foreach ($required_plugins as $plugin_id) {
         $theme_settings["theme_plugin_{$plugin_id}"] = 1;
     }
     variable_set("theme_okcdesign_settings", $theme_settings);
     drupal_static_reset('theme_get_setting');
     // each required plugin should be enabled now.
     foreach ($required_plugins as $plugin_id) {
         $this->assertTrue(theme_plugin_is_enabled($plugin_id));
     }
     // theme_get_enabled_plugins must return exactly the same plugins :
     $this->assertSame(ksort($required_plugins), ksort(array_keys(theme_plugin_get_enabled_plugins())));
 }
예제 #6
0
/**
 * Build a checkbox to enable / disable a plugin.
 *
 * @FIXME A plugin should not be disabled if it is required by another plugin.
 *   Do not use "disabled" html attribute, as values are not POSTed anymore and
 *   so configuration is not saved correctly in this case.
 * @param $plugin_id
 *   plugin id
 * @param $plugins
 *   all registered plugins. Needed to display informations about plugin dependecies.
 * @return array
 *   checkbox FAPI element
 */
function _okcdesign_build_plugin_checkbox($plugin_id, $plugins)
{
    $plugin = $plugins[$plugin_id];
    // Fetch all plugins which required this plugin to work as expected
    $required_by_plugins = array();
    // this array will contain only *enabled* required plugins.
    $required_by_enabled_plugins = array();
    foreach ($plugin['required_by_plugins'] as $required_by_plugin_id => $required_by_plugin) {
        $required_by_plugins[$required_by_plugin_id] = $required_by_plugin['title'];
        if (theme_plugin_is_enabled($required_by_plugin_id)) {
            $required_by_plugins[$required_by_plugin_id] = $required_by_plugin['title'] . '<strong style="color:green;"> (enabled) </strong>';
            $required_by_enabled_plugins[$required_by_plugin_id] = $required_by_plugin;
        } else {
            $required_by_plugins[$required_by_plugin_id] = $required_by_plugin['title'] . ' <strong style="color:red"> (disabled) </strong>';
        }
    }
    // Find all plugins our plugin need to work.
    $dependencies = array();
    $dependencies_disabled = array();
    if (isset($plugin['dependencies'])) {
        foreach ($plugin['dependencies'] as $dependencie_id) {
            if (theme_plugin_is_enabled($dependencie_id)) {
                $dependencies[$dependencie_id] = $plugins[$dependencie_id]['title'] . '<strong style="color:green"> (enabled) </strong>';
            } else {
                $dependencies[$dependencie_id] = $plugins[$dependencie_id]['title'] . ' <strong style="color:red;"> (disabled) </strong>';
                $dependencies_disabled[$dependencie_id] = $plugins[$dependencie_id]['title'];
            }
        }
    }
    // build a title for the checkbox, adding description and all dependencies informations.
    $title = "<strong> ENABLE PLUGIN " . strtoupper($plugin['title']) . "</strong>";
    $description = !empty($plugin['description']) ? $plugin['description'] . '<br />' : '';
    if ($required_by_plugins) {
        $description .= '<br/> <strong>Required by : </strong>' . implode(', ', $required_by_plugins) . '<br />';
    }
    if ($dependencies) {
        $description .= '<br/> <strong>Depends on : </strong>' . implode(', ', $dependencies) . '<br />';
    }
    // create checkbox to enable / disabled this plugin.
    $checkbox = array('#type' => 'checkbox', '#title' => $title, '#default_value' => theme_get_setting("theme_plugin_{$plugin_id}"), '#description' => $description);
    // do not allow to disable a plugin if enabled plugins require it
    if ($required_by_enabled_plugins) {
        $fake_checkbox = $checkbox;
        $fake_checkbox['#disabled'] = FALSE;
        $checkbox['#access'] = FALSE;
        return $fake_checkbox;
    }
    // do not allow to Enable a plugin if there is some missing dependencies
    if ($dependencies_disabled) {
        $fake_checkbox = $checkbox;
        $fake_checkbox['#disabled'] = FALSE;
        $fake_checkbox['#title'] .= ' - Please enable missing dependencies to enable this plugin ! ';
        $checkbox['#access'] = FALSE;
        return $fake_checkbox;
    }
    return $checkbox;
}