/** * Preprocess variables for html.tpl.php * * @see system_elements() * @see html.tpl.php */ function omega_kickstart_preprocess_html(&$variables) { // Add conditional stylesheets for IE $theme_path = drupal_get_path('theme', 'omega_kickstart'); drupal_add_css($theme_path . '/css/ie-lte-8.css', array('group' => CSS_THEME, 'weight' => 20, 'browsers' => array('IE' => 'lte IE 8', '!IE' => FALSE), 'preprocess' => FALSE)); drupal_add_css($theme_path . '/css/ie-lte-7.css', array('group' => CSS_THEME, 'weight' => 21, 'browsers' => array('IE' => 'lte IE 7', '!IE' => FALSE), 'preprocess' => FALSE)); }
function manis_form_system_theme_settings_alter(&$form, $form_state) { $theme_path = drupal_get_path('theme', 'manis'); $form['settings'] = array('#type' => 'vertical_tabs', '#title' => t('Theme settings'), '#weight' => 2, '#collapsible' => TRUE, '#collapsed' => FALSE); $form['settings']['general_setting'] = array('#type' => 'fieldset', '#title' => t('General Settings'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['settings']['general_setting']['general_setting_tracking_code'] = array('#type' => 'textarea', '#title' => t('Tracking Code'), '#default_value' => theme_get_setting('general_setting_tracking_code', 'manis')); $form['settings']['header'] = array('#type' => 'fieldset', '#title' => t('Header settings'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['settings']['header']['header_style'] = array('#title' => t('Header style'), '#type' => 'select', '#options' => array('header1' => t('Header 1'), 'header2' => t('Header 2'), 'header3' => t('Header 3')), '#default_value' => theme_get_setting('header_style', 'manis')); $form['settings']['header']['phone_contact'] = array('#title' => t('Phone contact'), '#type' => 'textfield', '#default_value' => theme_get_setting('phone_contact', 'manis')); $form['settings']['header']['contact_email'] = array('#title' => t('Contact email'), '#type' => 'textfield', '#default_value' => theme_get_setting('contact_email', 'manis')); $form['settings']['header']['social_network'] = array('#title' => t('Header social network'), '#type' => 'textarea', '#default_value' => theme_get_setting('social_network', 'manis')); $form['settings']['blogs'] = array('#type' => 'fieldset', '#title' => t('Blogs'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['settings']['blogs']['blogs_list'] = array('#type' => 'select', '#title' => t('Blogs list style'), '#options' => array('style1' => t('Style 1'), 'style2' => t('Style 2')), '#default_value' => theme_get_setting('blogs_style', 'manis')); $form['settings']['footer'] = array('#type' => 'fieldset', '#title' => t('Footer settings'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['settings']['footer']['enable_footer_logo'] = array('#type' => 'select', '#title' => t('Enable footer logo'), '#options' => array('on' => t('ON'), 'off' => t('OFF')), '#default_value' => theme_get_setting('enable_footer_logo', 'manis')); $form['settings']['footer']['footer_copyright_message'] = array('#type' => 'textarea', '#title' => t('Footer copyright message'), '#default_value' => theme_get_setting('footer_copyright_message', 'manis')); $form['settings']['custom_css'] = array('#type' => 'fieldset', '#title' => t('Custom CSS'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['settings']['custom_css']['custom_css'] = array('#type' => 'textarea', '#title' => t('Custom CSS'), '#default_value' => theme_get_setting('custom_css', 'manis'), '#description' => t('<strong>Example:</strong><br/>h1 { font-family: \'Metrophobic\', Arial, serif; font-weight: 400; }')); $form['settings']['skin'] = array('#type' => 'fieldset', '#title' => t('Switcher Style'), '#collapsible' => TRUE, '#collapsed' => FALSE); //Disable Switcher style; $form['settings']['skin']['manis_disable_switch'] = array('#title' => t('Switcher style'), '#type' => 'select', '#options' => array('on' => t('ON'), 'off' => t('OFF')), '#default_value' => theme_get_setting('manis_disable_switch', 'manis')); $form['settings']['skin']['manis_layout'] = array('#title' => t('Layout'), '#type' => 'select', '#options' => array('wide' => t('Wide'), 'boxed' => t('Boxed')), '#default_value' => theme_get_setting('manis_layout', 'manis')); $form['settings']['skin']['manis_direction'] = array('#title' => t('Direction'), '#type' => 'select', '#options' => array('ltr' => t('LTR'), 'rtl' => t('RTL')), '#default_value' => theme_get_setting('manis_direction', 'manis')); $form['settings']['skin']['manis_style'] = array('#title' => t('Style'), '#type' => 'select', '#options' => array('light' => t('LIGHT'), 'dark' => t('DARK')), '#default_value' => theme_get_setting('manis_style', 'manis')); $form['settings']['skin']['manis_skin'] = array('#title' => t('Skins'), '#type' => 'select', '#options' => array('default' => t('Default'), 'alimbalmarina' => t('Alimbalmarina'), 'juicy' => t('Juicy'), 'spoonflower_goats' => t('Spoonflower goats'), 'nutricap_keratin_vit' => t('Nutricap keratin vit'), 'courtly_attire' => t('Courtly attire'), 'mondrian' => t('Mondrian'), 'sage' => t('Sage'), 'walking_by' => t('Walking by')), '#default_value' => theme_get_setting('manis_skin', 'manis')); $form['settings']['skin']['background'] = array('#type' => 'fieldset', '#title' => t('Background style'), '#collapsible' => TRUE, '#collapsed' => FALSE); $form['settings']['skin']['background']['background_style'] = array('#title' => t('Use style'), '#type' => 'select', '#options' => array('pattern' => t('Pattern'), 'image' => t('Image')), '#default_value' => theme_get_setting('background_style', 'manis')); $form['settings']['skin']['background']['manis_bg_pattern'] = array('#title' => t('Bg pattern'), '#type' => 'select', '#options' => array('swirl_pattern' => t('Swirl pattern'), 'sativa' => t('Sativa'), 'dimension' => t('Dimension'), 'symphony' => t('Symphony'), 'black_lozenge' => t('Black lozenge'), 'congruent_outline' => t('Congruent outline'), 'dark_exa' => t('Dark exa'), 'office_pattern' => t('Office pattern')), '#default_value' => theme_get_setting('manis_bg_pattern', 'manis')); $form['settings']['skin']['background']['manis_bg_image'] = array('#title' => t('Bg image'), '#type' => 'select', '#options' => array('1' => t('1'), '2' => t('2'), '3' => t('3'), '4' => t('4'), '5' => t('5'), '6' => t('6'), '7' => t('7'), '8' => t('8')), '#default_value' => theme_get_setting('manis_bg_image', 'manis')); }
public function testFileParsing() { $filename = drupal_get_path('module', 'locale') . '/tests/locale_test.js'; // Parse the file to look for source strings. _locale_parse_js_file($filename); // Get all of the source strings that were found. $strings = $this->container->get('locale.storage')->getStrings(array('type' => 'javascript', 'name' => $filename)); $source_strings = array(); foreach ($strings as $string) { $source_strings[$string->source] = $string->context; } $etx = LOCALE_PLURAL_DELIMITER; // List of all strings that should be in the file. $test_strings = array('Standard Call t' => '', 'Whitespace Call t' => '', 'Single Quote t' => '', "Single Quote \\'Escaped\\' t" => '', 'Single Quote Concat strings t' => '', 'Double Quote t' => '', "Double Quote \\\"Escaped\\\" t" => '', 'Double Quote Concat strings t' => '', 'Context !key Args t' => 'Context string', 'Context Unquoted t' => 'Context string unquoted', 'Context Single Quoted t' => 'Context string single quoted', 'Context Double Quoted t' => 'Context string double quoted', "Standard Call plural{$etx}Standard Call @count plural" => '', "Whitespace Call plural{$etx}Whitespace Call @count plural" => '', "Single Quote plural{$etx}Single Quote @count plural" => '', "Single Quote \\'Escaped\\' plural{$etx}Single Quote \\'Escaped\\' @count plural" => '', "Double Quote plural{$etx}Double Quote @count plural" => '', "Double Quote \\\"Escaped\\\" plural{$etx}Double Quote \\\"Escaped\\\" @count plural" => '', "Context !key Args plural{$etx}Context !key Args @count plural" => 'Context string', "Context Unquoted plural{$etx}Context Unquoted @count plural" => 'Context string unquoted', "Context Single Quoted plural{$etx}Context Single Quoted @count plural" => 'Context string single quoted', "Context Double Quoted plural{$etx}Context Double Quoted @count plural" => 'Context string double quoted'); // Assert that all strings were found properly. foreach ($test_strings as $str => $context) { $args = array('%source' => $str, '%context' => $context); // Make sure that the string was found in the file. $this->assertTrue(isset($source_strings[$str]), String::format('Found source string: %source', $args)); // Make sure that the proper context was matched. $message = $context ? String::format('Context for %source is %context', $args) : String::format('Context for %source is blank', $args); $this->assertTrue(isset($source_strings[$str]) && $source_strings[$str] === $context, $message); } $this->assertEqual(count($source_strings), count($test_strings), 'Found correct number of source strings.'); }
/** * Generates a test feed and simulates last-modified and etags. * * @param $use_last_modified * Set TRUE to send a last modified header. * @param $use_etag * Set TRUE to send an etag. * @param Request $request * Information about the current HTTP request. * * @return \Symfony\Component\HttpFoundation\Response * A feed that forces cache validation. */ public function testFeed($use_last_modified, $use_etag, Request $request) { $response = new Response(); $last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT'); $etag = Crypt::hashBase64($last_modified); $if_modified_since = strtotime($request->server->get('HTTP_IF_MODIFIED_SINCE')); $if_none_match = stripslashes($request->server->get('HTTP_IF_NONE_MATCH')); // Send appropriate response. We respond with a 304 not modified on either // etag or on last modified. if ($use_last_modified) { $response->headers->set('Last-Modified', gmdate(DateTimePlus::RFC7231, $last_modified)); } if ($use_etag) { $response->headers->set('ETag', $etag); } // Return 304 not modified if either last modified or etag match. if ($last_modified == $if_modified_since || $etag == $if_none_match) { $response->setStatusCode(304); return $response; } // The following headers force validation of cache. $response->headers->set('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT'); $response->headers->set('Cache-Control', 'must-revalidate'); $response->headers->set('Content-Type', 'application/rss+xml; charset=utf-8'); // Read actual feed from file. $file_name = drupal_get_path('module', 'aggregator_test') . '/aggregator_test_rss091.xml'; $handle = fopen($file_name, 'r'); $feed = fread($handle, filesize($file_name)); fclose($handle); $response->setContent($feed); return $response; }
/** * Tests if installed config is equal to the exported config. * * @dataProvider providerTestModuleConfig */ public function testModuleConfig($module) { /** @var \Drupal\Core\Extension\ModuleInstallerInterface $module_installer */ $module_installer = $this->container->get('module_installer'); /** @var \Drupal\Core\Config\StorageInterface $active_config_storage */ $active_config_storage = $this->container->get('config.storage'); /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */ $config_manager = $this->container->get('config.manager'); $module_installer->install([$module]); // System and user are required in order to be able to install some of the // other modules. Therefore they are put into static::$modules, which though // doesn't install config files, so import those config files explicitly. switch ($module) { case 'system': case 'user': $this->installConfig([$module]); break; } $default_install_path = drupal_get_path('module', $module) . '/' . InstallStorage::CONFIG_INSTALL_DIRECTORY; $module_config_storage = new FileStorage($default_install_path, StorageInterface::DEFAULT_COLLECTION); // The following config entries are changed on module install, so compare // them doesn't make sense. $skipped_config = []; $skipped_config['locale.settings'][] = 'path: '; $skipped_config['syslog.settings'][] = 'facility: '; // @todo Figure out why simpletest.settings is not installed. $skipped_config['simpletest.settings'] = TRUE; // Compare the installed config with the one in the module directory. foreach ($module_config_storage->listAll() as $config_name) { $result = $config_manager->diff($module_config_storage, $active_config_storage, $config_name); $this->assertConfigDiff($result, $config_name, $skipped_config); } }
/** * Function is used to render a test harness for the API. */ static function CallAPI() { global $conf; if ($_GET['submit'] == 1) { $host = $conf['check_book']['data_feeds']['site_url']; $url = $host . '/api?wsdl'; $xml = $_POST['txtInput']; $ch = curl_init($url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $response = curl_exec($ch); curl_close($ch); $xml = simplexml_load_string($response); $json = json_encode($xml); $array = json_decode($json, TRUE); $html = self::render_xml_data($array); echo $html; } else { $domain = 'spending_oge'; $xml = file_get_contents(realpath(drupal_get_path('module', 'checkbook_api')) . "/sample/" . strtolower($domain) . ".xml"); echo '<form action="api-test?submit=1" method="post">'; echo 'Paste Input Here:<br>'; echo '<textarea name="txtInput" rows="20" columns="40" style="height: 100%;">' . $xml . '</textarea>'; echo '<br>'; echo '<br><br>'; echo '<input type="submit" value="Submit">'; echo '</form> '; } }
/** * implements hook_preprocess_page() * **/ function odsherredweb_preprocess_page(&$variables) { $current_theme = variable_get('theme_default', 'none'); // Search form $variables['simple_navigation_search'] = module_invoke('search', 'block_view', 'search'); // Navigation $variables['sidebar_borger'] = _bellcom_generate_menu('menu-indhold', 'sidebar'); $variables['sidebar_erhverv'] = _bellcom_generate_menu('menu-erhverv', 'sidebar'); $variables['sidebar_politik'] = _bellcom_generate_menu('menu-politik', 'sidebar'); // Add the site structure term id to the page div $node = node_load(arg(1)); if (is_object($node) && isset($node->field_os2web_spotbox_sitestruct)) { $termParents = taxonomy_get_parents($node->field_os2web_spotbox_sitestruct[LANGUAGE_NONE][0]['tid']); $termId = 'tid-' . $node->field_os2web_spotbox_sitestruct[LANGUAGE_NONE][0]['tid']; $termIdParent = ""; if (!empty($termParents)) { $termIdParent = 'tid-' . key($termParents); } $variables['attributes_array']['class'] = $termIdParent . ' ' . $termId; } // Paths $variables['path_js'] = base_path() . drupal_get_path('theme', $current_theme) . '/js'; $variables['path_img'] = base_path() . drupal_get_path('theme', $current_theme) . '/images'; $variables['path_css'] = base_path() . drupal_get_path('theme', $current_theme) . '/css'; $variables['path_font'] = base_path() . drupal_get_path('theme', $current_theme) . '/font'; }
/** * Callback for $element['#process'] * Create one textfield element per rule. * * @param array $element * @param array $form_state * @return array */ function process($element, $form_state) { /** @var crumbs_PluginSystem_PluginInfo $info */ $info = $element['#crumbs_plugin_info']; $available_keys_meta = $info->availableKeysMeta; // Set up table rows /** @var crumbs_Container_MultiWildcardDataOffset $meta */ foreach ($available_keys_meta as $key => $meta) { $element[$key] = array('#type' => 'textfield', '#size' => 10, '#default_value' => 'inherit', '#class' => array('crumbs-weight-element'), '#crumbs_rule_info' => $meta); if (isset($element['#value'][$key])) { $v = $element['#value'][$key]; if (FALSE === $v) { $v = 'disabled'; } elseif (-1 === $v || '-1' === $v) { $v = 'auto'; } $element[$key]['#default_value'] = $v; } } // Calculate md5 hashes for keys, because javascript sucks at it. $keys_md5 = array(); foreach ($available_keys_meta as $key => $meta) { $keys_md5[$key] = md5($key); } $settings['crumbs']['default_weights'] = $element['#crumbs_plugin_info']->defaultWeights; $settings['crumbs']['keys_md5'] = $keys_md5; $element['#attached']['js'][] = array('data' => $settings, 'type' => 'setting'); $element['#attached']['js'][] = drupal_get_path('module', 'crumbs') . '/js/crumbs.admin.expansible.js'; $element['#attached']['css'][] = drupal_get_path('module', 'crumbs') . '/css/crumbs.admin.expansible.css'; return $element; }
/** * Test validation of the User-Agent header we use to perform test requests. */ public function testUserAgentValidation() { global $base_url; // Logout the user which was logged in during test-setup. $this->drupalLogout(); $system_path = $base_url . '/' . drupal_get_path('module', 'system'); $HTTP_path = $system_path . '/tests/http.php/user/login'; $https_path = $system_path . '/tests/https.php/user/login'; // Generate a valid simpletest User-Agent to pass validation. $this->assertTrue(preg_match('/simpletest\\d+/', $this->databasePrefix, $matches), 'Database prefix contains simpletest prefix.'); $test_ua = drupal_generate_test_ua($matches[0]); $this->additionalCurlOptions = array(CURLOPT_USERAGENT => $test_ua); // Test pages only available for testing. $this->drupalGet($HTTP_path); $this->assertResponse(200, 'Requesting http.php with a legitimate simpletest User-Agent returns OK.'); $this->drupalGet($https_path); $this->assertResponse(200, 'Requesting https.php with a legitimate simpletest User-Agent returns OK.'); // Now slightly modify the HMAC on the header, which should not validate. $this->additionalCurlOptions = array(CURLOPT_USERAGENT => $test_ua . 'X'); $this->drupalGet($HTTP_path); $this->assertResponse(403, 'Requesting http.php with a bad simpletest User-Agent fails.'); $this->drupalGet($https_path); $this->assertResponse(403, 'Requesting https.php with a bad simpletest User-Agent fails.'); // Use a real User-Agent and verify that the special files http.php and // https.php can't be accessed. $this->additionalCurlOptions = array(CURLOPT_USERAGENT => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12'); $this->drupalGet($HTTP_path); $this->assertResponse(403, 'Requesting http.php with a normal User-Agent fails.'); $this->drupalGet($https_path); $this->assertResponse(403, 'Requesting https.php with a normal User-Agent fails.'); }
/** * Creates a node, then tests the statistics tokens generated from it. */ function testStatisticsTokenReplacement() { $language_interface = \Drupal::languageManager()->getCurrentLanguage(); // Create user and node. $user = $this->drupalCreateUser(array('create page content')); $this->drupalLogin($user); $node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $user->id())); // Hit the node. $this->drupalGet('node/' . $node->id()); // Manually calling statistics.php, simulating ajax behavior. $nid = $node->id(); $post = http_build_query(array('nid' => $nid)); $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $client = \Drupal::service('http_client_factory')->fromOptions(['config/curl' => [CURLOPT_TIMEOUT => 10]]); $client->post($stats_path, array('headers' => $headers, 'body' => $post)); $statistics = statistics_get($node->id()); // Generate and test tokens. $tests = array(); $tests['[node:total-count]'] = 1; $tests['[node:day-count]'] = 1; $tests['[node:last-view]'] = format_date($statistics['timestamp']); $tests['[node:last-view:short]'] = format_date($statistics['timestamp'], 'short'); // Test to make sure that we generated something for each token. $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.'); foreach ($tests as $input => $expected) { $output = \Drupal::token()->replace($input, array('node' => $node), array('langcode' => $language_interface->getId())); $this->assertEqual($output, $expected, format_string('Statistics token %token replaced.', array('%token' => $input))); } }
/** * Tests #attached functionality in children elements. */ function testDrupalRenderChildrenAttached() { // The cache system is turned off for POST requests. $request_method = \Drupal::request()->getMethod(); \Drupal::request()->setMethod('GET'); // Create an element with a child and subchild. Each element loads a // different JavaScript file using #attached. $parent_js = drupal_get_path('module', 'user') . '/user.js'; $child_js = drupal_get_path('module', 'forum') . '/forum.js'; $subchild_js = drupal_get_path('module', 'book') . '/book.js'; $element = array('#type' => 'details', '#open' => TRUE, '#cache' => array('keys' => array('simpletest', 'drupal_render', 'children_attached')), '#attached' => array('js' => array($parent_js)), '#title' => 'Parent'); $element['child'] = array('#type' => 'details', '#open' => TRUE, '#attached' => array('js' => array($child_js)), '#title' => 'Child'); $element['child']['subchild'] = array('#attached' => array('js' => array($subchild_js)), '#markup' => 'Subchild'); // Render the element and verify the presence of #attached JavaScript. drupal_render($element); $scripts = drupal_get_js(); $this->assertTrue(strpos($scripts, $parent_js), 'The element #attached JavaScript was included.'); $this->assertTrue(strpos($scripts, $child_js), 'The child #attached JavaScript was included.'); $this->assertTrue(strpos($scripts, $subchild_js), 'The subchild #attached JavaScript was included.'); // Load the element from cache and verify the presence of the #attached // JavaScript. drupal_static_reset('_drupal_add_js'); $element = array('#cache' => array('keys' => array('simpletest', 'drupal_render', 'children_attached'))); $this->assertTrue(strlen(drupal_render($element)) > 0, 'The element was retrieved from cache.'); $scripts = drupal_get_js(); $this->assertTrue(strpos($scripts, $parent_js), 'The element #attached JavaScript was included when loading from cache.'); $this->assertTrue(strpos($scripts, $child_js), 'The child #attached JavaScript was included when loading from cache.'); $this->assertTrue(strpos($scripts, $subchild_js), 'The subchild #attached JavaScript was included when loading from cache.'); // Restore the previous request method. \Drupal::request()->setMethod($request_method); }
/** * Implements theme_settings(). */ function radix_form_system_theme_settings_alter(&$form, &$form_state) { $theme_path = drupal_get_path('theme', 'sizzle'); // Ensure this include file is loaded when the form is rebuilt from the cache. $form_state['build_info']['files']['form'] = $theme_path . '/theme-settings.php'; // Hide all theme settings $form['theme_settings']['#access'] = FALSE; // Add theme settings here. $form['default_theme_settings'] = array('#title' => t('Theme Settings'), '#type' => 'vertical_tabs'); $form['layout'] = array('#type' => 'fieldset', '#title' => t('Layout'), '#collapsible' => TRUE, '#group' => 'default_theme_settings'); $form['layout']['site_width'] = array('#title' => t('Width'), '#type' => 'radios', '#options' => array('full' => t('Full width'), 'boxed' => t('Boxed')), '#default_value' => theme_get_setting('site_width')); // Site background image. $form['layout']['site_background_image'] = array('#title' => t('Background image'), '#type' => 'managed_file', '#description' => t('The background image to use for the site.'), '#upload_location' => 'public://', '#theme' => 'restaurant_admin_thumbnail', '#default_value' => theme_get_setting('site_background_image')); // Create a branding group and move logo and favicon to it. $form['branding'] = array('#type' => 'fieldset', '#title' => t('Branding'), '#collapsible' => TRUE, '#group' => 'default_theme_settings'); $form['logo']['#group'] = 'branding'; $form['favicon']['#group'] = 'branding'; // Footer. $form['footer'] = array('#type' => 'fieldset', '#title' => t('Footer'), '#collapsible' => TRUE, '#group' => 'default_theme_settings'); // Footer background image. $form['footer']['footer_background_image'] = array('#title' => t('Background image'), '#type' => 'managed_file', '#description' => t('The background image to use for the site footer.'), '#upload_location' => 'public://', '#theme' => 'restaurant_admin_thumbnail', '#default_value' => theme_get_setting('footer_background_image')); // Footer text. $footer_text = theme_get_setting('footer_text'); $form['footer']['footer_text'] = array('#title' => t('Footer text'), '#type' => 'text_format', '#format' => $footer_text['format'], '#default_value' => $footer_text['value']); $form['footer']['show_footer_nav'] = array('#title' => t('Show the footer nav?'), '#type' => 'checkbox', '#default_value' => theme_get_setting('show_footer_nav')); // Copyright. $copyright = theme_get_setting('copyright'); $form['footer']['copyright'] = array('#title' => t('Copyright'), '#type' => 'text_format', '#format' => $copyright['format'], '#default_value' => $copyright['value']); // Add a custom submit handler. $form['#submit'][] = 'sizzle_form_system_theme_settings_submit'; // Return the additional form widgets. return $form; }
/** * Add items to the toolbar menu. * * The toolbar is a container for administrative and site-global interactive * components. * * The toolbar provides a common styling for items denoted by the * .toolbar-tab class. * * The toolbar provides a construct called a 'tray'. The tray is a container * for content. The tray may be associated with a toggle in the administration * bar. The toggle shows or hides the tray and is optimized for small and * large screens. To create this association, hook_toolbar() returns one or * more render elements of type 'toolbar_item', containing the toggle and tray * elements in its 'tab' and 'tray' properties. * * The following properties are available: * - 'tab': A renderable array. * - 'tray': Optional. A renderable array. * - '#weight': Optional. Integer weight used for sorting toolbar items in * administration bar area. * * This hook is invoked in toolbar_pre_render(). * * @return * An array of toolbar items, keyed by unique identifiers such as 'home' or * 'administration', or the short name of the module implementing the hook. * The corresponding value is a render element of type 'toolbar_item'. * * @see toolbar_pre_render() * @ingroup toolbar_tabs */ function hook_toolbar() { $items = array(); // Add a search field to the toolbar. The search field employs no toolbar // module theming functions. $items['global_search'] = array('#type' => 'toolbar_item', 'tab' => array('#type' => 'search', '#attributes' => array('placeholder' => t('Search the site'), 'class' => array('search-global'))), '#weight' => 200, '#attached' => array('css' => array(drupal_get_path('module', 'search') . '/css/search.base.css'))); // The 'Home' tab is a simple link, which is wrapped in markup associated // with a visual tab styling. $items['home'] = array('#type' => 'toolbar_item', 'tab' => array('#type' => 'link', '#title' => t('Home'), '#url' => Url::fromRoute('<front>'), '#options' => array('attributes' => array('title' => t('Home page'), 'class' => array('toolbar-icon', 'toolbar-icon-home')))), '#weight' => -20); // A tray may be associated with a tab. // // When the tab is activated, the tray will become visible, either in a // horizontal or vertical orientation on the screen. // // The tray should contain a renderable array. An optional #heading property // can be passed. This text is written to a heading tag in the tray as a // landmark for accessibility. $items['commerce'] = array('#type' => 'toolbar_item', 'tab' => array('#type' => 'link', '#title' => t('Shopping cart'), '#url' => Url::fromRoute('cart'), '#options' => array('html' => FALSE, 'attributes' => array('title' => t('Shopping cart')))), 'tray' => array('#heading' => t('Shopping cart actions'), 'shopping_cart' => array('#theme' => 'item_list', '#items' => array())), '#weight' => 150); // The tray can be used to render arbritrary content. // // A renderable array passed to the 'tray' property will be rendered outside // the administration bar but within the containing toolbar element. // // If the default behavior and styling of a toolbar tray is not desired, one // can render content to the toolbar element and apply custom theming and // behaviors. $items['user_messages'] = array('#type' => 'toolbar_item', 'tab' => array('#type' => 'link', '#theme' => 'user_message_toolbar_tab', '#theme_wrappers' => array(), '#title' => t('Messages'), '#url' => Url::fromRoute('user.message'), '#options' => array('attributes' => array('title' => t('Messages')))), 'tray' => array('#heading' => t('User messages'), 'messages' => array()), '#weight' => 125); return $items; }
/** * Add the comic strip name right above the body field. */ function whaleocalypse_preprocess_field(&$vars) { if (isset($vars['element']['#bundle']) && $vars['element']['#bundle'] == 'comic' && isset($vars['element']['#field_name']) && $vars['element']['#field_name'] == 'body') { $vars['label'] = $vars['element']['#object']->title; } //Add the transcript expand js if the field is populated if ($vars['element']['#field_name'] == 'field_transcript') { drupal_add_js(drupal_get_path('theme', 'whaleocalypse') . '/js/expand-transcript.js', array('scope' => 'footer', 'type' => 'file')); } //Create the custom "story arc" functionality if (isset($vars['element']['#field_name']) && $vars['element']['#field_name'] == 'field_story_arc') { $tid = $vars['element']['#object']->field_story_arc[LANGUAGE_NONE][0]['tid']; $nid = $vars['element']['#object']->nid; $story_arc_count = new EntityFieldQuery(); $vars['story_arc_count'] = $story_arc_count->entityCondition('entity_type', 'node')->entityCondition('bundle', 'comic')->fieldCondition('field_story_arc', 'tid', $tid, '=')->count()->execute(); $story_arc_position = new EntityFieldQuery(); $story_arc_position = $story_arc_position->entityCondition('entity_type', 'node')->entityCondition('bundle', 'comic')->fieldCondition('field_story_arc', 'tid', $tid, '=')->propertyOrderBy('created', 'ASC')->execute(); $vars['story_arc_position'] = array_search($nid, array_keys($story_arc_position['node'])) + 1; } //Add the author URL if it is set. if (isset($vars['element']['#field_name']) && $vars['element']['#field_name'] == 'field_contributing_author') { if (isset($vars['element']['#object']->field_contributing_author_url[LANGUAGE_NONE][0])) { $vars['items'][0]['#markup'] = l($vars['items'][0]['#markup'], $vars['element']['#object']->field_contributing_author_url[LANGUAGE_NONE][0]['value'], array("attributes" => array("target" => "_blank"))); } $vars['call_to_action'] = 'You can ' . l('write your own whaleocalypse too.', 'node/169', array()); } }
/** * Implements hook_preprocess_maintenance_page(). */ function bartik_preprocess_maintenance_page(&$variables) { if (!$variables['db_is_active']) { unset($variables['site_name']); } drupal_add_css(drupal_get_path('theme', 'bartik') . '/css/maintenance-page.css'); }
/** * Verifies node hit counter logging and script placement. */ function testLogging() { $path = 'node/' . $this->node->id(); $module_path = drupal_get_path('module', 'statistics'); $stats_path = base_path() . $module_path . '/statistics.php'; $lib_path = base_path() . $module_path . '/statistics.js'; $expected_library = '/<script src=".*?' . preg_quote($lib_path, '/.') . '.*?">/is'; // Verify that logging scripts are not found on a non-node page. $this->drupalGet('node'); $settings = $this->getDrupalSettings(); $this->assertNoPattern($expected_library, 'Statistics library JS not found on node page.'); $this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.'); // Verify that logging scripts are not found on a non-existent node page. $this->drupalGet('node/9999'); $settings = $this->getDrupalSettings(); $this->assertNoPattern($expected_library, 'Statistics library JS not found on non-existent node page.'); $this->assertFalse(isset($settings['statistics']), 'Statistics settings not found on node page.'); // Verify that logging scripts are found on a valid node page. $this->drupalGet($path); $settings = $this->getDrupalSettings(); $this->assertPattern($expected_library, 'Found statistics library JS on node page.'); $this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on node page.'); // Verify the same when loading the site in a non-default language. $this->drupalGet($this->language['langcode'] . '/' . $path); $settings = $this->getDrupalSettings(); $this->assertPattern($expected_library, 'Found statistics library JS on a valid node page in a non-default language.'); $this->assertIdentical($this->node->id(), $settings['statistics']['data']['nid'], 'Found statistics settings on valid node page in a non-default language.'); // Manually call statistics.php to simulate ajax data collection behavior. global $base_root; $post = array('nid' => $this->node->id()); $this->client->post($base_root . $stats_path, array('form_params' => $post)); $node_counter = statistics_get($this->node->id()); $this->assertIdentical($node_counter['totalcount'], '1'); }
/** * {@inheritdoc} */ public function render(ResultRow $values) { $value = parent::render($values); switch ($value) { case LocalTaskItemInterface::STATUS_PENDING: $label = t('Untranslated'); $icon = drupal_get_path('module', 'tmgmt') . '/icons/ready.svg'; break; case LocalTaskItemInterface::STATUS_COMPLETED: $label = t('Translated'); $icon = drupal_get_path('module', 'tmgmt') . '/icons/gray-check.svg'; break; case LocalTaskItemInterface::STATUS_REJECTED: $label = t('Rejected'); $icon = drupal_get_path('module', 'tmgmt') . '/icons/rejected.svg'; break; case LocalTaskItemInterface::STATUS_CLOSED: $label = t('Completed'); $icon = 'core/misc/icons/73b355/check.svg'; break; default: $label = t('Untranslated'); $icon = drupal_get_path('module', 'tmgmt') . '/icons/ready.svg'; } $element = ['#type' => 'inline_template', '#template' => '<img src="{{ icon }}" title="{{ label }}"><span></span></img>', '#context' => array('icon' => file_create_url($icon), 'label' => $label)]; return \Drupal::service('renderer')->render($element); }
function loadcss($styles) { $program_module_path = drupal_get_path('module', 'program'); foreach ($styles as $style) { drupal_add_css($program_module_path . $style, array('group' => CSS_DEFAULT, 'type' => 'file')); } }
/** * Expand module source * * @param string $source * * return string[] */ protected final function expandSource($source) { if (false === strpos($source, ':')) { return [$source => $source]; } $ret = []; // This is a source from a module list($module, $target) = explode(':', $source, 2); if (!module_exists($module)) { throw new \InvalidArgumentException(sprintf("'%s' module is not enable or does not exist", $module)); } $list = $this->getModuleList(); if (!isset($list[$module])) { throw new \InvalidArgumentException(sprintf("'%s' module does not declare any synchronization sources", $module)); } $targets = []; // This is valid, user asked module: without any target defined, the // whole module will be imported if (empty($target)) { $targets = $list[$module]; } else { if (!in_array($target, $list[$module])) { throw new \InvalidArgumentException(sprintf("'%s' module: '%s' source is not declared", $module, $target)); } else { $targets = [$target]; } } $path = drupal_get_path('module', $module); foreach ($targets as $target) { $ret[$module . ':' . $target] = $path . '/' . $target; } return $ret; }
/** * hook_wysiwyg_plugin(). Return an array of editor plugins. * * @todo Completely outdated; rewrite necessary. * * Each wysiwyg editor as well as each contrib module implementing an editor * plugin has to return an associative array of available plugins. Each module * can add one or more plugins and editor buttons. * * Notes for TinyMCE: * A module is able to override almost all TinyMCE initialization settings. * However, modules should only make use of that if a plugin really needs to, * because customized configuration settings may clash with overrides by another * module. TinyMCE automatically assigns the baseURL of your plugin to the plugin * object. If you need to load or access additional files from your plugin * directory, retrieve the path via this.baseURL. tinyMCE.baseURL returns the * path of TinyMCE and not your module. For example: * @code * initInstance: function(inst) { * tinyMCE.importCSS(inst.getDoc(), this.baseURL + '/myplugin.css'); * }, * @endcode * * @param string $editor * An (lowercase) editor name to return plugins for. * * @return array * An associative array having internal plugin names as keys, an array of * plugin meta-information as values: * - type: 'external' (optional); if omitted, wysiwyg editors will likely * search for the plugin in their own plugins folder. * - title: A human readable title of the plugin. * - description: A (one-line) description of the plugin. * - path: The patch to the javascript plugin. * - callback: A Drupal menu callback returning the plugin UI. A plugin * should return a callback *or* a path. * - icon: An icon (usually 16x16 pixels) for the plugin button (optional). * - ... Any other custom editor settings (optional). * * @todo Move this template into hooks.php. */ function hook_wysiwyg_plugin($editor) { switch ($editor) { case 'tinymce': return array('myplugin' => array('type' => 'external', 'title' => t('My plugin title'), 'description' => t('My plugin title'), 'path' => drupal_get_path('module', 'mymodule') . '/myplugin', 'callback' => url('myplugin/browse'), 'icon' => drupal_get_path('module', 'mymodule') . '/myplugin/myplugin.png', 'extended_valid_elements' => array('tag[attribute1|attribute2=default_value]'), 'theme_advanced_buttons1' => array(t('Button title (optional)') => 'myplugin'))); } }
/** * Add link to view full-sized image in colorbox and add caption */ function gettysw_preprocess_field(&$vars, $hook) { foreach ($vars['element']['#items'] as $delta => $item) { if (!empty($vars['element'][$delta])) { if (module_exists('image_field_caption') && isset($item['image_field_caption'])) { $vars['items'][$delta]['caption'] = check_markup($item['image_field_caption']['value'], $item['image_field_caption']['format']); } if ($vars['element']['#field_name'] == 'field_image' && isset($item['uri']) && module_exists('colorbox') && empty($vars['element']['#object']->is_export)) { $vars['items'][$delta]['colorbox_link'] = '<a class="colorbox" href="' . file_create_url($item['uri']) . '">Expand Image</a>'; } if ($vars['element']['#field_name'] == 'field_image_reference_info' && $vars['element']['#view_mode'] == 'full') { drupal_add_css(drupal_get_path('module', 'lighttable') . '/lighttable.css'); $vars['content_attributes_array'] = array('id' => 'lighttable'); foreach ($vars['items'] as $delta => $item) { $fc_item = reset($vars['items'][$delta]['entity']['field_collection_item']); $image_entity = $fc_item['#entity']->field_image_reference[LANGUAGE_NONE][0]['entity']; $file_nodes = file_usage_list($image_entity); $image_node = node_load(key($file_nodes['file']['node'])); $vars['items'][$delta]['entity']['field_collection_item']['title'] = array('#markup' => '<span class="field-title">' . $image_node->title . '</span>', '#weight' => -1); $left = $fc_item['#entity']->field_x_pos[LANGUAGE_NONE][0]['value']; $top = $fc_item['#entity']->field_y_pos[LANGUAGE_NONE][0]['value']; $width = $fc_item['#entity']->field_width[LANGUAGE_NONE][0]['value']; $height = $fc_item['#entity']->field_height[LANGUAGE_NONE][0]['value']; $vars['items'][$delta]['#attributes']['style'] = "position: absolute; top: {$top}px; left: {$left}px; width: {$width}px; height: {$height}px;"; $vars['items'][$delta]['#attributes']['class'][] = 'lighttable-image-container'; } } } } }
/** hook_preprocess_page(&$variables) */ function gitp_preprocess_page(&$variables) { $path = drupal_get_path('theme', 'gitp'); if ($variables['theme_hook_suggestions'][0] == 'page__taxonomy') { drupal_add_js('/' . $path . '/assets/js/init-bs-popover.js', 'file'); } }
/** * Contrast operations test. */ public function doTestContrastOperations() { $image_factory = $this->container->get('image.factory'); $image_toolkit_id = $image_factory->getToolkitId(); // Test on the PNG test image. $test_file = drupal_get_path('module', 'simpletest') . '/files/image-test.png'; $original_uri = file_unmanaged_copy($test_file, 'public://', FILE_EXISTS_RENAME); $generated_uri = 'public://styles/image_effects_test/public/' . \Drupal::service('file_system')->basename($original_uri); // Test data. $test_data = ['0' => [$this->red, $this->green, $this->transparent, $this->blue], '-50' => [$image_toolkit_id === 'imagemagick' ? array(180, 75, 75, 0) : array(159, 95, 95, 0), $image_toolkit_id === 'imagemagick' ? array(75, 180, 75, 0) : array(95, 159, 95, 0), $this->transparent, $image_toolkit_id === 'imagemagick' ? array(75, 75, 180, 0) : array(95, 95, 159, 0)], '-100' => [$image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0), $image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0), $this->transparent, $image_toolkit_id === 'imagemagick' ? array(128, 128, 128, 0) : array(127, 127, 127, 0)], '50' => [array(255, 0, 0, 0), array(0, 255, 0, 0), $this->transparent, array(0, 0, 255, 0)], '100' => [array(255, 0, 0, 0), array(0, 255, 0, 0), $this->transparent, array(0, 0, 255, 0)]]; foreach ($test_data as $key => $colors) { // Add contrast effect to the test image style. $effect = ['id' => 'image_effects_contrast', 'data' => ['level' => $key]]; $uuid = $this->addEffectToTestStyle($effect); // Load Image Style. $image_style = ImageStyle::load('image_effects_test'); // Check that ::applyEffect generates image with expected contrast. $image_style->createDerivative($original_uri, $image_style->buildUri($original_uri)); $image = $image_factory->get($generated_uri, 'gd'); $this->assertTrue($this->colorsAreEqual($colors[0], $this->getPixelColor($image, 0, 0))); $this->assertTrue($this->colorsAreEqual($colors[1], $this->getPixelColor($image, 39, 0))); $this->assertTrue($this->colorsAreEqual($colors[2], $this->getPixelColor($image, 0, 19))); $this->assertTrue($this->colorsAreEqual($colors[3], $this->getPixelColor($image, 39, 19))); // Remove effect. $uuid = $this->removeEffectFromTestStyle($uuid); } }
/** * Display a view as a grid style. */ function reset_preprocess_views_view_grid(&$vars) { drupal_add_css(drupal_get_path('theme', 'reset') . '/css/views-view-grid.css'); foreach (element_children($vars['row_classes']) as $key => $value) { $vars['row_classes'][$key] .= 'view-grid-row has-' . $vars['options']['columns'] . '-cols'; } }
/** * CTools plugin API hook for Context. Note that a proper entry in * hook_ctools_plugin_api() must exist for this hook to be called. */ function hook_context_plugins() { $plugins = array(); $plugins['foo_context_condition_bar'] = array('handler' => array('path' => drupal_get_path('module', 'foo') . '/plugins', 'file' => 'foo_context_condition_bar.inc', 'class' => 'foo_context_condition_bar', 'parent' => 'context_condition')); $plugins['foo_context_reaction_baz'] = array('handler' => array('path' => drupal_get_path('module', 'foo') . '/plugins', 'file' => 'foo_context_reaction_baz.inc', 'class' => 'foo_context_reaction_baz', 'parent' => 'context_reaction')); return $plugins; }
/** * Implementation of THEMEHOOK_settings() function. * * @param $saved_settings * An array of saved settings for this theme. * @param $subtheme_defaults * Allow a subtheme to override the default values. * @return * A form array. */ function zen_settings($saved_settings, $subtheme_defaults = array()) { // Add the form's CSS drupal_add_css(drupal_get_path('theme', 'zen') . '/theme-settings.css', 'theme'); // Add javascript to show/hide optional settings drupal_add_js(drupal_get_path('theme', 'zen') . '/theme-settings.js', 'theme'); // Get the default values from the .info file. $defaults = zen_theme_get_default_settings('zen'); // Allow a subtheme to override the default values. $defaults = array_merge($defaults, $subtheme_defaults); // Merge the saved variables and their default values. $settings = array_merge($defaults, $saved_settings); /* * Create the form using Forms API */ $form['zen-div-opening'] = array('#value' => '<div id="zen-settings">'); $form['zen_block_editing'] = array('#type' => 'checkbox', '#title' => t('Show block editing on hover'), '#description' => t('When hovering over a block, privileged users will see block editing links.'), '#default_value' => $settings['zen_block_editing']); $form['breadcrumb'] = array('#type' => 'fieldset', '#title' => t('Breadcrumb settings'), '#attributes' => array('id' => 'zen-breadcrumb')); $form['breadcrumb']['zen_breadcrumb'] = array('#type' => 'select', '#title' => t('Display breadcrumb'), '#default_value' => $settings['zen_breadcrumb'], '#options' => array('yes' => t('Yes'), 'admin' => t('Only in admin section'), 'no' => t('No'))); $form['breadcrumb']['zen_breadcrumb_separator'] = array('#type' => 'textfield', '#title' => t('Breadcrumb separator'), '#description' => t('Text only. Don’t forget to include spaces.'), '#default_value' => $settings['zen_breadcrumb_separator'], '#size' => 5, '#maxlength' => 10, '#prefix' => '<div id="div-zen-breadcrumb-collapse">'); $form['breadcrumb']['zen_breadcrumb_home'] = array('#type' => 'checkbox', '#title' => t('Show home page link in breadcrumb'), '#default_value' => $settings['zen_breadcrumb_home']); $form['breadcrumb']['zen_breadcrumb_trailing'] = array('#type' => 'checkbox', '#title' => t('Append a separator to the end of the breadcrumb'), '#default_value' => $settings['zen_breadcrumb_trailing'], '#description' => t('Useful when the breadcrumb is placed just before the title.')); $form['breadcrumb']['zen_breadcrumb_title'] = array('#type' => 'checkbox', '#title' => t('Append the content title to the end of the breadcrumb'), '#default_value' => $settings['zen_breadcrumb_title'], '#description' => t('Useful when the breadcrumb is not placed just before the title.'), '#suffix' => '</div>'); $form['themedev'] = array('#type' => 'fieldset', '#title' => t('Theme development settings'), '#attributes' => array('id' => 'zen-themedev')); $form['themedev']['zen_rebuild_registry'] = array('#type' => 'checkbox', '#title' => t('Rebuild theme registry on every page.'), '#default_value' => $settings['zen_rebuild_registry'], '#description' => t('During theme development, it can be very useful to continuously <a href="!link">rebuild the theme registry</a>. WARNING: this is a huge performance penalty and must be turned off on production websites.', array('!link' => 'http://drupal.org/node/173880#theme-registry')), '#prefix' => '<div id="div-zen-registry"><strong>' . t('Theme registry:') . '</strong>', '#suffix' => '</div>'); $form['themedev']['zen_layout'] = array('#type' => 'radios', '#title' => t('Layout method'), '#options' => array('border-politics-liquid' => t('Liquid layout') . ' <small>(layout-liquid.css)</small>', 'border-politics-fixed' => t('Fixed layout') . ' <small>(layout-fixed.css)</small>'), '#default_value' => $settings['zen_layout']); $form['themedev']['zen_wireframes'] = array('#type' => 'checkbox', '#title' => t('Display borders around main layout elements'), '#default_value' => $settings['zen_wireframes'], '#description' => t('<a href="!link">Wireframes</a> are useful when prototyping a website.', array('!link' => 'http://www.boxesandarrows.com/view/html_wireframes_and_prototypes_all_gain_and_no_pain')), '#prefix' => '<div id="div-zen-wireframes"><strong>' . t('Wireframes:') . '</strong>', '#suffix' => '</div>'); $form['zen-div-closing'] = array('#value' => '</div>'); // Return the form return $form; }
/** * Validate form values. */ function at_generator_validate_generator(&$form, &$form_state) { $build_info = $form_state->getBuildInfo(); $values = $form_state->getValues(); $theme = $build_info['args'][0]; // Validate Theme Generator. if (!empty($values['generate']['generate_machine_name']) && $theme == 'at_core') { $machine_name = $values['generate']['generate_machine_name']; $path = drupal_get_path('theme', 'at_core'); $target = $path . '/../../' . $machine_name; $subtheme_type = $values['generate']['generate_type']; $skin_base_theme = $values['generate']['generate_skin_base']; $clone_source = $values['generate']['generate_clone_source']; if ($subtheme_type == 'at_standard' || $subtheme_type == 'at_minimal' || $subtheme_type == 'at_skin') { $source = $path . '/../at_starterkits/' . $subtheme_type; } else if ($subtheme_type == 'at_clone') { $clone_source_theme = drupal_get_path('theme', $clone_source); $source = $clone_source_theme; } // Check if directories and files exist and are readable/writable etc. if (!file_exists($source) && !is_readable($source)) { $form_state->setErrorByName('', t('The Starterkit or base theme (if you are generating a Skin) can not be found or is not readable - check permissions or perhaps you moved things around?')); } if (!is_writable(dirname($target))) { $form_state->setErrorByName('', t('The target directory is not writable, please check permissions on the <code>/themes/</code> directory where Adaptivetheme is located.')); } } }
/** * Allows modules to alter widget definitions. * * @param array $widgets * An array of widget definitions. */ function hook_views_flag_refresh_widgets_alter(&$widgets) { // NOTE: This code is for demonstration purposes only. We are probably better // off creating another widget. $widgets['throbber']['theme hook'] = 'betterThrobber'; $widgets['throbber']['js file'] = drupal_get_path('module', 'mymodule') . '/mymodule.js'; }
/** * Tests the "popular content" block. */ function testPopularContentBlock() { // Clear the block cache to load the Statistics module's block definitions. $this->container->get('plugin.manager.block')->clearCachedDefinitions(); // Visit a node to have something show up in the block. $node = $this->drupalCreateNode(array('type' => 'page', 'uid' => $this->blockingUser->id())); $this->drupalGet('node/' . $node->id()); // Manually calling statistics.php, simulating ajax behavior. $nid = $node->id(); $post = http_build_query(array('nid' => $nid)); $headers = array('Content-Type' => 'application/x-www-form-urlencoded'); global $base_url; $stats_path = $base_url . '/' . drupal_get_path('module', 'statistics') . '/statistics.php'; $client = \Drupal::service('http_client_factory')->fromOptions(['config/curl' => [CURLOPT_TIMEOUT => 10]]); $client->post($stats_path, array('headers' => $headers, 'body' => $post)); // Configure and save the block. $this->drupalPlaceBlock('statistics_popular_block', array('label' => 'Popular content', 'top_day_num' => 3, 'top_all_num' => 3, 'top_last_num' => 3)); // Get some page and check if the block is displayed. $this->drupalGet('user'); $this->assertText('Popular content', 'Found the popular content block.'); $this->assertText("Today's", "Found today's popular content."); $this->assertText('All time', 'Found the all time popular content.'); $this->assertText('Last viewed', 'Found the last viewed popular content.'); // statistics.module doesn't use node entities, prevent the node language // from being added to the options. $this->assertRaw(\Drupal::l($node->label(), $node->urlInfo('canonical', ['language' => NULL])), 'Found link to visited node.'); }
public function setup() { parent::setup(); drupal_install_modules(array('search', 'kasahorow', 'kentry', 'devel')); $this->path = drupal_get_path('module', 'kentry'); //Create a node and add some relations $this->relid = 'testrel'; $this->node1 = new stdClass(); $this->node2 = new stdClass(); $this->node3 = new stdClass(); $this->node4 = new stdClass(); $this->node5 = new stdClass(); $this->node1->title = 'Test node 1'; node_save($this->node1); $this->node2->title = 'Test node 2'; node_save($this->node2); $this->node3->title = 'Test node 3'; node_save($this->node3); $this->node4->title = 'Test node 4'; node_save($this->node4); $this->node5->title = 'Test node 5'; node_save($this->node5); //Outgoing link from node1 to node2: ancestor(node1) = node2 _kentry_add_link($this->node1, $this->node2, $this->relid); //Incoming link from node3 to node1: descendant(node1) = node3 _kentry_add_link($this->node3, $this->node1, $this->relid); // ancestor(node2) = node4 _kentry_add_link($this->node2, $this->node4, $this->relid); // descendant(node3) = node5 _kentry_add_link($this->node5, $this->node3, $this->relid); }