Skip to content
GitLab
Explore
Sign in
project
drupal
Compare revisions
7b8e20411889ddead83846c93d4e523f9b5096eb to 8.0-alpha6
Expand all
Hide whitespace changes
Inline
Side-by-side
core/lib/Drupal/Core/EventSubscriber/AjaxResponseSubscriber.php
0 → 100644
View file @
172cd265
<?php
/**
* @file
* Contains \Drupal\Core\EventSubscriber\AjaxResponseSubscriber.
*/
namespace
Drupal\Core\EventSubscriber
;
use
Drupal\Core\Ajax\AjaxResponse
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
use
Symfony\Component\HttpKernel\Event\FilterResponseEvent
;
use
Symfony\Component\HttpKernel\HttpKernelInterface
;
use
Symfony\Component\HttpKernel\KernelEvents
;
class
AjaxResponseSubscriber
implements
EventSubscriberInterface
{
/**
* Renders the ajax commands right before preparing the result.
*
* @param \Symfony\Component\HttpKernel\Event\FilterResponseEvent $event
* The response event, which contains the possible AjaxResponse object.
*/
public
function
onResponse
(
FilterResponseEvent
$event
)
{
$response
=
$event
->
getResponse
();
if
(
$response
instanceof
AjaxResponse
)
{
$response
->
prepareResponse
(
$event
->
getRequest
());
}
}
/**
* {@inheritdoc}
*/
public
static
function
getSubscribedEvents
()
{
$events
[
KernelEvents
::
RESPONSE
][]
=
array
(
'onResponse'
,
-
100
);
return
$events
;
}
}
core/lib/Drupal/Core/EventSubscriber/SpecialAttributesRouteSubscriber.php
View file @
172cd265
...
...
@@ -23,7 +23,6 @@ class SpecialAttributesRouteSubscriber extends RouteSubscriberBase {
*/
protected
function
alterRoutes
(
RouteCollection
$collection
,
$module
)
{
$special_variables
=
array
(
'_account'
,
'system_path'
,
'_maintenance'
,
'_legacy'
,
...
...
core/lib/Drupal/Core/Form/FormBase.php
View file @
172cd265
...
...
@@ -178,7 +178,7 @@ public function setRequest(Request $request) {
* The current user.
*/
protected
function
currentUser
()
{
return
$this
->
getRequest
()
->
attributes
->
get
(
'_account'
);
return
\Drupal
::
currentUser
(
);
}
/**
...
...
core/lib/Drupal/Core/Form/FormBuilder.php
View file @
172cd265
...
...
@@ -478,21 +478,6 @@ public function retrieveForm($form_id, &$form_state) {
// Record the $form_id.
$form_state
[
'build_info'
][
'form_id'
]
=
$form_id
;
// Record the filepath of the include file containing the original form, so
// the form builder callbacks can be loaded when the form is being rebuilt
// from cache on a different path (such as 'system/ajax'). See
// self::getCache(). Don't do this in maintenance mode as Drupal may not be
// fully bootstrapped (i.e. during installation) in which case
// menu_get_item() is not available.
if
(
!
isset
(
$form_state
[
'build_info'
][
'files'
][
'menu'
])
&&
!
defined
(
'MAINTENANCE_MODE'
))
{
$item
=
$this
->
menuGetItem
();
if
(
!
empty
(
$item
[
'include_file'
]))
{
// Do not use form_load_include() here, as the file is already loaded.
// Anyway, self::getCache() is able to handle filepaths too.
$form_state
[
'build_info'
][
'files'
][
'menu'
]
=
$item
[
'include_file'
];
}
}
// We save two copies of the incoming arguments: one for modules to use
// when mapping form ids to constructor functions, and another to pass to
// the constructor function itself.
...
...
@@ -1701,15 +1686,6 @@ protected function drupalInstallationAttempted() {
return
drupal_installation_attempted
();
}
/**
* Wraps menu_get_item().
*
* @return array|bool
*/
protected
function
menuGetItem
()
{
return
menu_get_item
();
}
/**
* Wraps watchdog().
*/
...
...
core/lib/Drupal/Core/Routing/Enhancer/AuthenticationEnhancer.php
View file @
172cd265
...
...
@@ -55,8 +55,6 @@ public function enhance(array $defaults, Request $request) {
$anonymous_user
=
drupal_anonymous_user
();
$this
->
container
->
set
(
'current_user'
,
$anonymous_user
,
'request'
);
// @todo Remove this in https://drupal.org/node/2073531
$request
->
attributes
->
set
(
'_account'
,
$anonymous_user
);
// The global $user object is included for backward compatibility only
// and should be considered deprecated.
...
...
core/lib/Drupal/Core/Theme/Registry.php
0 → 100644
View file @
172cd265
This diff is collapsed.
Click to expand it.
core/lib/Drupal/Core/Utility/ThemeRegistry.php
View file @
172cd265
...
...
@@ -8,16 +8,19 @@
namespace
Drupal\Core\Utility
;
use
Drupal\Core\Cache\CacheBackendInterface
;
use
Drupal\Core\Cache\CacheCollector
;
use
Drupal\Core\DestructableInterface
;
use
Drupal\Core\Lock\LockBackendInterface
;
/**
* Builds the run-time theme registry.
*
*
Extends CacheArray
to allow the theme registry to be accessed as a
*
A cache collector
to allow the theme registry to be accessed as a
* complete registry, while internally caching only the parts of the registry
* that are actually in use on the site. On cache misses the complete
* theme registry is loaded and used to update the run-time cache.
*/
class
ThemeRegistry
extends
Cache
Array
{
class
ThemeRegistry
extends
Cache
Collector
implements
DestructableInterface
{
/**
* Whether the partial registry can be persisted to the cache.
...
...
@@ -38,35 +41,42 @@ class ThemeRegistry extends CacheArray {
*
* @param string $cid
* The cid for the array being cached.
* @param string $bin
* The bin to cache the array.
* @param \Drupal\Core\Cache\CacheBackendInterface $cache
* The cache backend.
* @param \Drupal\Core\Lock\LockBackendInterface $lock
* The lock backend.
* @param array $tags
* (optional) The tags to specify for the cache item.
* @param bool $modules_loaded
* Whether all modules have already been loaded.
*/
function
__construct
(
$cid
,
$bin
,
$tags
,
$modules_loaded
=
FALSE
)
{
function
__construct
(
$cid
,
CacheBackendInterface
$cache
,
LockBackendInterface
$lock
,
$tags
=
array
(),
$modules_loaded
=
FALSE
)
{
$this
->
cid
=
$cid
;
$this
->
bin
=
$bin
;
$this
->
cache
=
$cache
;
$this
->
lock
=
$lock
;
$this
->
tags
=
$tags
;
$request
=
\Drupal
::
request
();
$this
->
persistable
=
$modules_loaded
&&
$request
->
isMethod
(
'GET'
);
if
(
$this
->
persistable
&&
$cached
=
cache
(
$this
->
bin
)
->
get
(
$this
->
cid
))
{
$data
=
$cached
->
data
;
// @todo: Implement lazyload.
$this
->
cacheLoaded
=
TRUE
;
if
(
$this
->
persistable
&&
$cached
=
$this
->
cache
->
get
(
$this
->
cid
))
{
$this
->
storage
=
$cached
->
data
;
}
else
{
// If there is no runtime cache stored, fetch the full theme registry,
// but then initialize each value to NULL. This allows offsetExists()
// to function correctly on non-registered theme hooks without triggering
// a call to resolveCacheMiss().
$
data
=
$this
->
initializeRegistry
();
if
(
$this
->
persistable
)
{
$this
->
set
(
$data
);
$
this
->
storage
=
$this
->
initializeRegistry
();
foreach
(
array_keys
(
$this
->
storage
)
as
$key
)
{
$this
->
persist
(
$key
);
}
// RegistryTest::testRaceCondition() ensures that the cache entry is
// written on the initial construction of the theme registry.
$this
->
updateCache
();
}
$this
->
storage
=
$data
;
}
/**
...
...
@@ -77,58 +87,73 @@ function __construct($cid, $bin, $tags, $modules_loaded = FALSE) {
* initialized to NULL.
*/
function
initializeRegistry
()
{
$this
->
completeRegistry
=
theme_get_registry
();
// @todo DIC this.
$this
->
completeRegistry
=
\Drupal
::
service
(
'theme.registry'
)
->
get
();
return
array_fill_keys
(
array_keys
(
$this
->
completeRegistry
),
NULL
);
}
/**
*
Overrides CacheArray::offsetExists().
*
{@inheritdoc}
*/
public
function
offsetExists
(
$offset
)
{
public
function
has
(
$key
)
{
// Since the theme registry allows for theme hooks to be requested that
// are not registered, just check the existence of the key in the registry.
// Use array_key_exists() here since a NULL value indicates that the theme
// hook exists but has not yet been requested.
return
array_key_exists
(
$
offset
,
$this
->
storage
);
return
array_key_exists
(
$
key
,
$this
->
storage
);
}
/**
*
Overrides CacheArray::offsetGet().
*
{@inheritdoc}
*/
public
function
offsetGet
(
$offset
)
{
public
function
get
(
$key
)
{
// If the offset is set but empty, it is a registered theme hook that has
// not yet been requested. Offsets that do not exist at all were not
// registered in hook_theme().
if
(
isset
(
$this
->
storage
[
$
offset
]))
{
return
$this
->
storage
[
$
offset
];
if
(
isset
(
$this
->
storage
[
$
key
]))
{
return
$this
->
storage
[
$
key
];
}
elseif
(
array_key_exists
(
$
offset
,
$this
->
storage
))
{
return
$this
->
resolveCacheMiss
(
$
offset
);
elseif
(
array_key_exists
(
$
key
,
$this
->
storage
))
{
return
$this
->
resolveCacheMiss
(
$
key
);
}
}
/**
*
Implements CacheArray::resolveCacheMiss().
*
{@inheritdoc}
*/
public
function
resolveCacheMiss
(
$
offset
)
{
public
function
resolveCacheMiss
(
$
key
)
{
if
(
!
isset
(
$this
->
completeRegistry
))
{
$this
->
completeRegistry
=
theme_get_
registry
();
$this
->
completeRegistry
=
\Drupal
::
service
(
'theme.
registry
'
)
->
get
();
}
$this
->
storage
[
$
offset
]
=
$this
->
completeRegistry
[
$
offset
];
$this
->
storage
[
$
key
]
=
$this
->
completeRegistry
[
$
key
];
if
(
$this
->
persistable
)
{
$this
->
persist
(
$
offset
);
$this
->
persist
(
$
key
);
}
return
$this
->
storage
[
$
offset
];
return
$this
->
storage
[
$
key
];
}
/**
*
Overrides CacheArray::set().
*
{@inheritdoc}
*/
public
function
set
(
$data
,
$lock
=
TRUE
)
{
$lock_name
=
$this
->
cid
.
':'
.
$this
->
bin
;
if
(
!
$lock
||
lock
()
->
acquire
(
$lock_name
))
{
if
(
$cached
=
cache
(
$this
->
bin
)
->
get
(
$this
->
cid
))
{
protected
function
updateCache
(
$lock
=
TRUE
)
{
if
(
!
$this
->
persistable
)
{
return
;
}
// @todo: Is the custom implementation necessary?
$data
=
array
();
foreach
(
$this
->
keysToPersist
as
$offset
=>
$persist
)
{
if
(
$persist
)
{
$data
[
$offset
]
=
$this
->
storage
[
$offset
];
}
}
if
(
empty
(
$data
))
{
return
;
}
$lock_name
=
$this
->
cid
.
':'
.
__CLASS__
;
if
(
!
$lock
||
$this
->
lock
->
acquire
(
$lock_name
))
{
if
(
$cached
=
$this
->
cache
->
get
(
$this
->
cid
))
{
// Use array merge instead of union so that filled in values in $data
// overwrite empty values in the current cache.
$data
=
array_merge
(
$cached
->
data
,
$data
);
...
...
@@ -137,10 +162,11 @@ public function set($data, $lock = TRUE) {
$registry
=
$this
->
initializeRegistry
();
$data
=
array_merge
(
$registry
,
$data
);
}
cache
(
$this
->
bin
)
->
set
(
$this
->
cid
,
$data
,
CacheBackendInterface
::
CACHE_PERMANENT
,
$this
->
tags
);
$this
->
cache
->
set
(
$this
->
cid
,
$data
,
CacheBackendInterface
::
CACHE_PERMANENT
,
$this
->
tags
);
if
(
$lock
)
{
lock
()
->
release
(
$lock_name
);
$this
->
lock
->
release
(
$lock_name
);
}
}
}
}
core/modules/action/action.views.inc
View file @
172cd265
...
...
@@ -2,9 +2,7 @@
/**
* @file
* Provides views data and handlers for action.module.
*
* @ingroup views_module_handlers
* Provides views data for action.module.
*/
/**
...
...
core/modules/aggregator/aggregator.views.inc
View file @
172cd265
...
...
@@ -3,8 +3,6 @@
/**
* @file
* Provides views data for aggregator.module.
*
* @ingroup views_module_handlers
*/
/**
...
...
core/modules/block/custom_block/lib/Drupal/custom_block/Entity/CustomBlock.php
View file @
172cd265
...
...
@@ -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
{
...
...
core/modules/block/tests/Drupal/block/Tests/BlockBaseTest.php
View file @
172cd265
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\
Tests\block
\BlockBaseTest.
* Contains \Drupal\
block\Tests
\BlockBaseTest.
*/
namespace
Drupal\
Tests\block
;
namespace
Drupal\
block\Tests
;
use
Drupal\block_test
\Plugin\Block\TestBlockInstantiation
;
use
Drupal\Core\DependencyInjection\ContainerBuilder
;
...
...
core/modules/block/tests/Drupal/block/Tests/BlockFormControllerTest.php
View file @
172cd265
...
...
@@ -2,10 +2,10 @@
/**
* @file
* Contains \Drupal\
Tests\block
\BlockFormControllerTest.
* Contains \Drupal\
block\Tests
\BlockFormControllerTest.
*/
namespace
Drupal\
Tests\block
;
namespace
Drupal\
block\Tests
;
use
Drupal\block\BlockFormController
;
use
Drupal\Tests\UnitTestCase
;
...
...
core/modules/book/book.module
View file @
172cd265
...
...
@@ -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'
);
...
...
core/modules/breakpoint/breakpoint.install
deleted
100644 → 0
View file @
7b8e2041
<?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
()));
}
core/modules/breakpoint/breakpoint.module
View file @
172cd265
...
...
@@ -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
;
}
core/modules/breakpoint/config/breakpoint.settings.yml
deleted
100644 → 0
View file @
7b8e2041
multipliers
:
-
1x
-
1.5x
-
2x
core/modules/breakpoint/config/schema/breakpoint.schema.yml
View file @
172cd265
# 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'
...
...
core/modules/breakpoint/lib/Drupal/breakpoint/BreakpointGroupInterface.php
View file @
172cd265
...
...
@@ -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
);
}
core/modules/breakpoint/lib/Drupal/breakpoint/Entity/BreakpointGroup.php
View file @
172cd265
...
...
@@ -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
*/
p
ublic
$breakpoints
=
array
();
p
rotected
$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
_id
s
),
));
$breakpoint
->
save
();
}
$this
->
b
reakpoints
[
$breakpoint
->
id
()]
=
$breakpoint
;
return
$this
->
addB
reakpoints
(
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
;
}
}
core/modules/breakpoint/lib/Drupal/breakpoint/Tests/BreakpointGroupCRUDTest.php
View file @
172cd265
...
...
@@ -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.
...
...
Prev
1
2
3
4
5
6
…
15
Next