Example #1
1
 /**
  * Tests if a translated and tokenized string is properly escaped by Twig.
  *
  * In each assert* call we add a new line at the expected result to match the
  * newline at the end of the template file.
  */
 public function testLocalizedTokenizedString()
 {
     $tests_to_do = [1 => ['original' => 'Go to the <a href="[locale_test:security_test1]">frontpage</a>', 'replaced' => 'Go to the &lt;a href=&quot;javascript:alert(&amp;#039;Mooooh!&amp;#039;);&quot;&gt;frontpage&lt;/a&gt;'], 2 => ['original' => 'Hello <strong>[locale_test:security_test2]</strong>!', 'replaced' => 'Hello &lt;strong&gt;&amp;lt;script&amp;gt;alert(&amp;#039;Mooooh!&amp;#039;);&amp;lt;/script&amp;gt;&lt;/strong&gt;!']];
     foreach ($tests_to_do as $i => $test) {
         $original_string = $test['original'];
         $rendered_original_string = \Drupal::theme()->render('locale_test_tokenized', ['content' => $original_string]);
         // Twig assumes that strings are unsafe so it escapes them, and so the
         // original and the rendered version should be different.
         $this->assertNotEqual($rendered_original_string, $original_string . "\n", 'Security test ' . $i . ' before translation');
         // Pass the original string to the t() function to get it marked as safe.
         $safe_string = t($original_string);
         $rendered_safe_string = \Drupal::theme()->render('locale_test_tokenized', ['content' => $safe_string]);
         // t() function always marks the string as safe so it won't be escaped,
         // and should be the same as the original.
         $this->assertEqual($rendered_safe_string, $original_string . "\n", 'Security test ' . $i . ' after translation before token replacement');
         // Replace tokens in the safe string to inject it with dangerous content.
         // @see locale_test_tokens().
         $unsafe_string = \Drupal::token()->replace($safe_string);
         $rendered_unsafe_string = \Drupal::theme()->render('locale_test_tokenized', ['content' => $unsafe_string]);
         // Token replacement changes the string so it is not marked as safe
         // anymore. Check it is escaped the way we expect.
         $this->assertEqual($rendered_unsafe_string, $test['replaced'] . "\n", 'Security test ' . $i . ' after translation  after token replacement');
     }
 }
Example #2
0
 /**
  * Ensures Twig template cache setting can be overridden.
  */
 function testTwigCacheOverride()
 {
     $extension = twig_extension();
     $theme_handler = $this->container->get('theme_handler');
     $theme_handler->install(array('test_theme'));
     $theme_handler->setDefault('test_theme');
     // The registry still works on theme globals, so set them here.
     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->getActiveThemeByName('test_theme'));
     // Reset the theme registry, so that the new theme is used.
     $this->container->set('theme.registry', NULL);
     // Load array of Twig templates.
     // reset() is necessary to invalidate caches tagged with 'theme_registry'.
     $registry = $this->container->get('theme.registry');
     $registry->reset();
     $templates = $registry->getRuntime();
     // Get the template filename and the cache filename for
     // theme_test.template_test.html.twig.
     $info = $templates->get('theme_test_template_test');
     $template_filename = $info['path'] . '/' . $info['template'] . $extension;
     $cache_filename = $this->container->get('twig')->getCacheFilename($template_filename);
     // Navigate to the page and make sure the template gets cached.
     $this->drupalGet('theme-test/template-test');
     $this->assertTrue(PhpStorageFactory::get('twig')->exists($cache_filename), 'Cached Twig template found.');
     // Disable the Twig cache and rebuild the service container.
     $parameters = $this->container->getParameter('twig.config');
     $parameters['cache'] = FALSE;
     $this->setContainerParameter('twig.config', $parameters);
     $this->rebuildContainer();
     // This should return false after rebuilding the service container.
     $this->assertFalse($this->container->get('twig')->getCache(), 'Twig environment has caching disabled.');
 }
Example #3
0
  /**
   * @param $active_group_ids
   *
   * @return array
   */
  public function activeList($active_group_ids) {
    $active_group_ids = explode(',', $active_group_ids);
    /** @var \Drupal\block_visibility_groups\Entity\BlockVisibilityGroup[] $groups */
    $groups = $this->storage->loadMultiple($active_group_ids);

    $edit_links = [];
    foreach ($groups as $group) {
      $edit_links[] = [
        '#type' => 'container',

        'edit' => [
          '#type' => 'link',
          '#title' => $group->label(),
          '#url' => $group->urlInfo('edit-form'),
          '#suffix' => ' - ',
        ],
        'manage' => [
          '#type' => 'link',
          '#title' => t('Manage Blocks'),
          '#url' => Url::fromRoute('block.admin_display_theme', [
            'theme' => \Drupal::theme()->getActiveTheme()->getName(),
          ],
            [
              'query' => ['block_visibility_group' => $group->id()],
            ]
          ),
        ],

      ];
    }
    return $edit_links;
  }
Example #4
0
/**
 * Pre-processes variables for the "region" theme hook.
 *
 * See template for list of available variables.
 *
 * @see region.tpl.php
 *
 * @ingroup theme_preprocess
 */
function bootstrap_preprocess_region(&$variables)
{
    $region = $variables['elements']['#region'];
    $variables['region'] = $region;
    $variables['content'] = $variables['elements']['#children'];
    $theme = \Drupal::theme()->getActiveTheme()->getName();
    // Content region.
    if ($region === 'content') {
        // @todo is this actually used properly?
        $variables['theme_hook_suggestions'][] = 'region__no_wrapper';
    } elseif ($region === 'help' && !empty($variables['content'])) {
        $content = $variables['content'];
        $variables['content'] = array('icon' => array('#markup' => _bootstrap_icon('question-sign')), 'content' => array('#markup' => $content));
        $variables['attributes']['class'][] = 'alert';
        $variables['attributes']['class'][] = 'alert-info';
        $variables['attributes']['class'][] = 'messages';
        $variables['attributes']['class'][] = 'info';
    }
    // Support for "well" classes in regions.
    static $wells;
    if (!isset($wells)) {
        foreach (system_region_list($theme) as $name => $title) {
            $wells[$name] = bootstrap_setting('region_well-' . $name);
        }
    }
    if (!empty($wells[$region])) {
        $variables['attributes']['class'][] = $wells[$region];
    }
}
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installEntitySchema('user');
     // Set up a test theme that prints the user's mail field.
     \Drupal::service('theme_handler')->install(array('user_test_theme'));
     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('user_test_theme'));
     // Clear the theme registry.
     $this->container->set('theme.registry', NULL);
 }
 public function getSocialLinks()
 {
     //Base Path
     global $base_url;
     $theme_path = \Drupal::theme()->getActiveTheme()->getPath();
     //Get Current Path
     $current_path = \Drupal::service('path.current')->getPath();
     $path = \Drupal::service('path.alias_manager')->getAliasByPath($current_path);
     //Get Current Title
     $request = \Drupal::request();
     if ($route = $request->attributes->get(\Symfony\Cmf\Component\Routing\RouteObjectInterface::ROUTE_OBJECT)) {
         $title_object = \Drupal::service('title_resolver')->getTitle($request, $route);
         if (is_array($title_object)) {
             $title = $title_object['#markup'];
         } else {
             $title = $title_object;
         }
     }
     //ShareThis Key
     $settings = \Drupal::config('social_lite.settings');
     $key = $settings->get('api_key');
     $email = $settings->get('use_email');
     $print = $settings->get('use_print');
     $logo = null;
     $url_share = null;
     $url_email = null;
     $url_print = null;
     if ($settings->get('logo')) {
         $logo = '&img=' . $base_url . '/' . $theme_path . '/' . $settings->get('logo');
     }
     $share_icon = $settings->get('share_icon');
     $email_icon = $settings->get('email_icon');
     $print_icon = $settings->get('print_icon');
     //Check if the key has a value
     if (!empty($key)) {
         //Share URL
         $url_share = Url::fromUri("http://www.sharethis.com/share?url={$base_url}{$path}&title=" . $title . "{$logo}&pageInfo=%7B%22hostname%22%3A%22{$base_url}%22%2C%22publisher%22%3A%22{$key}%22%7D");
     }
     //If Email option is selected
     if ($email == 1) {
         //Email URL
         $url_email = Url::fromUri('mailto:?subject=' . $title . '&body=View Article ' . $base_url . $path);
     }
     //If Print option is selected
     if ($print == 1) {
         //Print URL
         $url_print = Url::fromUri($base_url . $path . '/#');
     }
     //Values to be passed to the block
     $content = array('url_share' => $url_share, 'url_email' => $url_email, 'url_print' => $url_print, 'theme_path' => $base_url . '/' . $theme_path, 'share_icon' => $share_icon, 'email_icon' => $email_icon, 'print_icon' => $print_icon);
     return $content;
 }
Example #7
0
 /**
  * Test that _theme() returns expected data types.
  */
 function testThemeDataTypes()
 {
     // theme_test_false is an implemented theme hook so \Drupal::theme() service should
     // return a string, even though the theme function itself can return anything.
     $foos = array('null' => NULL, 'false' => FALSE, 'integer' => 1, 'string' => 'foo');
     foreach ($foos as $type => $example) {
         $output = \Drupal::theme()->render('theme_test_foo', array('foo' => $example));
         $this->assertTrue(is_string($output), format_string('\\Drupal::theme() returns a string for data type !type.', array('!type' => $type)));
     }
     // suggestionnotimplemented is not an implemented theme hook so \Drupal::theme() service
     // should return FALSE instead of a string.
     $output = \Drupal::theme()->render(array('suggestionnotimplemented'), array());
     $this->assertIdentical($output, FALSE, '\\Drupal::theme() returns FALSE when a hook suggestion is not implemented.');
 }
 /**
  * Ensures that Stable overrides all relevant core templates.
  */
 public function testStableTemplateOverrides()
 {
     $registry = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $this->themeHandler, \Drupal::service('theme.initialization'), 'stable');
     $registry->setThemeManager(\Drupal::theme());
     $registry_full = $registry->get();
     foreach ($registry_full as $hook => $info) {
         if (isset($info['template'])) {
             // Allow skipping templates.
             if (in_array($info['template'], $this->templatesToSkip)) {
                 continue;
             }
             $this->assertEquals('core/themes/stable', $info['theme path'], $info['template'] . '.html.twig overridden in Stable.');
         }
     }
 }
Example #9
0
 /**
  * Initializes devel module requirements.
  */
 public function onRequest(GetResponseEvent $event)
 {
     if ($this->account->hasPermission('access devel information')) {
         devel_set_handler(devel_get_handlers());
         // See http://www.firephp.org/HQ/Install.htm
         $path = NULL;
         if (@(include_once 'fb.php') || @(include_once 'FirePHPCore/fb.php')) {
             // FirePHPCore is in include_path. Probably a PEAR installation.
             $path = '';
         } elseif ($this->moduleHandler->moduleExists('libraries')) {
             // Support Libraries API - http://drupal.org/project/libraries
             $firephp_path = libraries_get_path('FirePHPCore');
             $firephp_path = $firephp_path ? $firephp_path . '/lib/FirePHPCore/' : '';
             $chromephp_path = libraries_get_path('chromephp');
         } else {
             $firephp_path = DRUPAL_ROOT . '/libraries/FirePHPCore/lib/FirePHPCore/';
             $chromephp_path = './' . drupal_get_path('module', 'devel') . '/chromephp';
         }
         // Include FirePHP if it exists.
         if (!empty($firephp_path) && file_exists($firephp_path . 'fb.php')) {
             include_once $firephp_path . 'fb.php';
             include_once $firephp_path . 'FirePHP.class.php';
         }
         // Include ChromePHP if it exists.
         if (!empty($chromephp_path) && file_exists($chromephp_path .= '/ChromePhp.php')) {
             include_once $chromephp_path;
         }
     }
     if ($this->config->get('rebuild_theme')) {
         drupal_theme_rebuild();
         // Ensure that the active theme object is cleared.
         $theme_name = \Drupal::theme()->getActiveTheme()->getName();
         \Drupal::state()->delete('theme.active_theme.' . $theme_name);
         \Drupal::theme()->resetActiveTheme();
         /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler*/
         $theme_handler = \Drupal::service('theme_handler');
         $theme_handler->refreshInfo();
         // @todo This is not needed after https://www.drupal.org/node/2330755
         $list = $theme_handler->listInfo();
         $theme_handler->addTheme($list[$theme_name]);
         if (\Drupal::service('flood')->isAllowed('devel.rebuild_theme_warning', 1)) {
             \Drupal::service('flood')->register('devel.rebuild_theme_warning');
             if ($this->account->hasPermission('access devel information')) {
                 drupal_set_message(t('The theme information is being rebuilt on every request. Remember to <a href=":url">turn off</a> this feature on production websites.', array(':url' => $this->urlGenerator->generateFromRoute('devel.admin_settings'))));
             }
         }
     }
 }
Example #10
0
 /**
  * Tests that the maintenance theme initializes the theme and its base themes.
  */
 public function testMaintenanceTheme()
 {
     $this->setSetting('maintenance_theme', 'seven');
     // Get the maintenance theme loaded.
     drupal_maintenance_theme();
     // Do we have an active theme?
     $this->assertTrue(\Drupal::theme()->hasActiveTheme());
     $active_theme = \Drupal::theme()->getActiveTheme();
     $this->assertEquals('seven', $active_theme->getName());
     $base_themes = $active_theme->getBaseThemes();
     $base_theme_names = array_keys($base_themes);
     $this->assertSame(['classy', 'stable'], $base_theme_names);
     // Ensure Classy has the correct base themes and amount of base themes.
     $classy_base_themes = $base_themes['classy']->getBaseThemes();
     $classy_base_theme_names = array_keys($classy_base_themes);
     $this->assertSame(['stable'], $classy_base_theme_names);
 }
Example #11
0
 /**
  * Tests if the theme has been altered.
  */
 function testDrupalAlter()
 {
     // This test depends on Bartik, so make sure that it is always the current
     // active theme.
     \Drupal::service('theme_handler')->install(array('bartik'));
     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('bartik'));
     $array = array('foo' => 'bar');
     $entity = new \stdClass();
     $entity->foo = 'bar';
     // Verify alteration of a single argument.
     $array_copy = $array;
     $array_expected = array('foo' => 'Drupal theme');
     \Drupal::moduleHandler()->alter('drupal_alter', $array_copy);
     \Drupal::theme()->alter('drupal_alter', $array_copy);
     $this->assertEqual($array_copy, $array_expected, 'Single array was altered.');
     $entity_copy = clone $entity;
     $entity_expected = clone $entity;
     $entity_expected->foo = 'Drupal theme';
     \Drupal::moduleHandler()->alter('drupal_alter', $entity_copy);
     \Drupal::theme()->alter('drupal_alter', $entity_copy);
     $this->assertEqual($entity_copy, $entity_expected, 'Single object was altered.');
     // Verify alteration of multiple arguments.
     $array_copy = $array;
     $array_expected = array('foo' => 'Drupal theme');
     $entity_copy = clone $entity;
     $entity_expected = clone $entity;
     $entity_expected->foo = 'Drupal theme';
     $array2_copy = $array;
     $array2_expected = array('foo' => 'Drupal theme');
     \Drupal::moduleHandler()->alter('drupal_alter', $array_copy, $entity_copy, $array2_copy);
     \Drupal::theme()->alter('drupal_alter', $array_copy, $entity_copy, $array2_copy);
     $this->assertEqual($array_copy, $array_expected, 'First argument to \\Drupal::moduleHandler->alter() was altered.');
     $this->assertEqual($entity_copy, $entity_expected, 'Second argument to \\Drupal::moduleHandler->alter() was altered.');
     $this->assertEqual($array2_copy, $array2_expected, 'Third argument to \\Drupal::moduleHandler->alter() was altered.');
     // Verify alteration order when passing an array of types to \Drupal::moduleHandler->alter().
     // common_test_module_implements_alter() places 'block' implementation after
     // other modules.
     $array_copy = $array;
     $array_expected = array('foo' => 'Drupal block theme');
     \Drupal::moduleHandler()->alter(array('drupal_alter', 'drupal_alter_foo'), $array_copy);
     \Drupal::theme()->alter(array('drupal_alter', 'drupal_alter_foo'), $array_copy);
     $this->assertEqual($array_copy, $array_expected, 'hook_TYPE_alter() implementations ran in correct order.');
 }
Example #12
0
 /**
  * {@inheritdoc}
  */
 public function setUp($processor = NULL)
 {
     parent::setUp('rendered_item');
     // Load configuration and needed schemas. (The necessary schemas for using
     // nodes are already installed by the parent method.)
     $this->installConfig(array('system', 'filter', 'node', 'comment'));
     $this->installSchema('system', array('router'));
     \Drupal::service('router.builder')->rebuild();
     // Create a node type for testing.
     $type = NodeType::create(array('type' => 'page', 'name' => 'page'));
     $type->save();
     node_add_body_field($type);
     // Create anonymous user role.
     $role = Role::create(array('id' => 'anonymous', 'label' => 'anonymous'));
     $role->save();
     // Insert the anonymous user into the database.
     $anonymous_user = User::create(array('uid' => 0, 'name' => ''));
     $anonymous_user->save();
     // Default node values for all nodes we create below.
     $node_data = array('status' => NODE_PUBLISHED, 'type' => 'page', 'title' => '', 'body' => array('value' => '', 'summary' => '', 'format' => 'plain_text'), 'uid' => $anonymous_user->id());
     // Create some test nodes with valid user on it for rendering a picture.
     $node_data['title'] = 'Title for node 1';
     $node_data['body']['value'] = 'value for node 1';
     $node_data['body']['summary'] = 'summary for node 1';
     $this->nodes[1] = Node::create($node_data);
     $this->nodes[1]->save();
     $node_data['title'] = 'Title for node 2';
     $node_data['body']['value'] = 'value for node 2';
     $node_data['body']['summary'] = 'summary for node 2';
     $this->nodes[2] = Node::create($node_data);
     $this->nodes[2]->save();
     // Set proper configuration for the tested processor.
     $config = $this->processor->getConfiguration();
     $config['view_mode'] = array('entity:node' => ['page' => 'full', 'article' => 'teaser'], 'entity:user' => 'compact', 'entity:comment' => 'teaser');
     $config['roles'] = array($role->id());
     $this->processor->setConfiguration($config);
     $this->index->save();
     $this->index->getDatasources();
     // Enable the classy theme as the tests rely on markup from that.
     \Drupal::service('theme_handler')->install(array('classy'));
     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('classy'));
 }
Example #13
0
 /**
  * Test that ThemeManager renders the expected data types.
  */
 function testThemeDataTypes()
 {
     // theme_test_false is an implemented theme hook so \Drupal::theme() service
     // should return a string or an object that implements MarkupInterface,
     // even though the theme function itself can return anything.
     $foos = array('null' => NULL, 'false' => FALSE, 'integer' => 1, 'string' => 'foo', 'empty_string' => '');
     foreach ($foos as $type => $example) {
         $output = \Drupal::theme()->render('theme_test_foo', array('foo' => $example));
         $this->assertTrue($output instanceof MarkupInterface || is_string($output), format_string('\\Drupal::theme() returns an object that implements MarkupInterface or a string for data type @type.', array('@type' => $type)));
         if ($output instanceof MarkupInterface) {
             $this->assertIdentical((string) $example, $output->__toString());
         } elseif (is_string($output)) {
             $this->assertIdentical($output, '', 'A string will be return when the theme returns an empty string.');
         }
     }
     // suggestionnotimplemented is not an implemented theme hook so \Drupal::theme() service
     // should return FALSE instead of a string.
     $output = \Drupal::theme()->render(array('suggestionnotimplemented'), array());
     $this->assertIdentical($output, FALSE, '\\Drupal::theme() returns FALSE when a hook suggestion is not implemented.');
 }
 /**
  * Tests the current theme condition.
  */
 public function testCurrentTheme()
 {
     \Drupal::service('theme_handler')->install(array('test_theme'));
     $manager = \Drupal::service('plugin.manager.condition');
     /** @var $condition \Drupal\Core\Condition\ConditionInterface */
     $condition = $manager->createInstance('current_theme');
     $condition->setConfiguration(array('theme' => 'test_theme'));
     /** @var $condition_negated \Drupal\Core\Condition\ConditionInterface */
     $condition_negated = $manager->createInstance('current_theme');
     $condition_negated->setConfiguration(array('theme' => 'test_theme', 'negate' => TRUE));
     $this->assertEqual($condition->summary(), SafeMarkup::format('The current theme is @theme', array('@theme' => 'test_theme')));
     $this->assertEqual($condition_negated->summary(), SafeMarkup::format('The current theme is not @theme', array('@theme' => 'test_theme')));
     // The expected theme has not been set up yet.
     $this->assertFalse($condition->execute());
     $this->assertTrue($condition_negated->execute());
     // Set the expected theme to be used.
     \Drupal::service('theme_handler')->setDefault('test_theme');
     \Drupal::theme()->resetActiveTheme();
     $this->assertTrue($condition->execute());
     $this->assertFalse($condition_negated->execute());
 }
 /**
  * Retrieves a theme instance of \Drupal\materialize.
  *
  * @param string $name
  *   The machine name of a theme. If omitted, the active theme will be used.
  * @param \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler
  *   The theme handler object.
  *
  * @return \Drupal\materialize\Theme
  *   A theme object.
  */
 public static function getTheme($name = NULL, ThemeHandlerInterface $theme_handler = NULL)
 {
     // Immediately return if theme passed is already instantiated.
     if ($name instanceof Theme) {
         return $name;
     }
     static $themes = [];
     static $active_theme;
     if (!isset($active_theme)) {
         $active_theme = \Drupal::theme()->getActiveTheme()->getName();
     }
     if (!isset($name)) {
         $name = $active_theme;
     }
     if (!isset($theme_handler)) {
         $theme_handler = self::getThemeHandler();
     }
     if (!isset($themes[$name])) {
         $themes[$name] = new Theme($theme_handler->getTheme($name), $theme_handler);
     }
     return $themes[$name];
 }
 /**
  * Initializes devel module requirements.
  */
 public function onRequest(GetResponseEvent $event)
 {
     if ($this->config->get('rebuild_theme')) {
         drupal_theme_rebuild();
         // Ensure that the active theme object is cleared.
         $theme_name = \Drupal::theme()->getActiveTheme()->getName();
         \Drupal::state()->delete('theme.active_theme.' . $theme_name);
         \Drupal::theme()->resetActiveTheme();
         /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler*/
         $theme_handler = \Drupal::service('theme_handler');
         $theme_handler->refreshInfo();
         // @todo This is not needed after https://www.drupal.org/node/2330755
         $list = $theme_handler->listInfo();
         $theme_handler->addTheme($list[$theme_name]);
         if (\Drupal::service('flood')->isAllowed('devel.rebuild_theme_warning', 1)) {
             \Drupal::service('flood')->register('devel.rebuild_theme_warning');
             if ($this->account->hasPermission('access devel information')) {
                 drupal_set_message(t('The theme information is being rebuilt on every request. Remember to <a href=":url">turn off</a> this feature on production websites.', array(':url' => $this->urlGenerator->generateFromRoute('devel.admin_settings'))));
             }
         }
     }
 }
function innovation_fonts_settings_form_alter(&$form)
{
    $form['fonts_settings'] = array('#type' => 'details', '#title' => 'Font Settings', '#group' => 'innovation_theme_settings', '#weight' => -1);
    $form['fonts_settings']['innovation_fonts'] = array('#markup' => '<div id="fonts"></div>');
    $theme_key = \Drupal::theme()->getActiveTheme()->getName();
    if (function_exists($theme_key . '_fonts')) {
        $fonts = call_user_func($theme_key . '_fonts');
    } else {
        $fonts = array('body' => array('#title' => t('Body Font'), '#description' => t('Typography option with each property can be called individually.')), 'h1' => array('#title' => t('H1')), 'h2' => array('#title' => t('H2')), 'h3' => array('#title' => t('H3')), 'h4' => array('#title' => t('H4')), 'h5' => array('#title' => t('H5')), 'h6' => array('#title' => t('H6')));
    }
    $general_fonts = array(1, 2, 3, 4, 5);
    $form['fonts_settings']['global'] = array('#type' => 'fieldset', '#title' => t('Global fonts'), '#description' => t('Global fonts use in CSS'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['fonts_settings']['general'] = array('#type' => 'fieldset', '#title' => t('General fonts'), '#description' => t('Define font for basic tag (body, heading...)'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['fonts_settings']['custom'] = array('#type' => 'fieldset', '#title' => t('Custom fonts'), '#description' => t('Define font for special elements'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    foreach ($general_fonts as $font) {
        $form['fonts_settings']['global']['global_font_' . $font] = array('#type' => 'textfield', '#default_value' => theme_get_setting('global_font_' . $font), '#attributes' => array('class' => array('google-font', 'global-font')), '#maxlength' => 256);
    }
    foreach ($fonts as $key => $font) {
        $font['#type'] = 'textfield';
        $font['#default_value'] = theme_get_setting($key);
        $font['#attributes'] = array('class' => array('google-font'));
        $form['fonts_settings']['general'][$key] = $font;
    }
    $custom_fonts = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
    foreach ($custom_fonts as $font) {
        $form['fonts_settings']['custom']['custom_font_' . $font] = array('#type' => 'textfield', '#default_value' => theme_get_setting('custom_font_' . $font), '#attributes' => array('class' => array('google-font', 'custom-font')), '#title' => t('Custom font #' . $font), '#maxlength' => 256);
    }
    $fonts = json_decode(file_get_contents(__DIR__ . '/font-list.json'));
    foreach ($fonts->items as $k => $font) {
        $fonts->items[$k]->label = $font->family;
        $fonts->items[$k]->value = $font->family;
        if (!isset($fonts->items[$k]->{'data-google'})) {
            $fonts->items[$k]->{'data-google'} = true;
        }
    }
    $form['#attached']['library'][] = 'core/drupal.autocomplete';
    $form['#attached']['drupalSettings'] = array_merge($form['#attached']['drupalSettings'], array('google_fonts' => $fonts));
}
 /**
  * Survey list page.
  *
  * @return string
  *   Survey HTML table.
  */
 public function surveyListPage()
 {
     $button_class = 'button button-action button--primary button--small';
     $route = 'block.admin_add';
     $actions = \Drupal::theme()->render('item_list', ['items' => [$this->l(t('Add embed survey'), Url::fromRoute($route, ['plugin_id' => 'survey-embed'], ['attributes' => ['class' => $button_class]])), $this->l(t('Add HTML survey'), Url::fromRoute($route, ['plugin_id' => 'survey-html'], ['attributes' => ['class' => $button_class]]))], 'attributes' => ['class' => 'action-links']]);
     $surveys_table = ['#type' => 'table', '#prefix' => $actions, '#header' => [t('Name'), t('Sections'), t('Type'), t('Manage')], '#empty' => t('There are no surveys added.')];
     $embed_surveys = _survey_manager_get_surveys('survey-embed');
     $html_surveys = _survey_manager_get_surveys('survey-html');
     $surveys = array_merge($embed_surveys, $html_surveys);
     $manager = \Drupal::service('plugin.manager.block');
     $definitions = $manager->getDefinitions();
     foreach ($surveys as $id => $survey) {
         $plugin_id = $survey->get('settings')['id'];
         $surveys_table[$id]['name'] = ['#plain_text' => $survey->get('settings')['label']];
         $sections = '';
         $visibility = $survey->getVisibility();
         if (!empty($visibility['request_path'])) {
             $pages = explode(PHP_EOL, $visibility['request_path']['pages']);
             $sections .= 'Pages: ' . implode(', ', $pages) . '</br>';
         }
         if (!empty($visibility['node_type'])) {
             $sections .= 'Content Types: ' . implode(', ', $visibility['node_type']['bundles']) . '</br>';
         }
         if (!empty($visibility['user_role'])) {
             $sections .= 'Roles: ' . implode(', ', $visibility['user_role']['roles']) . '</br>';
         }
         $surveys_table[$id]['sections'] = ['#markup' => $sections];
         $surveys_table[$id]['type'] = ['#plain_text' => $definitions[$plugin_id]['admin_label']->getUntranslatedString()];
         $surveys_table[$id]['operations'] = ['#type' => 'operations', '#links' => []];
         $surveys_table[$id]['operations']['#links']['edit'] = ['title' => t('Edit'), 'url' => Url::fromRoute('entity.block.edit_form', ['block' => $id])];
         $surveys_table[$id]['operations']['#links']['delete'] = ['title' => t('Delete'), 'url' => Url::fromRoute('entity.block.delete_form', ['block' => $id])];
         if (!empty($survey->get('settings')['manage_survey'])) {
             $surveys_table[$id]['operations']['#links']['manage'] = ['title' => t('Manage'), 'url' => Url::fromUri($survey->get('settings')['manage_survey'])];
         }
     }
     return $surveys_table;
 }
Example #19
0
 /**
  * Invokes the page attachment hooks.
  *
  * @param array &$page
  *   A #type 'page' render array, for which the page attachment hooks will be
  *   invoked and to which the results will be added.
  *
  * @throws \LogicException
  *
  * @internal
  *
  * @see hook_page_attachments()
  * @see hook_page_attachments_alter()
  */
 public function invokePageAttachmentHooks(array &$page)
 {
     // Modules can add attachments.
     $attachments = [];
     foreach ($this->moduleHandler->getImplementations('page_attachments') as $module) {
         $function = $module . '_page_attachments';
         $function($attachments);
     }
     if (array_diff(array_keys($attachments), ['#attached', '#cache']) !== []) {
         throw new \LogicException('Only #attached and #cache may be set in hook_page_attachments().');
     }
     // Modules and themes can alter page attachments.
     $this->moduleHandler->alter('page_attachments', $attachments);
     \Drupal::theme()->alter('page_attachments', $attachments);
     if (array_diff(array_keys($attachments), ['#attached', '#cache']) !== []) {
         throw new \LogicException('Only #attached and #cache may be set in hook_page_attachments_alter().');
     }
     // Merge the attachments onto the $page render array.
     $page = $this->renderer->mergeBubbleableMetadata($page, $attachments);
 }
Example #20
0
/**
 * Implements hook_form_system_theme_settings_alter().
 *
 * Custom theme settings
 */
function mayo_form_system_theme_settings_alter(&$form, FormStateInterface $form_state)
{
    global $base_url;
    //Change collapsible fieldsets (now details) to default #open => FALSE.
    $form['theme_settings']['#open'] = FALSE;
    $form['logo']['#open'] = FALSE;
    $form['favicon']['#open'] = FALSE;
    // Add various settings into drupalSettings for the live preview.
    $uri = theme_get_setting('logo.path', 'mayo');
    if (!empty($uri)) {
        $file_url = file_create_url($uri);
        $file_url = str_ireplace($base_url, '', $file_url);
    } else {
        $file_url = '/' . drupal_get_path('theme', 'mayo') . '/logo.svg';
    }
    $js = array('logo_path' => $file_url, 'header_bg_file' => theme_get_setting('header_bg_file', 'mayo'), 'header_bg_alignment' => theme_get_setting('header_bg_alignment', 'mayo'), 'header_watermark' => theme_get_setting('header_watermark', 'mayo'), 'header_border_width' => theme_get_setting('header_border_width', 'mayo'), 'layout_style' => theme_get_setting('layout_style', 'mayo'), 'base_vmargin' => theme_get_setting('base_vmargin', 'mayo'));
    $form['#attached']['drupalSettings']['color'] = $js;
    // Get our plugin system functions.
    require_once drupal_get_path('theme', 'mayo') . '/inc/plugins.inc';
    // We need some getters.
    require_once drupal_get_path('theme', 'mayo') . '/inc/get.inc';
    $path_to_mayo = drupal_get_path('theme', 'mayo');
    // General "alters" use a form id. Settings should not be set here. The only
    // thing useful about this is if you need to alter the form for the running
    // theme and *not* the theme setting.
    // @see http://drupal.org/node/943212
    if (isset($form_id)) {
        return;
    }
    // Get an array of device groups with option values
    $device_group_options = page_layouts_device_group_options('mayo');
    // Unit options
    $unit_options = array('%' => '%', 'px' => 'px', 'em' => 'em');
    // Assign $options for each device group
    foreach ($device_group_options as $device_group => $options) {
        // About here we need to call a custom sort function, this is what we got for now
        sort($options, SORT_STRING);
        foreach ($options as $option) {
            if ($device_group === 'bigscreen') {
                $bigscreen_options[$option] = \Drupal\Component\Utility\Unicode::ucfirst(str_replace('_', ' ', $option));
                // human readable option names for accessibility
            }
            if ($device_group === 'tablet_landscape') {
                $tablet_landscape_options[$option] = \Drupal\Component\Utility\Unicode::ucfirst(str_replace('_', ' ', $option));
            }
            if ($device_group === 'tablet_portrait') {
                $tablet_portrait_options[$option] = \Drupal\Component\Utility\Unicode::ucfirst(str_replace('_', ' ', $option));
            }
            if ($device_group === 'smalltouch_landscape') {
                $smalltouch_landscape_options[$option] = \Drupal\Component\Utility\Unicode::ucfirst(str_replace('_', ' ', $option));
            }
        }
    }
    /* --------------- Font settings -------------- */
    $form['font'] = array('#type' => 'details', '#title' => t('Font settings'), '#open' => FALSE);
    $form['font']['base_font_size'] = array('#type' => 'select', '#title' => t('Base font size'), '#default_value' => theme_get_setting('base_font_size'), '#options' => array('75%' => '75% (=12px)', '81.25%' => '81.25% (=13px)', '87.5%' => '87.5% (=14px)', '93.75%' => '93.75% (=15px)', '100%' => '100% (=16px)', '112.5%' => '112.5% (=18px)'), '#description' => t('To support text size enlargement/reduction, percent ratio based on the browser\'s regular font size (which is mostly 16px) is used.'));
    $form['font']['base_font_family'] = array('#type' => 'select', '#title' => t('Base font family'), '#default_value' => theme_get_setting('base_font_family'), '#options' => array(0 => t('Serif: Georgia, Palatino Linotype, Book Antiqua, URW Palladio L, Baskerville, serif'), 1 => t('Sans-Serif: Verdana, Geneva, Arial, Bitstream Vera Sans, DejaVu Sans, sans-serif'), 2 => t('Custom')), '#description' => t('Font used for most part of the contents.'));
    $form['font']['base_custom_font_family'] = array('#type' => 'textfield', '#title' => t('Custom base font family'), '#default_value' => theme_get_setting('base_custom_font_family'), '#size' => 80, '#description' => t('Enter the base font-family you want to use. No need to start with <b>font-family:</b> and end with <b>;</b>. Just enter comma separated font names.'), '#prefix' => '<div id="base-custom-font-family-wrapper">', '#suffix' => '</div>');
    $form['font']['heading_font_family'] = array('#type' => 'select', '#title' => t('Heading font family (except for the site name and slogan)'), '#default_value' => theme_get_setting('heading_font_family'), '#options' => array(0 => t('Serif: Georgia, Palatino Linotype, Book Antiqua, URW Palladio L, Baskerville, serif'), 1 => t('Sans-Serif: Verdana, Geneva, Arial, Bitstream Vera Sans, DejaVu Sans, sans-serif'), 2 => t('Custom')), '#description' => t('Font used for the headings (h1, h2, h3, h4, h5). Font used for the site name and slogan can not be changed here. If you want to change it, please manually edit style.css in the theme\'s css subdirectory.'));
    $form['font']['heading_custom_font_family'] = array('#type' => 'textfield', '#title' => t('Custom heading font family'), '#default_value' => theme_get_setting('heading_custom_font_family'), '#size' => 80, '#description' => t('Enter the font-family you want to use for the headings. No need to start with <b>font-family:</b> and end with <b>;</b>. Just enter comma separated font names.'), '#prefix' => '<div id="heading-custom-font-family-wrapper">', '#suffix' => '</div>');
    /* --------------- Layout settings -------------- */
    $form['layout'] = array('#type' => 'details', '#title' => t('Layout settings'), '#collapsed' => TRUE, '#collapsible' => TRUE);
    $form['layout']['base_vmargin'] = array('#type' => 'textfield', '#title' => t('Base vertical (top/bottom) margin'), '#default_value' => theme_get_setting('base_vmargin'), '#size' => 12, '#maxlength' => 8, '#description' => t('Specify the base vertical (top/bottom) margin which is vertical spaces between page edge and browser screen in px.'), '#prefix' => '<img src="' . Url::fromUri('base:' . drupal_get_path('theme', 'mayo') . '/images/base-layout.png')->toString() . '" /><br />');
    $form['layout']['page_margin'] = array('#type' => 'textfield', '#title' => t('Page margin'), '#default_value' => theme_get_setting('page_margin'), '#size' => 12, '#maxlength' => 8, '#description' => t('Specify the page margin which is spaces between page edge and contents in px.'));
    $form['layout']['layout_style'] = array('#type' => 'radios', '#title' => t('Layout style'), '#default_value' => theme_get_setting('layout_style'), '#options' => array(1 => t('1. Apply page margin to all (header, footer and main contents).'), 2 => t('2. Apply page margin to main contents only.')), '#description' => '<img src="' . Url::fromUri('base:' . drupal_get_path('theme', 'mayo') . '/images/page-layout.png')->toString() . '" /><br />' . t('When the layout 2 is selected, or header background image is selected, header borders are not drawn to make it look better.'));
    /* --------------- Responsive sidebar layout settings -------------- */
    /* -----------Big screen as in desktop pc monitor------------- */
    $form['layout']['bigscreen'] = array('#type' => 'details', '#title' => t('Big Screen Sidebar layout'), '#collapsible' => TRUE, '#collapsed' => TRUE, '#attributes' => array('class' => array('mayo-layout-form')));
    // Big screen Layout
    $form['layout']['bigscreen']['bigscreen-layout-wrapper'] = array('#type' => 'details', '#title' => t('Choose sidebar layout'));
    // Options
    $form['layout']['bigscreen']['bigscreen-layout-wrapper']['bigscreen_layout'] = array('#type' => 'radios', '#title' => t('<strong>Choose sidebar positions</strong>'), '#default_value' => str_replace('-', '_', theme_get_setting('bigscreen_layout')), '#options' => $bigscreen_options);
    // Sidebars
    $form['layout']['bigscreen']['bigscreen-sidebar-wrapper'] = array('#type' => 'details', '#title' => t('Set sidebar widths'), '#description' => t('<strong>Set the width of each sidebar</strong>'), '#collapsible' => FALSE);
    // Units
    $form['layout']['bigscreen']['bigscreen-sidebar-wrapper']['bigscreen_sidebar_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('bigscreen_sidebar_unit'), '#options' => $unit_options);
    // Sidebar first
    $form['layout']['bigscreen']['bigscreen-sidebar-wrapper']['bigscreen_sidebar_first'] = array('#type' => 'textfield', '#title' => t('First sidebar'), '#default_value' => Html::escape(theme_get_setting('bigscreen_sidebar_first')), '#size' => 4, '#maxlenght' => 4, '#states' => array('required' => array(array('input[name="bigscreen_layout"]' => array('value' => 'three_col_grail')), array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_left')), array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_right')))));
    // Sidebar second
    $form['layout']['bigscreen']['bigscreen-sidebar-wrapper']['bigscreen_sidebar_second'] = array('#type' => 'textfield', '#title' => t('Second sidebar'), '#default_value' => Html::escape(theme_get_setting('bigscreen_sidebar_second')), '#size' => 4, '#maxlenght' => 4, '#states' => array('required' => array(array('input[name="bigscreen_layout"]' => array('value' => 'three_col_grail')), array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_left')), array('input[name="bigscreen_layout"]' => array('value' => 'two_sidebars_right')))));
    // Page width
    $form['layout']['bigscreen']['bigscreen-width-wrapper'] = array('#type' => 'details', '#title' => t('Set the page width'), '#description' => t('<strong>Set the page width</strong>'));
    // Unit
    $form['layout']['bigscreen']['bigscreen-width-wrapper']['bigscreen_page_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('bigscreen_page_unit'), '#options' => $unit_options);
    // Width
    $form['layout']['bigscreen']['bigscreen-width-wrapper']['bigscreen_page_width'] = array('#type' => 'textfield', '#title' => t('Page width'), '#default_value' => Html::escape(theme_get_setting('bigscreen_page_width')), '#size' => 4, '#maxlenght' => 4, '#required' => TRUE);
    // Media queries
    $form['layout']['bigscreen']['media-queries-wrapper'] = array('#type' => 'details', '#title' => t('Standard Screen Media Queries'), '#weight' => 1, '#attributes' => array('class' => array('at-media-queries')));
    // Media query
    $form['layout']['bigscreen']['media-queries-wrapper']['bigscreen_media_query'] = array('#type' => 'textfield', '#title' => t('Media query for this layout'), '#default_value' => Html::escape(theme_get_setting('bigscreen_media_query')), '#description' => t('Do not include @media, it\'s included automatically.'), '#size' => 100, '#required' => TRUE);
    /* ****************************************************************************
     *
     * Tablet
     *
     * ************************************************************************** */
    $form['layout']['tablet'] = array('#type' => 'details', '#title' => t('Tablet Sidebar Layout'), '#description' => t('<h3>Tablet Layout</h3><p>Tablet devices such as iPad, Android and Windows tablets have two orientations - landscape and portrait, which can also be thought of as wide and narrow tablets. You can configure a different layout for each orientation.</p>'), '#attributes' => array('class' => array('mayo-layout-form')), '#collapsible' => TRUE, '#collapsed' => TRUE);
    /* ******************
     * Tablet landscape
     * **************** */
    $form['layout']['tablet']['landscape'] = array('#type' => 'details', '#title' => t('Landscape'), '#description' => t('<h4>Landscape tablet <span class="field-description-info">(wide)</span></h4>'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Tablet landscape Layout options
    $form['layout']['tablet']['landscape']['tablet-landscape-layout-wrapper'] = array('#type' => 'details', '#title' => t('Choose sidebar layout'));
    // Options
    $form['layout']['tablet']['landscape']['tablet-landscape-layout-wrapper']['tablet_landscape_layout'] = array('#type' => 'radios', '#title' => t('<strong>Choose sidebar positions</strong>'), '#default_value' => str_replace('-', '_', theme_get_setting('tablet_landscape_layout')), '#options' => $tablet_landscape_options);
    // Sidebars
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper'] = array('#type' => 'details', '#title' => t('Set sidebar widths'), '#description' => t('<strong>Set the width of each sidebar</strong>'));
    // Units
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet_landscape_sidebar_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('tablet_landscape_sidebar_unit'), '#options' => $unit_options);
    // Sidebar first
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet_landscape_sidebar_first'] = array('#type' => 'textfield', '#title' => t('First sidebar'), '#default_value' => Html::escape(theme_get_setting('tablet_landscape_sidebar_first')), '#size' => 4, '#maxlenght' => 4, '#states' => array('required' => array(array('input[name="tablet_landscape_layout"]' => array('value' => 'three_col_grail')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left_stack')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right_stack')))));
    // Sidebar second
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet_landscape_sidebar_second'] = array('#type' => 'textfield', '#title' => t('Second sidebar'), '#default_value' => Html::escape(theme_get_setting('tablet_landscape_sidebar_second')), '#size' => 4, '#maxlenght' => 4, '#states' => array('invisible' => array(array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left_stack')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right_stack'))), 'required' => array(array('input[name="tablet_landscape_layout"]' => array('value' => 'three_col_grail')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right')))));
    // Conditional messages for sidebar layouts
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet-landscape-sidebar-message-wrapper'] = array('#type' => 'details', '#states' => array('invisible' => array(array('input[name="tablet_landscape_layout"]' => array('value' => 'three_col_grail')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_left')), array('input[name="tablet_landscape_layout"]' => array('value' => 'two_sidebars_right')))));
    $form['layout']['tablet']['landscape']['tablet-landscape-sidebar-width-wrapper']['tablet-landscape-sidebar-message-wrapper']['message'] = array('#markup' => t('<div class="description">In this layout <em>Second sidebar</em> wraps below.</div>'));
    // Page width
    $form['layout']['tablet']['landscape']['tablet-landscape-page-width-wrapper'] = array('#type' => 'details', '#title' => t('Set the page width'), '#description' => t('<strong>Set the page width</strong>'));
    // Unit
    $form['layout']['tablet']['landscape']['tablet-landscape-page-width-wrapper']['tablet_landscape_page_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('tablet_landscape_page_unit'), '#options' => $unit_options);
    // Width
    $form['layout']['tablet']['landscape']['tablet-landscape-page-width-wrapper']['tablet_landscape_page_width'] = array('#type' => 'textfield', '#title' => t('Page width'), '#default_value' => Html::escape(theme_get_setting('tablet_landscape_page_width')), '#size' => 4, '#maxlenght' => 4, '#required' => TRUE);
    // Media Queries
    $form['layout']['tablet']['landscape']['tablet-landscape-media-queries-wrapper'] = array('#title' => t('Tablet Landscape Media Queries'), '#weight' => 1, '#attributes' => array('class' => array('at-media-queries')));
    // Media query
    $form['layout']['tablet']['landscape']['tablet-landscape-media-queries-wrapper']['tablet_landscape_media_query'] = array('#type' => 'textfield', '#title' => t('Media query for this layout'), '#default_value' => Html::escape(theme_get_setting('tablet_landscape_media_query')), '#description' => t('Do not include @media, it\'s included automatically.'), '#size' => 100, '#required' => TRUE);
    /* *****************
     * Tablet portrait
     * *************** */
    $form['layout']['tablet']['portrait'] = array('#type' => 'details', '#title' => t('Portrait'), '#description' => t('<h4>Portrait tablet <span class="field-description-info">(narrow)</span></h4>'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    // Tablet portrait Layout options
    $form['layout']['tablet']['portrait']['tablet-portrait-layout-wrapper'] = array('#type' => 'details', '#title' => t('Choose sidebar layout'));
    // Options
    $form['layout']['tablet']['portrait']['tablet-portrait-layout-wrapper']['tablet_portrait_layout'] = array('#type' => 'radios', '#title' => t('<strong>Choose sidebar positions</strong>'), '#default_value' => str_replace('-', '_', theme_get_setting('tablet_portrait_layout')), '#options' => $tablet_portrait_options);
    // Tablet portrait Sidebars
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper'] = array('#type' => 'details', '#title' => t('Set sidebar widths'), '#description' => t('<strong>Set the width of each sidebar</strong>'), '#states' => array('invisible' => array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack'))));
    // Units
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet_portrait_sidebar_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('tablet_portrait_sidebar_unit'), '#options' => $unit_options);
    // Sidebar first
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet_portrait_sidebar_first'] = array('#type' => 'textfield', '#title' => t('First sidebar'), '#default_value' => Html::escape(theme_get_setting('tablet_portrait_sidebar_first')), '#size' => 4, '#maxlenght' => 4, '#states' => array('invisible' => array(array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack'))), 'required' => array(array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_vert')), array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_left_stack')), array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_right_stack')))));
    // Sidebar second
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet_portrait_sidebar_second'] = array('#type' => 'textfield', '#title' => t('Second sidebar'), '#default_value' => Html::escape(theme_get_setting('tablet_portrait_sidebar_second')), '#size' => 4, '#maxlenght' => 4, '#states' => array('invisible' => array(array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack')), array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_left_stack')), array('input[name="tablet_portrait_layout"]' => array('value' => 'two_sidebars_right_stack'))), 'required' => array(array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_vert')))));
    // Conditional messages for sidebar layouts
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet-portrait-sidebar-message-wrapper'] = array('#type' => 'details', '#states' => array('invisible' => array(array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_vert')), array('input[name="tablet_portrait_layout"]' => array('value' => 'one_col_stack')))));
    $form['layout']['tablet']['portrait']['tablet-portrait-sidebar-width-wrapper']['tablet-portrait-sidebar-message-wrapper']['message'] = array('#markup' => t('<div class="description">In this layout <em>Second sidebar</em> wraps below.</div>'));
    // Tablet portrait Page width
    $form['layout']['tablet']['portrait']['tablet-portrait-page-width-wrapper'] = array('#type' => 'details', '#title' => t('Set the page width'), '#description' => t('<strong>Set the page width</strong>'));
    // Unit
    $form['layout']['tablet']['portrait']['tablet-portrait-page-width-wrapper']['tablet_portrait_page_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('tablet_portrait_page_unit'), '#options' => $unit_options);
    // Width
    $form['layout']['tablet']['portrait']['tablet-portrait-page-width-wrapper']['tablet_portrait_page_width'] = array('#type' => 'textfield', '#title' => t('Page width'), '#default_value' => Html::escape(theme_get_setting('tablet_portrait_page_width')), '#size' => 4, '#maxlenght' => 4, '#required' => TRUE);
    // Tablet portrait Media queries
    $form['layout']['tablet']['portrait']['tablet-portrait-media-queries-wrapper'] = array('#type' => 'details', '#title' => t('Tablet Portrait Media Queries'), '#attributes' => array('class' => array('at-media-queries')));
    // Media query
    $form['layout']['tablet']['portrait']['tablet-portrait-media-queries-wrapper']['tablet_portrait_media_query'] = array('#type' => 'textfield', '#title' => t('Media query for this layout'), '#default_value' => Html::escape(theme_get_setting('tablet_portrait_media_query')), '#description' => t('Do not include @media, it\'s included automatically.'), '#size' => 100, '#required' => TRUE);
    /* ****************************************************************************
     *
     * Smalltouch
     *
     * ************************************************************************** */
    $form['layout']['smalltouch'] = array('#type' => 'details', '#title' => t('Smalltouch Sidebar Layout'), '#description' => t('<h3>Smalltouch Layout</h3><p>Smalltouch devices such as iPhone, Android and Windows phones have two orientations - landscape and portrait, which can also be thought of as wide and arrow smalltouch devices. You can configure a layout for landscape orientation only - portrait orientation (narrow) will always display in one column (all regions full width and stacked) with sidebars below the main content.</p>'), '#attributes' => array('class' => array('mayo-layout-form')), '#collapsible' => TRUE, '#collapsed' => TRUE);
    /* **********************
     * Smalltouch landscape
     * ******************** */
    $form['layout']['smalltouch']['landscape'] = array('#type' => 'details', '#title' => t('Landscape'), '#description' => t('<h4>Landscape smalltouch <span class="field-description-info">(wide)</span></h4>'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-layout-wrapper'] = array('#type' => 'details', '#title' => t('Choose sidebar layout'));
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-layout-wrapper']['smalltouch_landscape_layout'] = array('#type' => 'radios', '#title' => t('<strong>Choose sidebar positions</strong>'), '#default_value' => theme_get_setting('smalltouch_landscape_layout') ? str_replace('-', '_', theme_get_setting('smalltouch_landscape_layout')) : str_replace('-', '_', theme_get_setting('smartphone_landscape_layout')), '#options' => $smalltouch_landscape_options);
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper'] = array('#type' => 'details', '#title' => t('Set sidebar widths'), '#description' => t('<strong>Set the width of each sidebar</strong>'), '#states' => array('!visible' => array('input[name="smalltouch_landscape_layout"]' => array('value' => 'one_col_stack'))));
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper']['smalltouch_landscape_sidebar_unit'] = array('#type' => 'select', '#title' => t('Unit'), '#default_value' => theme_get_setting('smalltouch_landscape_sidebar_unit') ? theme_get_setting('smalltouch_landscape_sidebar_unit') : theme_get_setting('smartphone_landscape_sidebar_unit'), '#options' => $unit_options);
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper']['smalltouch_landscape_sidebar_first'] = array('#type' => 'textfield', '#title' => t('First sidebar'), '#default_value' => theme_get_setting('smalltouch_landscape_sidebar_first') ? Html::escape(theme_get_setting('smalltouch_landscape_sidebar_first')) : Html::escape(theme_get_setting('smartphone_landscape_sidebar_first')), '#size' => 4, '#maxlenght' => 4, '#states' => array('required' => array('input[name="smalltouch_landscape_layout"]' => array('value' => 'one_col_vert'))));
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-sidebar-width-wrapper']['smalltouch_landscape_sidebar_second'] = array('#type' => 'textfield', '#title' => t('Second sidebar'), '#default_value' => theme_get_setting('smalltouch_landscape_sidebar_second') ? Html::escape(theme_get_setting('smalltouch_landscape_sidebar_second')) : Html::escape(theme_get_setting('smartphone_landscape_sidebar_second')), '#size' => 4, '#maxlenght' => 4, '#states' => array('required' => array('input[name="smalltouch_landscape_layout"]' => array('value' => 'one_col_vert'))));
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-media-queries-wrapper'] = array('#type' => 'details', '#title' => t('Smalltouch Landscape Media Queries'), '#weight' => 1, '#attributes' => array('class' => array('at-media-queries')));
    $form['layout']['smalltouch']['landscape']['smalltouch-landscape-media-queries-wrapper']['smalltouch_landscape_media_query'] = array('#type' => 'textfield', '#title' => t('Media query for this layout'), '#default_value' => theme_get_setting('smalltouch_landscape_media_query') ? Html::escape(theme_get_setting('smalltouch_landscape_media_query')) : Html::escape(theme_get_setting('smartphone_landscape_media_query')), '#description' => t('Do not include @media, it\'s included automatically.'), '#size' => 100);
    // Pass hidden values to the sumbit function, these values are required but the user can't change them via the UI
    $form['layout']['smalltouch']['landscape']['hidden']['smalltouch_landscape_page_width'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_landscape_page_width') ? Html::escape(theme_get_setting('smalltouch_landscape_page_width')) : Html::escape(theme_get_setting('smartphone_landscape_page_width')));
    $form['layout']['smalltouch']['landscape']['hidden']['smalltouch_landscape_page_unit'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_landscape_page_unit') ? theme_get_setting('smalltouch_landscape_page_unit') : theme_get_setting('smartphone_landscape_page_unit'));
    /* *********************
     * Smalltouch portrait
     * ******************* */
    $form['layout']['smalltouch']['portrait'] = array('#type' => 'details', '#title' => t('Portrait'), '#description' => t('<h4>Portrait smalltouch <span class="field-description-info">(narrow)</span></h4><div class="smalltouch-portrait-layout">One column</div><p>The smalltouch portrait layout always displays in one column with sidebars stacked horizontally below the main content. All widths are always 100%.</p>'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['layout']['smalltouch']['portrait']['smalltouch-portrait-media-queries-wrapper'] = array('#type' => 'details', '#title' => t('Smalltouch Portrait Media Queries'), '#weight' => 1, '#attributes' => array('class' => array('at-media-queries')));
    $form['layout']['smalltouch']['portrait']['smalltouch-portrait-media-queries-wrapper']['smalltouch_portrait_media_query'] = array('#type' => 'textfield', '#title' => t('Media query for this layout'), '#default_value' => theme_get_setting('smalltouch_portrait_media_query') ? Html::escape(theme_get_setting('smalltouch_portrait_media_query')) : Html::escape(theme_get_setting('smartphone_portrait_media_query')), '#description' => t('Do not include @media, it\'s included automatically.'), '#size' => 100);
    // Pass hidden values to the sumbit function, these values are required but the user can't change them via the UI
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_page_width'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_page_width') ? Html::escape(theme_get_setting('smalltouch_portrait_page_width')) : Html::escape(theme_get_setting('smartphone_portrait_page_width')));
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_page_unit'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_page_unit') ? theme_get_setting('smalltouch_portrait_page_unit') : theme_get_setting('smartphone_portrait_page_unit'));
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_sidebar_first'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_sidebar_first') ? Html::escape(theme_get_setting('smalltouch_portrait_sidebar_first')) : Html::escape(theme_get_setting('smartphone_portrait_sidebar_first')));
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_sidebar_second'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_sidebar_second') ? Html::escape(theme_get_setting('smalltouch_portrait_sidebar_second')) : Html::escape(theme_get_setting('smartphone_portrait_sidebar_second')));
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_sidebar_unit'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_sidebar_unit') ? Html::escape(theme_get_setting('smalltouch_portrait_sidebar_unit')) : Html::escape(theme_get_setting('smartphone_portrait_sidebar_unit')));
    $form['layout']['smalltouch']['portrait']['hidden']['smalltouch_portrait_layout'] = array('#type' => 'hidden', '#default_value' => theme_get_setting('smalltouch_portrait_layout') ? str_replace('-', '_', theme_get_setting('smalltouch_portrait_layout')) : str_replace('-', '_', theme_get_setting('smartphone_portrait_layout')));
    /* --------------- Style settings -------------- */
    $form['style'] = array('#type' => 'details', '#title' => t('Style settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['style']['round_corners'] = array('#type' => 'select', '#title' => t('Content box round corners'), '#default_value' => theme_get_setting('round_corners'), '#description' => t('Make the corner of sidebar block and/or node rounded.'), '#options' => array('rc-0' => t('No round corners'), 'rc-1' => t('Sidebar block only'), 'rc-2' => t('Node only'), 'rc-3' => t('Both sidebar block and node')), '#suffix' => '<img src="' . Url::fromUri('base:' . drupal_get_path('theme', 'mayo') . '/images/round-corners.png')->toString() . '" /><br />');
    $form['style']['menubar_style'] = array('#type' => 'radios', '#title' => t('Menubar style'), '#default_value' => theme_get_setting('menubar_style'), '#options' => array(1 => t('1. Normal (based on the colors specified by the color set)'), 2 => t('2. Gloss black image background.')), '#suffix' => '<img src="' . Url::fromUri('base:' . drupal_get_path('theme', 'mayo') . '/images/menubar-type.png')->toString() . '" />');
    $form['style']['note'] = array('#type' => 'item', '#title' => t('Note:'), '#markup' => t('When the menubar type 2 is selected, the menu text color, menu highlight color, menu divier color from the color set are ignored and the fixed colors that match to the menubar are used instead.  Besides, highlight color and menu divider color from the color set are still used for other places such as tabs and sub-menubar for superfish and nice_menus menu.'));
    $form['style']['menubar_background'] = array('#type' => 'checkbox', '#title' => t('Allow Menubar background color.'), '#default_value' => theme_get_setting('menubar_background'), '#description' => t('Add your own hex background color below.'));
    $form['style']['menubar_bg_value'] = array('#type' => 'textfield', '#title' => t('Meubar background color'), '#default_value' => theme_get_setting('menubar_bg_value'), '#size' => 7, '#maxlength' => 7, '#description' => t('Specify the background color for the menubar. This setting is used only when the <em>Allow Meubar background</em> option is checked above.'));
    /* --------------- Advanced header settings -------------- */
    $form['adv_header'] = array('#type' => 'details', '#title' => t('Advanced header settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['adv_header']['header_searchbox'] = array('#type' => 'checkbox', '#title' => t('Add search form to the header'), '#default_value' => theme_get_setting('header_searchbox'), '#description' => t('Check here if you want to add search form block to the right side of the header. Search module must be enabled for this to work.'));
    $form['adv_header']['header_fontsizer'] = array('#type' => 'checkbox', '#title' => t('Add font resizing controls'), '#default_value' => theme_get_setting('header_fontsizer'), '#description' => t('Check here if you want to add font resizing controls at side of the header.'));
    $form['adv_header']['header_border_width'] = array('#type' => 'textfield', '#title' => t('Header border width'), '#default_value' => theme_get_setting('header_border_width'), '#size' => 12, '#maxlength' => 8, '#description' => t('Specify the header border width in px. Note that header border is not drawn when you use header background image or when you use layout style 2.'));
    $form['adv_header']['searchbox_size'] = array('#type' => 'textfield', '#title' => t('Search form textfield width'), '#default_value' => theme_get_setting('searchbox_size'), '#size' => 10, '#maxlength' => 6, '#description' => t('Specify the width of the text field of the search forms in characters. This size is also applied for the search form in a block. NOTE: do not add px since this is not px size.'));
    $form['adv_header']['header_bg_file'] = array('#type' => 'textfield', '#title' => t('URL of the header background image'), '#default_value' => theme_get_setting('header_bg_file'), '#description' => t('Enter a URL of the form (/sites/default/files/your-background.jpg). If the background image is bigger than the header area, it is clipped. If it\'s smaller than the header area, it is tiled to fill the header area. To remove the background image, blank this field and save the settings.'), '#size' => 40, '#maxlength' => 120);
    $form['adv_header']['header_bg'] = array('#type' => 'file', '#title' => t('Upload header background image'), '#size' => 40, '#attributes' => array('enctype' => 'multipart/form-data'), '#description' => t('If you don\'t jave direct access to the server, use this field to upload your header background image. Uploads limited to .png .gif .jpg .jpeg .apng .svg extensions'), '#element_validate' => array('mayo_header_bg_validate'));
    $form['adv_header']['header_bg_alignment'] = array('#type' => 'select', '#title' => t('Header backgeround image alignment'), '#default_value' => theme_get_setting('header_bg_alignment'), '#description' => t('Select the alignment of the header background image.'), '#options' => array('top left' => t('Top left'), 'top center' => t('Top center'), 'top right' => t('Top right'), 'center left' => t('Center left'), 'center center' => t('Center center'), 'center right' => t('Center right'), 'bottom left' => t('Bottom left'), 'bottom center' => t('Bottom center'), 'bottom right' => t('Bottom right')));
    $form['adv_header']['header_watermark'] = array('#type' => 'select', '#title' => t('Header watermark'), '#default_value' => theme_get_setting('header_watermark'), '#description' => t('Select the watermark you want from the list below. The sample below is scaled down and the actual size of the watermark is bigger.'), '#options' => array(0 => t('-None-'), 1 => t('Pixture'), 2 => t('Wave'), 3 => t('Bubble'), 4 => t('Flower'), 5 => t('Star'), 6 => t('Metal')), '#suffix' => '<img src="' . Url::fromUri('base:' . drupal_get_path('theme', 'mayo') . '/images/watermark-sample.png')->toString() . '" /><br />');
    /* --------------- Misellanenous settings -------------- */
    $form['misc'] = array('#type' => 'details', '#title' => t('Miscellaneous settings'), '#collapsible' => TRUE, '#collapsed' => TRUE);
    $form['misc']['dark_messages'] = array('#type' => 'checkbox', '#title' => t('Use dark message colors'), '#default_value' => theme_get_setting('dark_messages'), '#return_value' => 'dark-messages', '#description' => t('Check here if you use the dark color set. Colors for the status/warning/error messages are adjusted.'));
    /*
     * Originally posted by dvessel (http://drupal.org/user/56782).
     * The following will be processed even if the theme is inactive.
     * If you are on a theme specific settings page but it is not an active
     * theme (example.com/admin/apearance/settings/THEME_NAME), it will
     * still be processed.
     *
     * Build a list of themes related to the theme specific form. If the form
     * is specific to a sub-theme, all parent themes leading to it will have
     * hook_form_theme_settings invoked. For example, if a theme named
     * 'grandchild' has its settings form in focus, the following will be invoked.
     * - parent_form_theme_settings()
     * - child_form_theme_settings()
     * - grandchild_form_theme_settings()
     *
     * If 'child' was in focus it will invoke:
     * - parent_form_theme_settings()
     * - child_form_theme_settings()
     *
     *  @see http://drupal.org/node/943212
     */
    $form_themes = array();
    $theme_handler = \Drupal::service('theme_handler');
    $themes = $theme_handler->listInfo();
    // Get a list of available themes.
    $_theme = \Drupal::theme()->getActiveTheme()->getName();
    while (isset($_theme)) {
        $form_themes[$_theme] = $_theme;
        $_theme = isset($themes[$_theme]->base_theme) ? $themes[$_theme]->base_theme : NULL;
    }
    $form_themes = array_reverse($form_themes);
    foreach ($form_themes as $theme_key) {
        if (function_exists($form_settings = "{$theme_key}_form_theme_settings")) {
            $form_settings($form, $form_state);
        }
    }
    // Include custom form validation and submit functions
    require_once drupal_get_path('theme', 'mayo') . '/inc/forms/mayo.validate.inc';
    require_once drupal_get_path('theme', 'mayo') . '/inc/forms/mayo.submit.inc';
    // Custom validate and submit functions
    // Custom submit buggy. Edited FormBuilder.php with patch in #12
    // found here: https://drupal.org/node/2252165
    $form['#validate'][] = 'mayo_settings_validate';
    $form['#submit'][] = 'mayo_settings_submit';
}
Example #21
0
 /**
  * Render this view for a certain display.
  *
  * Note: You should better use just the preview function if you want to
  * render a view.
  *
  * @param string $display_id
  *   The machine name of the display, which should be rendered.
  *
  * @return string|null
  *   Return the output of the rendered view or NULL if something failed in the process.
  */
 public function render($display_id = NULL)
 {
     $this->execute($display_id);
     // Check to see if the build failed.
     if (!empty($this->build_info['fail'])) {
         return;
     }
     if (!empty($this->build_info['denied'])) {
         return;
     }
     $exposed_form = $this->display_handler->getPlugin('exposed_form');
     $exposed_form->preRender($this->result);
     $module_handler = \Drupal::moduleHandler();
     // @TODO In the longrun, it would be great to execute a view without
     //   the theme system at all. See https://www.drupal.org/node/2322623.
     $active_theme = \Drupal::theme()->getActiveTheme();
     $themes = array_keys($active_theme->getBaseThemes());
     $themes[] = $active_theme->getName();
     // Check for already-cached output.
     if (!empty($this->live_preview)) {
         $cache = FALSE;
     } else {
         /** @var \Drupal\views\Plugin\views\cache\CachePluginBase $cache */
         $cache = $this->display_handler->getPlugin('cache');
     }
     // Run preRender for the pager as it might change the result.
     if (!empty($this->pager)) {
         $this->pager->preRender($this->result);
     }
     // Initialize the style plugin.
     $this->initStyle();
     if (!isset($this->response)) {
         // Set the response so other parts can alter it.
         $this->response = new Response('', 200);
     }
     // Give field handlers the opportunity to perform additional queries
     // using the entire resultset prior to rendering.
     if ($this->style_plugin->usesFields()) {
         foreach ($this->field as $id => $handler) {
             if (!empty($this->field[$id])) {
                 $this->field[$id]->preRender($this->result);
             }
         }
     }
     $this->style_plugin->preRender($this->result);
     // Let each area handler have access to the result set.
     $areas = array('header', 'footer');
     // Only call preRender() on the empty handlers if the result is empty.
     if (empty($this->result)) {
         $areas[] = 'empty';
     }
     foreach ($areas as $area) {
         foreach ($this->{$area} as $handler) {
             $handler->preRender($this->result);
         }
     }
     // Let modules modify the view just prior to rendering it.
     $module_handler->invokeAll('views_pre_render', array($this));
     // Let the themes play too, because pre render is a very themey thing.
     foreach ($themes as $theme_name) {
         $function = $theme_name . '_views_pre_render';
         if (function_exists($function)) {
             $function($this);
         }
     }
     $this->display_handler->output = $this->display_handler->render();
     $exposed_form->postRender($this->display_handler->output);
     if ($cache) {
         $cache->postRender($this->display_handler->output);
     }
     // Let modules modify the view output after it is rendered.
     $module_handler->invokeAll('views_post_render', array($this, &$this->display_handler->output, $cache));
     // Let the themes play too, because post render is a very themey thing.
     foreach ($themes as $theme_name) {
         $function = $theme_name . '_views_post_render';
         if (function_exists($function)) {
             $function($this);
         }
     }
     return $this->display_handler->output;
 }
Example #22
0
 /**
  * {@inheritdoc}
  *
  * @param string|null $theme
  *   (optional) The theme to display the blocks for. If NULL, the current
  *   theme will be used.
  * @param \Symfony\Component\HttpFoundation\Request $request
  *   The current request.
  *
  * @return array
  *   The block list as a renderable array.
  */
 public function render($theme = NULL, Request $request = NULL)
 {
     $this->request = $request;
     // If no theme was specified, use the current theme.
     $this->theme = $theme ?: \Drupal::theme()->getActiveTheme()->getName();
     return \Drupal::formBuilder()->getForm($this);
 }
Example #23
0
 /**
  * Asserts themed output.
  *
  * @param string $callback
  *   The name of the theme hook to invoke; e.g. 'links' for links.html.twig.
  * @param string $variables
  *   An array of variables to pass to the theme function.
  * @param string $expected
  *   The expected themed output string.
  * @param string $message
  *   (optional) A message to display with the assertion. Do not translate
  *   messages: use format_string() to embed variables in the message text, not
  *   t(). If left blank, a default message will be displayed.
  * @param string $group
  *   (optional) The group this message is in, which is displayed in a column
  *   in test output. Use 'Debug' to indicate this is debugging output. Do not
  *   translate this string. Defaults to 'Other'; most tests do not override
  *   this default.
  *
  * @return bool
  *   TRUE on pass, FALSE on fail.
  */
 protected function assertThemeOutput($callback, array $variables = array(), $expected = '', $message = '', $group = 'Other')
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     $output = $renderer->executeInRenderContext(new RenderContext(), function () use($callback, $variables) {
         return \Drupal::theme()->render($callback, $variables);
     });
     $this->verbose('<hr />' . 'Result:' . '<pre>' . SafeMarkup::checkPlain(var_export($output, TRUE)) . '</pre>' . '<hr />' . 'Expected:' . '<pre>' . SafeMarkup::checkPlain(var_export($expected, TRUE)) . '</pre>' . '<hr />' . $output);
     if (!$message) {
         $message = '%callback rendered correctly.';
     }
     $message = format_string($message, array('%callback' => 'theme_' . $callback . '()'));
     return $this->assertIdentical($output, $expected, $message, $group);
 }
Example #24
0
 /**
  * Tests that the theme registry can be altered by themes.
  */
 public function testThemeRegistryAlterByTheme()
 {
     /** @var \Drupal\Core\Extension\ThemeHandlerInterface $theme_handler */
     $theme_handler = \Drupal::service('theme_handler');
     $theme_handler->install(['test_theme']);
     $theme_handler->setDefault('test_theme');
     $registry = new Registry(\Drupal::root(), \Drupal::cache(), \Drupal::lock(), \Drupal::moduleHandler(), $theme_handler, \Drupal::service('theme.initialization'), 'test_theme');
     $registry->setThemeManager(\Drupal::theme());
     $this->assertEqual('value', $registry->get()['theme_test_template_test']['variables']['additional']);
 }
 /**
  * Controller to ensure that no theme is initialized.
  *
  * @return \Symfony\Component\HttpFoundation\JsonResponse
  *   The json response with the theme initialized information.
  */
 public function nonHtml()
 {
     $theme_initialized = \Drupal::theme()->hasActiveTheme();
     return new JsonResponse(['theme_initialized' => $theme_initialized]);
 }
 /**
  * Returns the used theme.
  */
 public function theme() {
   return [
     '#markup' => 'Current theme: ' . \Drupal::theme()->getActiveTheme()->getName(),
   ];
 }
Example #27
0
 /**
  * Asserts themed output.
  *
  * @param string $callback
  *   The name of the theme hook to invoke; e.g. 'links' for links.html.twig.
  * @param string $variables
  *   An array of variables to pass to the theme function.
  * @param string $expected
  *   The expected themed output string.
  * @param string $message
  *   (optional) A message to display with the assertion. Do not translate
  *   messages: use format_string() to embed variables in the message text, not
  *   t(). If left blank, a default message will be displayed.
  * @param string $group
  *   (optional) The group this message is in, which is displayed in a column
  *   in test output. Use 'Debug' to indicate this is debugging output. Do not
  *   translate this string. Defaults to 'Other'; most tests do not override
  *   this default.
  *
  * @return bool
  *   TRUE on pass, FALSE on fail.
  */
 protected function assertThemeOutput($callback, array $variables = array(), $expected = '', $message = '', $group = 'Other')
 {
     /** @var \Drupal\Core\Render\RendererInterface $renderer */
     $renderer = \Drupal::service('renderer');
     // The string cast is necessary because theme functions return
     // SafeStringInterface objects. This means we can assert that $expected
     // matches the theme output without having to worry about 0 == ''.
     $output = (string) $renderer->executeInRenderContext(new RenderContext(), function () use($callback, $variables) {
         return \Drupal::theme()->render($callback, $variables);
     });
     $this->verbose('<hr />' . 'Result:' . '<pre>' . SafeMarkup::checkPlain(var_export($output, TRUE)) . '</pre>' . '<hr />' . 'Expected:' . '<pre>' . SafeMarkup::checkPlain(var_export($expected, TRUE)) . '</pre>' . '<hr />' . $output);
     if (!$message) {
         $message = '%callback rendered correctly.';
     }
     $message = format_string($message, array('%callback' => 'theme_' . $callback . '()'));
     return $this->assertIdentical($output, $expected, $message, $group);
 }
 /**
  * Asserts themed output.
  *
  * @param string $callback
  *   The name of the theme hook to invoke; e.g. 'links' for links.html.twig.
  * @param string $variables
  *   An array of variables to pass to the theme function.
  * @param string $expected
  *   The expected themed output string.
  * @param string $message
  *   (optional) A message to display with the assertion. Do not translate
  *   messages: use format_string() to embed variables in the message text, not
  *   t(). If left blank, a default message will be displayed.
  * @param string $group
  *   (optional) The group this message is in, which is displayed in a column
  *   in test output. Use 'Debug' to indicate this is debugging output. Do not
  *   translate this string. Defaults to 'Other'; most tests do not override
  *   this default.
  *
  * @return bool
  *   TRUE on pass, FALSE on fail.
  */
 protected function assertThemeOutput($callback, array $variables = array(), $expected = '', $message = '', $group = 'Other')
 {
     $output = \Drupal::theme()->render($callback, $variables);
     $this->verbose('<hr />' . 'Result:' . '<pre>' . String::checkPlain(var_export($output, TRUE)) . '</pre>' . '<hr />' . 'Expected:' . '<pre>' . String::checkPlain(var_export($expected, TRUE)) . '</pre>' . '<hr />' . $output);
     if (!$message) {
         $message = '%callback rendered correctly.';
     }
     $message = format_string($message, array('%callback' => 'theme_' . $callback . '()'));
     return $this->assertIdentical($output, $expected, $message, $group);
 }
 /**
  * Menu callback for testing PHP variables in a Twig template.
  */
 public function phpVariablesRender()
 {
     return ['#markup' => \Drupal::theme()->render('twig_theme_test_php_variables', array())];
 }
 /**
  * Test the theme suggestions when sending mails.
  */
 function testNewsletterTheme()
 {
     // Install and enable the test theme.
     \Drupal::service('theme_handler')->install(array('simplenews_newsletter_test_theme'));
     \Drupal::theme()->setActiveTheme(\Drupal::service('theme.initialization')->initTheme('simplenews_newsletter_test_theme'));
     $node = Node::create(array('type' => 'simplenews_issue', 'title' => $this->randomString(10), 'uid' => '0', 'status' => 1));
     $node->simplenews_issue->target_id = $this->getRandomNewsletter();
     $node->simplenews_issue->handler = 'simplenews_all';
     $node->save();
     // Send the node.
     \Drupal::service('simplenews.spool_storage')->addFromEntity($node);
     $node->save();
     // Send mails.
     \Drupal::service('simplenews.mailer')->sendSpool();
     \Drupal::service('simplenews.spool_storage')->clear();
     // Update sent status for newsletter admin panel.
     \Drupal::service('simplenews.mailer')->updateSendStatus();
     $mails = $this->drupalGetMails();
     // Check if the correct theme was used in mails.
     $this->assertTrue(strpos($mails[0]['body'], 'Simplenews test theme') != FALSE);
 }