Skip to content
<?php
/**
* @file
* Contains \Drupal\Core\Theme\ThemeNegotiator.
*/
namespace Drupal\Core\Theme;
use Symfony\Component\HttpFoundation\Request;
/**
* Provides a class which determines the active theme of the page.
*
* It therefore uses ThemeNegotiatorInterface objects which are passed in
* using the 'theme_negotiator' tag.
*
* @see \Drupal\Core\Theme\ThemeNegotiatorPass
* @see \Drupal\Core\Theme\ThemeNegotiatorInterface
*/
class ThemeNegotiator implements ThemeNegotiatorInterface {
/**
* Holds arrays of theme negotiators, keyed by priority.
*
* @var array
*/
protected $negotiators = array();
/**
* Holds the array of theme negotiators sorted by priority.
*
* Set to NULL if the array needs to be re-calculated.
*
* @var array|NULL
*/
protected $sortedNegotiators;
/**
* The current request.
*
* @var \Symfony\Component\HttpFoundation\Request
*/
protected $request;
/**
* The access checker for themes.
*
* @var \Drupal\Core\Theme\ThemeAccessCheck
*/
protected $themeAccess;
/**
* Constructs a new ThemeNegotiator.
*
* @param \Drupal\Core\Theme\ThemeAccessCheck $theme_access
* The access checker for themes.
*/
public function __construct(ThemeAccessCheck $theme_access) {
$this->themeAccess = $theme_access;
}
/**
* Sets the request object to use.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The request object.
*/
public function setRequest(Request $request) {
$this->request = $request;
}
/**
* Adds a active theme negotiation service.
*
* @param \Drupal\Core\Theme\ThemeNegotiatorInterface $negotiator
* The theme negotiator to add.
* @param int $priority
* Priority of the breadcrumb builder.
*/
public function addNegotiator(ThemeNegotiatorInterface $negotiator, $priority) {
$this->negotiators[$priority][] = $negotiator;
// Force the negotiators to be re-sorted.
$this->sortedNegotiators = NULL;
}
/**
* Returns the sorted array of theme negotiators.
*
* @return array|\Drupal\Core\Theme\ThemeNegotiatorInterface[]
* An array of breadcrumb builder objects.
*/
protected function getSortedNegotiators() {
if (!isset($this->sortedNegotiators)) {
// Sort the negotiators according to priority.
krsort($this->negotiators);
// Merge nested negotiators from $this->negotiators into
// $this->sortedNegotiators.
$this->sortedNegotiators = array();
foreach ($this->negotiators as $builders) {
$this->sortedNegotiators = array_merge($this->sortedNegotiators, $builders);
}
}
return $this->sortedNegotiators;
}
/**
* Get the current active theme.
*
* @return string
* The current active string.
*/
public function getActiveTheme() {
if (!$this->request->attributes->has('_theme_active')) {
$this->determineActiveTheme($this->request);
}
return $this->request->attributes->get('_theme_active');
}
/**
* {@inheritdoc}
*/
public function determineActiveTheme(Request $request) {
foreach ($this->getSortedNegotiators() as $negotiator) {
$theme = $negotiator->determineActiveTheme($request);
if ($theme !== NULL && $this->themeAccess->checkAccess($theme)) {
$request->attributes->set('_theme_active', $theme);
return $request->attributes->get('_theme_active');
}
}
}
}
<?php
/**
* @file
* Contains \Drupal\Core\Theme\ThemeNegotiatorInterface.
*/
namespace Drupal\Core\Theme;
use Symfony\Component\HttpFoundation\Request;
/**
* Defines an interface for classes which determine the active theme.
*
* To set the active theme, create a new service tagged with 'theme_negotiator'
* (see user.services.yml for an example). The only method this service needs
* to implement is determineActiveTheme. Return the name of the theme, or NULL
* if other negotiators like the configured default one should kick in instead.
*
* If you are setting a theme which is closely tied to the functionality of a
* particular page or set of pages (such that the page might not function
* correctly if a different theme is used), make sure to set the priority on
* the service to a high number so that it is not accidentally overridden by
* other theme negotiators. By convention, a priority of "1000" is used in
* these cases; see \Drupal\Core\Theme\AjaxBasePageNegotiator and
* core.services.yml for an example.
*/
interface ThemeNegotiatorInterface {
/**
* Determine the active theme for the request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The active request of the site.
*
* @return string|null
* Returns the active theme name, else return NULL.
*/
public function determineActiveTheme(Request $request);
}
<?php
/**
* @file
* Contains \Drupal\Core\Theme\ThemeNegotiatorPass.
*/
namespace Drupal\Core\Theme;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
/**
* Adds services to the theme negotiator service.
*
* @see \Drupal\Core\Theme\ThemeNegotiator
* @see \Drupal\Core\Theme\ThemeNegotiatorInterfa
*/
class ThemeNegotiatorPass implements CompilerPassInterface {
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container) {
if (!$container->hasDefinition('theme.negotiator')) {
return;
}
$manager = $container->getDefinition('theme.negotiator');
foreach ($container->findTaggedServiceIds('theme_negotiator') as $id => $attributes) {
$priority = isset($attributes[0]['priority']) ? $attributes[0]['priority'] : 0;
$manager->addMethodCall('addNegotiator', array(new Reference($id), $priority));
}
}
}
......@@ -382,7 +382,7 @@ Drupal.ajax.prototype.beforeSerialize = function (element, options) {
// Allow Drupal to return new JavaScript and CSS files to load without
// returning the ones already loaded.
// @see \Drupal\Core\Theme\AjaxBasePageNegotiator
// @see ajax_base_page_theme()
// @see drupal_get_css()
// @see drupal_get_js()
var pageState = drupalSettings.ajaxPageState;
......
......@@ -2,9 +2,7 @@
/**
* @file
* Provides views data and handlers for action.module.
*
* @ingroup views_module_handlers
* Provides views data for action.module.
*/
/**
......
......@@ -3,8 +3,6 @@
/**
* @file
* Provides views data for aggregator.module.
*
* @ingroup views_module_handlers
*/
/**
......
......@@ -109,9 +109,41 @@ function block_menu() {
'type' => MENU_VISIBLE_IN_BREADCRUMB,
'route_name' => 'block.admin_add',
);
// Block administration is tied to the theme and plugin definition so
// that the plugin can appropriately attach to this URL structure.
// @todo D8: Use dynamic % arguments instead of static, hard-coded theme names
// and plugin IDs to decouple the routes from these dependencies.
// @see http://drupal.org/node/1067408
foreach (list_themes() as $key => $theme) {
$items["admin/structure/block/demo/$key"] = array(
'route_name' => 'block.admin_demo',
'type' => MENU_CALLBACK,
'theme callback' => '_block_custom_theme',
'theme arguments' => array($key),
);
}
return $items;
}
/**
* Theme callback: Uses the theme specified in the parameter.
*
* @param $theme
* The theme whose blocks are being configured. If not set, the default theme
* is assumed.
*
* @return
* The theme that should be used for the block configuration page, or NULL
* to indicate that the default theme should be used.
*
* @see block_menu()
*/
function _block_custom_theme($theme = NULL) {
// We return exactly what was passed in, to guarantee that the page will
// always be displayed using the theme whose blocks are being configured.
return $theme;
}
/**
* Implements hook_page_build().
*
......
......@@ -9,8 +9,3 @@ services:
factory_method: get
factory_service: cache_factory
arguments: [block]
theme.negotiator.block.admin_demo:
class: Drupal\block\Theme\AdminDemoNegotiator
tags:
- { name: theme_negotiator, priority: 1000 }
......@@ -36,10 +36,10 @@
* admin_permission = "administer blocks",
* base_table = "custom_block",
* revision_table = "custom_block_revision",
* route_base_path = "admin/structure/block/custom-blocks/manage/{bundle}",
* links = {
* "canonical" = "custom_block.edit",
* "edit-form" = "custom_block.edit"
* "edit-form" = "custom_block.edit",
* "admin-form" = "custom_block.type_edit"
* },
* fieldable = TRUE,
* translatable = TRUE,
......@@ -52,7 +52,8 @@
* },
* bundle_keys = {
* "bundle" = "type"
* }
* },
* bundle_entity_type = "custom_block_type"
* )
*/
class CustomBlock extends ContentEntityBase implements CustomBlockInterface {
......
<?php
/**
* @file
* Contains \Drupal\block\Theme\AdminDemoNegotiator.
*/
namespace Drupal\block\Theme;
use Drupal\Core\Theme\ThemeNegotiatorInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
/**
* Negotiates the theme for the block admin demo page via the URL.
*/
class AdminDemoNegotiator implements ThemeNegotiatorInterface {
/**
* {@inheritdoc}
*/
public function determineActiveTheme(Request $request) {
// We return exactly what was passed in, to guarantee that the page will
// always be displayed using the theme whose blocks are being configured.
if ($request->attributes->get(RouteObjectInterface::ROUTE_NAME) == 'block.admin_demo') {
return $request->attributes->get('theme');
}
}
}
......@@ -696,28 +696,43 @@ function template_preprocess_book_navigation(&$variables) {
if ($book_link['mlid']) {
$variables['tree'] = book_children($book_link);
$build = array();
if ($prev = book_prev($book_link)) {
$prev_href = url($prev['href']);
drupal_add_html_head_link(array('rel' => 'prev', 'href' => $prev_href));
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'prev',
'href' => $prev_href,
);
$variables['prev_url'] = $prev_href;
$variables['prev_title'] = check_plain($prev['title']);
}
if ($book_link['plid'] && $parent = book_link_load($book_link['plid'])) {
$parent_href = url($parent['link_path']);
drupal_add_html_head_link(array('rel' => 'up', 'href' => $parent_href));
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'up',
'href' => $parent_href,
);
$variables['parent_url'] = $parent_href;
$variables['parent_title'] = check_plain($parent['title']);
}
if ($next = book_next($book_link)) {
$next_href = url($next['href']);
drupal_add_html_head_link(array('rel' => 'next', 'href' => $next_href));
$build['#attached']['drupal_add_html_head_link'][][] = array(
'rel' => 'next',
'href' => $next_href,
);
$variables['next_url'] = $next_href;
$variables['next_title'] = check_plain($next['title']);
}
}
if (!empty($build)) {
drupal_render($build);
}
$variables['has_links'] = FALSE;
// Link variables to filter for values and set state of the flag variable.
$links = array('prev_url', 'prev_title', 'parent_url', 'parent_title', 'next_url', 'next_title');
......
<?php
/**
* @file
* Enable, install, update and uninstall functions for the breakpoint module.
*/
/**
* Implements hook_install().
*
* Import breakpoints from all enabled themes.
*/
function breakpoint_install() {
// Import breakpoints from enabled themes.
$themes = array_filter(list_themes(), function ($theme) {return $theme->status;});
_breakpoint_theme_enabled(array_keys($themes));
// Import breakpoints from modules.
_breakpoint_modules_installed(array_keys(\Drupal::moduleHandler()->getModuleList()));
}
......@@ -33,20 +33,6 @@ function breakpoint_help($path, $arg) {
}
}
/**
* Implements hook_themes_enabled().
*
* @param array $theme_list
* An array of theme names.
*
* @see _breakpoint_theme_enabled()
*
* @todo: This should be removed if https://drupal.org/node/1813110 is resolved.
*/
function breakpoint_themes_enabled($theme_list) {
_breakpoint_theme_enabled($theme_list);
}
/**
* Implements hook_themes_disabled().
*
......@@ -61,20 +47,6 @@ function breakpoint_themes_disabled($theme_list) {
_breakpoint_delete_breakpoints($theme_list, Breakpoint::SOURCE_TYPE_THEME);
}
/**
* Implements hook_modules_installed().
*
* @param array $modules
* An array of the modules that were enabled.
*
* @see _breakpoint_modules_enabled()
*
* @todo: This should be removed if https://drupal.org/node/1813110 is resolved.
*/
function breakpoint_modules_installed($modules) {
_breakpoint_modules_installed($modules);
}
/**
* Implements hook_modules_uninstalled().
*
......@@ -89,91 +61,6 @@ function breakpoint_modules_uninstalled($modules) {
_breakpoint_delete_breakpoints($modules, Breakpoint::SOURCE_TYPE_MODULE);
}
/**
* Import breakpoints from all new enabled themes.
*
* @param array $theme_list
* An array of theme names.
*/
function _breakpoint_theme_enabled($theme_list) {
$themes = list_themes();
foreach ($theme_list as $theme_key) {
$media_queries = breakpoint_get_theme_media_queries($theme_key);
_breakpoint_import_media_queries($theme_key, $themes[$theme_key]->info['name'], Breakpoint::SOURCE_TYPE_THEME, $media_queries);
// Import custom groups.
_breakpoint_import_breakpoint_groups($theme_key, Breakpoint::SOURCE_TYPE_THEME);
}
}
/**
* Import breakpoints from all new installed modules.
*
* @param array $modules
* An array of the modules that were installed.
*/
function _breakpoint_modules_installed($modules) {
foreach ($modules as $module) {
$media_queries = breakpoint_get_module_media_queries($module);
_breakpoint_import_media_queries($module, $module, Breakpoint::SOURCE_TYPE_MODULE, $media_queries);
// Import custom groups.
_breakpoint_import_breakpoint_groups($module, Breakpoint::SOURCE_TYPE_MODULE);
}
}
/**
* Import media queries from a theme or module and create a default group.
*
* @param string $group_name
* Machine readable name of the breakpoint group.
* @param string $label
* Human readable name of the breakpoint group.
* @param string $source_type
* Either Breakpoint::SOURCE_TYPE_THEME or Breakpoint::SOURCE_TYPE_MODULE.
* @param array $media_queries
* An array of breakpoints in the form $breakpoint['name'] = 'media query'.
*/
function _breakpoint_import_media_queries($group_name, $label, $source_type, $media_queries) {
if (!empty($media_queries)) {
// Create a new breakpoint group if it doesn't exist.
$breakpoint_group = _breakpoint_group_create_or_load($group_name, $label, $group_name, $source_type);
// Load all media queries, create a breakpoint for each one and add them
// to this breakpoint group.
foreach ($media_queries as $name => $media_query) {
$breakpoint_group->addBreakpointFromMediaQuery($name, $media_query);
}
$breakpoint_group->save();
}
}
/**
* Import breakpoint groups from theme or module.
*
* @param string $source
* The theme or module name
* @param string $source_type
* Either Breakpoint::SOURCE_TYPE_THEME or Breakpoint::SOURCE_TYPE_MODULE.
*/
function _breakpoint_import_breakpoint_groups($source, $source_type) {
$breakpoint_groups = \Drupal::config($source . '.breakpoint_groups');
if ($breakpoint_groups) {
foreach ($breakpoint_groups->get() as $group_name => $data) {
// Breakpoints is mandatory, extra check since this is coming from config.
if (isset($data['breakpoints']) && !empty($data['breakpoints'])) {
// Create a new breakpoint group if it doesn't exist.
$breakpoint_group = _breakpoint_group_create_or_load($group_name, isset($data['label']) ? $data['label'] : $group_name, $source, $source_type);
// Add the breakpoints.
$breakpoint_group->addBreakpoints($data['breakpoints']);
$breakpoint_group->save();
}
else {
throw new \Exception('Illegal config file detected.');
}
}
}
}
/**
* Remove breakpoints from all disabled themes or uninstalled modules.
*
......@@ -245,65 +132,6 @@ function _breakpoint_delete_breakpoint_groups($group_id, $source_type) {
}
}
/**
* Get a list of available breakpoints from a specified theme.
*
* @param string $theme_key
* The name of the theme.
*
* @return array
* An array of breakpoints in the form $breakpoint['name'] = 'media query'.
*/
function breakpoint_get_theme_media_queries($theme_key) {
$themes = list_themes();
if (!isset($themes[$theme_key])) {
throw new \Exception('Illegal theme_key passed.');
}
$config = \Drupal::config($theme_key . '.breakpoints');
if ($config) {
return $config->get();
}
return array();
}
/**
* Get a list of available breakpoints from a specified module.
*
* @param string $module
* The name of the module.
*
* @return array
* An array of breakpoints in the form $breakpoint['name'] = 'media query'.
*/
function breakpoint_get_module_media_queries($module) {
if (!\Drupal::moduleHandler()->moduleExists($module)) {
throw new \Exception('Illegal module name passed.');
}
$config = \Drupal::config($module . '.breakpoints');
if ($config) {
return $config->get();
}
return array();
}
/**
* Load one breakpoint group by its identifier.
*
* @param string $id
* The id of the breakpoint group to load.
*
* @return \Drupal\breakpoint\Entity\BreakpointGroup|null
* The breakpoint group, or NULL if there is no entity with the given id.
*
* @todo Remove this in a follow-up issue.
* @see http://drupal.org/node/1798214
*/
function breakpoint_group_load($id) {
return entity_load('breakpoint_group', $id);
}
/**
* Load one breakpoint by its identifier.
*
......@@ -351,36 +179,3 @@ function breakpoint_select_options() {
asort($options);
return $options;
}
/**
* Helper function to easily create/load a breakpoint group.
*
* @param string $name
* Machine readable name of the breakpoint group.
* @param string $label
* Human readable name of the breakpoint group.
* @param string $source
* Machine readable name of the defining theme or module.
* @param string $source_type
* Either Breakpoint::SOURCE_TYPE_THEME or Breakpoint::SOURCE_TYPE_MODULE.
*
* @return \Drupal\breakpoint\Entity\BreakpointGroup
*
* @see _breakpoint_import_media_queries()
* @see _breakpoint_import_breakpoint_groups()
*/
function _breakpoint_group_create_or_load($name, $label, $source, $source_type) {
// Try loading the breakpoint group.
$breakpoint_group = entity_load('breakpoint_group', $source_type . '.' . $source . '.' . $name);
// Create a new breakpoint group if it doesn't exist.
if (!$breakpoint_group) {
// Build a new breakpoint group.
$breakpoint_group = entity_create('breakpoint_group', array(
'name' => $name,
'label' => $label,
'source' => $source,
'sourceType' => $source_type,
));
}
return $breakpoint_group;
}
# Schema for the configuration files of the Breakpoint module.
breakpoint.settings:
type: mapping
label: 'Breakpoint settings'
mapping:
multipliers:
type: sequence
label: 'Assigning resolution multipliers to breakpoints'
sequence:
- type: string
label: 'Multiplier'
breakpoint.breakpoint.*.*.*:
type: mapping
label: 'Defines the Breakpoint entity'
......
......@@ -41,8 +41,30 @@ public function addBreakpointFromMediaQuery($name, $media_query);
* The breakpoint name is either the machine_name or the ID of a breakpoint.
*
* @param array $breakpoints
* Array containing breakpoints keyed by their ID.
* Array containing breakpoint objects
*
* @return \Drupal\breakpoint\Entity\BreakpointGroup
* The breakpoint group object.
*/
public function addBreakpoints($breakpoints);
/**
* Gets the array of breakpoints for the breakpoint group.
*
* @return array
* The array of breakpoints for the breakpoint group.
*/
public function getBreakpoints();
/**
* Gets a breakpoint from the breakpoint group by ID.
*
* @param string $id
* The breakpoint ID to get.
*
* @return \Drupal\breakpoint\Entity\Breakpoint|boolean
* The breakpoint or FALSE if not in the Breakpoint group.
*/
public function getBreakpointById($id);
}
......@@ -61,15 +61,25 @@ class BreakpointGroup extends ConfigEntityBase implements BreakpointGroupInterfa
*/
public $label;
/**
* The breakpoint group breakpoint IDs.
*
* @var array
* Array containing all breakpoints IDs of this group.
*
* @see \Drupal\breakpoint\Entity\Breakpoint
*/
protected $breakpoint_ids = array();
/**
* The breakpoint group breakpoints.
*
* @var array
* Array containing all breakpoints of this group.
* Array containing all breakpoints objects of this group.
*
* @see \Drupal\breakpoint\Entity\Breakpoint
*/
public $breakpoints = array();
protected $breakpoints = array();
/**
* The breakpoint group source: theme or module name. Use 'user' for
......@@ -97,7 +107,6 @@ class BreakpointGroup extends ConfigEntityBase implements BreakpointGroupInterfa
*/
public function __construct(array $values, $entity_type) {
parent::__construct($values, $entity_type);
$this->loadAllBreakpoints();
}
/**
......@@ -111,10 +120,7 @@ public function save() {
if (empty($this->id)) {
$this->id = $this->sourceType . '.' . $this->source . '.' . $this->name;
}
// Only save the keys, but return the full objects.
$this->breakpoints = array_keys($this->breakpoints);
parent::save();
$this->loadAllBreakpoints();
}
/**
......@@ -156,47 +162,70 @@ public function addBreakpointFromMediaQuery($name, $media_query) {
'mediaQuery' => $media_query,
'source' => $this->name,
'sourceType' => $this->sourceType,
'weight' => count($this->breakpoints),
'weight' => count($this->breakpoint_ids),
));
$breakpoint->save();
}
$this->breakpoints[$breakpoint->id()] = $breakpoint;
return $this->addBreakpoints(array($breakpoint));
}
/**
* {@inheritdoc}
*/
public function addBreakpoints($breakpoints) {
foreach ($breakpoints as $breakpoint_name) {
// Check if breakpoint exists, assume $breakpoint_name is a machine name.
$breakpoint = entity_load('breakpoint', $this->sourceType . '.' . $this->source . '.' . $breakpoint_name);
// If the breakpoint doesn't exist, assume $breakpoint_name is an id.
if (!$breakpoint) {
$breakpoint = entity_load('breakpoint', $breakpoint_name);
}
// If the breakpoint doesn't exists, do not add it.
if ($breakpoint) {
// Add breakpoint to group.
$this->breakpoints[$breakpoint->id()] = $breakpoint;
}
foreach ($breakpoints as $breakpoint) {
// Add breakpoint to group.
$this->breakpoints[$breakpoint->id()] = $breakpoint;
$this->breakpoint_ids[] = $breakpoint->id();
}
return $this;
}
/**
* Loads all breakpoints, remove non-existing ones.
*
* @return array
* Array containing breakpoints keyed by their id.
*/
protected function loadAllBreakpoints() {
$breakpoints = $this->breakpoints;
$this->breakpoints = array();
foreach ($breakpoints as $breakpoint_id) {
$breakpoint = breakpoint_load($breakpoint_id);
if ($breakpoint) {
$this->breakpoints[$breakpoint_id] = $breakpoint;
* {@inheritdoc}
*/
public function getBreakpoints() {
if (empty($this->breakpoints)) {
foreach ($this->breakpoint_ids as $breakpoint_id) {
$breakpoint = breakpoint_load($breakpoint_id);
if ($breakpoint) {
$this->breakpoints[$breakpoint_id] = $breakpoint;
}
}
}
return $this->breakpoints;
}
/**
* {@inheritdoc}
*/
public function getBreakpointById($id) {
$breakpoints = $this->getBreakpoints();
if (isset($breakpoints[$id])) {
return $breakpoints[$id];
}
return FALSE;
}
/**
* {@inheritdoc}
*/
public function getExportProperties() {
$names = array(
'id',
'uuid',
'name',
'label',
'breakpoint_ids',
'source',
'sourceType',
'status',
'langcode',
);
$properties = array();
foreach ($names as $name) {
$properties[$name] = $this->get($name);
}
return $properties;
}
}
......@@ -50,8 +50,7 @@ public function testBreakpointGroupCRUD() {
$this->verifyBreakpointGroup($group);
// Update the breakpoint group.
$group->breakpoints = array_keys($breakpoints);
$group->save();
$group->addBreakpoints($breakpoints)->save();
$this->verifyBreakpointGroup($group);
// Delete the breakpoint group.
......
......@@ -33,7 +33,6 @@ public function verifyBreakpointGroup(BreakpointGroup $group, BreakpointGroup $c
'label',
'id',
'name',
'breakpoints',
'sourceType',
);
......@@ -58,5 +57,8 @@ public function verifyBreakpointGroup(BreakpointGroup $group, BreakpointGroup $c
$this->assertEqual($compare_set->{$property}, $group->{$property}, format_string('breakpoint_group_load: Proper %property: %property1 == %property2 for breakpoint group %group.', $t_args), 'Breakpoint API');
}
}
// Ensure that the breakpoint group has the expected breakpoints.
$this->assertEqual(array_keys($compare_set->getBreakpoints()), array_keys($group->getBreakpoints()));
}
}
......@@ -47,12 +47,14 @@ public function testThemeBreakpoints() {
'sourceType' => Breakpoint::SOURCE_TYPE_THEME,
'id' => Breakpoint::SOURCE_TYPE_THEME . '.breakpoint_test_theme.breakpoint_test_theme',
));
$breakpoint_group_obj->breakpoints = array(
'theme.breakpoint_test_theme.mobile' => array(),
'theme.breakpoint_test_theme.narrow' => array(),
'theme.breakpoint_test_theme.wide' => array(),
'theme.breakpoint_test_theme.tv' => array(),
);
$breakpoint_group_obj->addBreakpoints(entity_load_multiple('breakpoint',
array(
'theme.breakpoint_test_theme.mobile',
'theme.breakpoint_test_theme.narrow',
'theme.breakpoint_test_theme.wide',
'theme.breakpoint_test_theme.tv',
)
));
// Verify we can load this breakpoint defined by the theme.
$this->verifyBreakpointGroup($breakpoint_group_obj);
......@@ -74,11 +76,13 @@ public function testThemeBreakpointGroup() {
'source' => 'breakpoint_test_theme',
'id' => Breakpoint::SOURCE_TYPE_THEME . '.breakpoint_test_theme.test',
));
$breakpoint_group_obj->breakpoints = array(
'theme.breakpoint_test_theme.mobile' => array('1.5x', '2.x'),
'theme.breakpoint_test_theme.narrow' => array(),
'theme.breakpoint_test_theme.wide' => array(),
);
$breakpoint_group_obj->addBreakpoints(entity_load_multiple('breakpoint',
array(
'theme.breakpoint_test_theme.mobile',
'theme.breakpoint_test_theme.narrow',
'theme.breakpoint_test_theme.wide',
)
));
// Verify we can load this breakpoint defined by the theme.
$this->verifyBreakpointGroup($breakpoint_group_obj);
......@@ -88,39 +92,4 @@ public function testThemeBreakpointGroup() {
$this->assertFalse(entity_load('breakpoint_group', $breakpoint_group_obj->id()), 'breakpoint_group_load: Loading a deleted breakpoint group returns false.', 'Breakpoint API');
}
/**
* Test the breakpoints defined by the custom group in the module.
*/
public function testThemeBreakpointGroupModule() {
// Call the import manually, since the testbot needs to enable the module
// first, otherwise the theme isn't detected.
_breakpoint_import_breakpoint_groups('breakpoint_theme_test', Breakpoint::SOURCE_TYPE_MODULE);
// Verify the breakpoint group 'module_test' was created by
// breakpoint_theme_test module.
$breakpoint_group_obj = entity_create('breakpoint_group', array(
'label' => 'Test Module',
'name' => 'module_test',
'sourceType' => Breakpoint::SOURCE_TYPE_MODULE,
'source' => 'breakpoint_theme_test',
'id' => Breakpoint::SOURCE_TYPE_MODULE . '.breakpoint_theme_test.module_test',
));
$breakpoint_group_obj->breakpoints = array(
'theme.breakpoint_test_theme.mobile' => array(),
'theme.breakpoint_test_theme.narrow' => array(),
'theme.breakpoint_test_theme.wide' => array(),
);
// Verify we can load this breakpoint defined by the theme.
$this->verifyBreakpointGroup($breakpoint_group_obj);
// Disable the test theme and verify the breakpoint group still exists.
theme_disable(array('breakpoint_test_theme'));
$this->assertTrue(entity_load('breakpoint_group', $breakpoint_group_obj->id()), 'Breakpoint group still exists if theme is disabled.');
// Uninstall the test module and verify the breakpoint group is deleted.
module_uninstall(array('breakpoint_theme_test'));
$this->assertFalse(entity_load('breakpoint_group', $breakpoint_group_obj->id()), 'Breakpoint group is removed if module is uninstalled.');
}
}