Update core 8.3.0
This commit is contained in:
parent
da7a7918f8
commit
cd7a898e66
6144 changed files with 132297 additions and 87747 deletions
|
@ -78,7 +78,7 @@ class AccessManager implements AccessManagerInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function checkNamedRoute($route_name, array $parameters = array(), AccountInterface $account = NULL, $return_as_object = FALSE) {
|
||||
public function checkNamedRoute($route_name, array $parameters = [], AccountInterface $account = NULL, $return_as_object = FALSE) {
|
||||
try {
|
||||
$route = $this->routeProvider->getRouteByName($route_name, $parameters);
|
||||
|
||||
|
@ -120,7 +120,7 @@ class AccessManager implements AccessManagerInterface {
|
|||
$account = $this->currentUser;
|
||||
}
|
||||
$route = $route_match->getRouteObject();
|
||||
$checks = $route->getOption('_access_checks') ?: array();
|
||||
$checks = $route->getOption('_access_checks') ?: [];
|
||||
|
||||
// Filter out checks which require the incoming request.
|
||||
if (!isset($request)) {
|
||||
|
@ -130,10 +130,6 @@ class AccessManager implements AccessManagerInterface {
|
|||
$result = AccessResult::neutral();
|
||||
if (!empty($checks)) {
|
||||
$arguments_resolver = $this->argumentsResolverFactory->getArgumentsResolver($route_match, $account, $request);
|
||||
|
||||
if (!$checks) {
|
||||
return AccessResult::neutral();
|
||||
}
|
||||
$result = AccessResult::allowed();
|
||||
foreach ($checks as $service_id) {
|
||||
$result = $result->andIf($this->performCheck($service_id, $arguments_resolver));
|
||||
|
|
|
@ -33,7 +33,7 @@ interface AccessManagerInterface {
|
|||
* returned, i.e. TRUE means access is explicitly allowed, FALSE means
|
||||
* access is either explicitly forbidden or "no opinion".
|
||||
*/
|
||||
public function checkNamedRoute($route_name, array $parameters = array(), AccountInterface $account = NULL, $return_as_object = FALSE);
|
||||
public function checkNamedRoute($route_name, array $parameters = [], AccountInterface $account = NULL, $return_as_object = FALSE);
|
||||
|
||||
/**
|
||||
* Execute access checks against the incoming request.
|
||||
|
|
|
@ -31,17 +31,22 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable
|
|||
/**
|
||||
* Creates an AccessResultInterface object with isNeutral() === TRUE.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResult
|
||||
* @param string|null $reason
|
||||
* (optional) The reason why access is forbidden. Intended for developers,
|
||||
* hence not translatable.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResultNeutral
|
||||
* isNeutral() will be TRUE.
|
||||
*/
|
||||
public static function neutral() {
|
||||
return new AccessResultNeutral();
|
||||
public static function neutral($reason = NULL) {
|
||||
assert('is_string($reason) || is_null($reason)');
|
||||
return new AccessResultNeutral($reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an AccessResultInterface object with isAllowed() === TRUE.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResult
|
||||
* @return \Drupal\Core\Access\AccessResultAllowed
|
||||
* isAllowed() will be TRUE.
|
||||
*/
|
||||
public static function allowed() {
|
||||
|
@ -55,7 +60,7 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable
|
|||
* (optional) The reason why access is forbidden. Intended for developers,
|
||||
* hence not translatable.
|
||||
*
|
||||
* @return \Drupal\Core\Access\AccessResult
|
||||
* @return \Drupal\Core\Access\AccessResultForbidden
|
||||
* isForbidden() will be TRUE.
|
||||
*/
|
||||
public static function forbidden($reason = NULL) {
|
||||
|
@ -106,7 +111,12 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable
|
|||
* isNeutral() will be TRUE.
|
||||
*/
|
||||
public static function allowedIfHasPermission(AccountInterface $account, $permission) {
|
||||
return static::allowedIf($account->hasPermission($permission))->addCacheContexts(['user.permissions']);
|
||||
$access_result = static::allowedIf($account->hasPermission($permission))->addCacheContexts(['user.permissions']);
|
||||
|
||||
if ($access_result instanceof AccessResultReasonInterface) {
|
||||
$access_result->setReason("The '$permission' permission is required.");
|
||||
}
|
||||
return $access_result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -147,7 +157,21 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable
|
|||
}
|
||||
}
|
||||
|
||||
return static::allowedIf($access)->addCacheContexts(empty($permissions) ? [] : ['user.permissions']);
|
||||
$access_result = static::allowedIf($access)->addCacheContexts(empty($permissions) ? [] : ['user.permissions']);
|
||||
|
||||
if ($access_result instanceof AccessResultReasonInterface) {
|
||||
if (count($permissions) === 1) {
|
||||
$access_result->setReason("The '$permission' permission is required.");
|
||||
}
|
||||
elseif (count($permissions) > 1) {
|
||||
$quote = function ($s) {
|
||||
return "'$s'";
|
||||
};
|
||||
$access_result->setReason(sprintf("The following permissions are required: %s.", implode(" $conjunction ", array_map($quote, $permissions))));
|
||||
}
|
||||
}
|
||||
|
||||
return $access_result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -237,7 +261,7 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable
|
|||
* @return $this
|
||||
*/
|
||||
public function cachePerPermissions() {
|
||||
$this->addCacheContexts(array('user.permissions'));
|
||||
$this->addCacheContexts(['user.permissions']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -247,7 +271,7 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable
|
|||
* @return $this
|
||||
*/
|
||||
public function cachePerUser() {
|
||||
$this->addCacheContexts(array('user'));
|
||||
$this->addCacheContexts(['user']);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -308,6 +332,13 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable
|
|||
if (!$this->isForbidden() || ($this->getCacheMaxAge() === 0 && $other->isForbidden())) {
|
||||
$merge_other = TRUE;
|
||||
}
|
||||
|
||||
if ($this->isForbidden() && $this instanceof AccessResultReasonInterface) {
|
||||
$result->setReason($this->getReason());
|
||||
}
|
||||
elseif ($other->isForbidden() && $other instanceof AccessResultReasonInterface) {
|
||||
$result->setReason($other->getReason());
|
||||
}
|
||||
}
|
||||
elseif ($this->isAllowed() || $other->isAllowed()) {
|
||||
$result = static::allowed();
|
||||
|
@ -319,6 +350,14 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable
|
|||
$result = static::neutral();
|
||||
if (!$this->isNeutral() || ($this->getCacheMaxAge() === 0 && $other->isNeutral()) || ($this->getCacheMaxAge() !== 0 && $other instanceof CacheableDependencyInterface && $other->getCacheMaxAge() !== 0)) {
|
||||
$merge_other = TRUE;
|
||||
if ($other instanceof AccessResultReasonInterface) {
|
||||
$result->setReason($other->getReason());
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($this instanceof AccessResultReasonInterface) {
|
||||
$result->setReason($this->getReason());
|
||||
}
|
||||
}
|
||||
}
|
||||
$result->inheritCacheability($this);
|
||||
|
@ -358,6 +397,14 @@ abstract class AccessResult implements AccessResultInterface, RefinableCacheable
|
|||
$result = static::neutral();
|
||||
if (!$this->isNeutral()) {
|
||||
$merge_other = TRUE;
|
||||
if ($other instanceof AccessResultReasonInterface) {
|
||||
$result->setReason($other->getReason());
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($this instanceof AccessResultReasonInterface) {
|
||||
$result->setReason($this->getReason());
|
||||
}
|
||||
}
|
||||
}
|
||||
$result->inheritCacheability($this);
|
||||
|
|
|
@ -5,7 +5,24 @@ namespace Drupal\Core\Access;
|
|||
/**
|
||||
* Value object indicating a neutral access result, with cacheability metadata.
|
||||
*/
|
||||
class AccessResultNeutral extends AccessResult {
|
||||
class AccessResultNeutral extends AccessResult implements AccessResultReasonInterface {
|
||||
|
||||
/**
|
||||
* The reason why access is neutral. For use in messages.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $reason;
|
||||
|
||||
/**
|
||||
* Constructs a new AccessResultNeutral instance.
|
||||
*
|
||||
* @param null|string $reason
|
||||
* (optional) a message to provide details about this access result
|
||||
*/
|
||||
public function __construct($reason = NULL) {
|
||||
$this->reason = $reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -14,4 +31,19 @@ class AccessResultNeutral extends AccessResult {
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getReason() {
|
||||
return $this->reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setReason($reason) {
|
||||
$this->reason = $reason;
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class CheckProvider implements CheckProviderInterface, ContainerAwareInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $checkIds = array();
|
||||
protected $checkIds = [];
|
||||
|
||||
/**
|
||||
* Array of access check objects keyed by service id.
|
||||
|
@ -34,12 +34,12 @@ class CheckProvider implements CheckProviderInterface, ContainerAwareInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $checkMethods = array();
|
||||
protected $checkMethods = [];
|
||||
|
||||
/**
|
||||
* Array of access checks which only will be run on the incoming request.
|
||||
*/
|
||||
protected $checksNeedsRequest = array();
|
||||
protected $checksNeedsRequest = [];
|
||||
|
||||
/**
|
||||
* An array to map static requirement keys to service IDs.
|
||||
|
@ -58,7 +58,7 @@ class CheckProvider implements CheckProviderInterface, ContainerAwareInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function addCheckService($service_id, $service_method, array $applies_checks = array(), $needs_incoming_request = FALSE) {
|
||||
public function addCheckService($service_id, $service_method, array $applies_checks = [], $needs_incoming_request = FALSE) {
|
||||
$this->checkIds[] = $service_id;
|
||||
$this->checkMethods[$service_id] = $service_method;
|
||||
if ($needs_incoming_request) {
|
||||
|
@ -102,7 +102,7 @@ class CheckProvider implements CheckProviderInterface, ContainerAwareInterface {
|
|||
if (!($check instanceof AccessInterface)) {
|
||||
throw new AccessException('All access checks must implement AccessInterface.');
|
||||
}
|
||||
if (!is_callable(array($check, $this->checkMethods[$service_id]))) {
|
||||
if (!is_callable([$check, $this->checkMethods[$service_id]])) {
|
||||
throw new AccessException(sprintf('Access check method %s in service %s must be callable.', $this->checkMethods[$service_id], $service_id));
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ class CheckProvider implements CheckProviderInterface, ContainerAwareInterface {
|
|||
* route.
|
||||
*/
|
||||
protected function applies(Route $route) {
|
||||
$checks = array();
|
||||
$checks = [];
|
||||
|
||||
// Iterate through map requirements from appliesTo() on access checkers.
|
||||
// Only iterate through all checkIds if this is not used.
|
||||
|
@ -151,7 +151,7 @@ class CheckProvider implements CheckProviderInterface, ContainerAwareInterface {
|
|||
}
|
||||
|
||||
// Set them here, so we can use the isset() check above.
|
||||
$this->dynamicRequirementMap = array();
|
||||
$this->dynamicRequirementMap = [];
|
||||
|
||||
foreach ($this->checkIds as $service_id) {
|
||||
if (empty($this->checks[$service_id])) {
|
||||
|
|
|
@ -37,7 +37,7 @@ interface CheckProviderInterface {
|
|||
* @param bool $needs_incoming_request
|
||||
* (optional) True if access-check method only acts on an incoming request.
|
||||
*/
|
||||
public function addCheckService($service_id, $service_method, array $applies_checks = array(), $needs_incoming_request = FALSE);
|
||||
public function addCheckService($service_id, $service_method, array $applies_checks = [], $needs_incoming_request = FALSE);
|
||||
|
||||
/**
|
||||
* Lazy-loads access check services.
|
||||
|
|
|
@ -58,7 +58,7 @@ class CsrfAccessCheck implements RoutingAccessInterface {
|
|||
$result = AccessResult::allowed();
|
||||
}
|
||||
else {
|
||||
$result = AccessResult::forbidden();
|
||||
$result = AccessResult::forbidden($request->query->has('token') ? "'csrf_token' URL query argument is invalid." : "'csrf_token' URL query argument is missing.");
|
||||
}
|
||||
// Not cacheable because the CSRF token is highly dynamic.
|
||||
return $result->setCacheMaxAge(0);
|
||||
|
|
|
@ -64,7 +64,7 @@ class CsrfRequestHeaderAccessCheck implements AccessCheckInterface {
|
|||
$methods = explode('|', $requirements['_method']);
|
||||
// CSRF protection only applies to write operations, so we can filter
|
||||
// out any routes that require reading methods only.
|
||||
$write_methods = array_diff($methods, array('GET', 'HEAD', 'OPTIONS', 'TRACE'));
|
||||
$write_methods = array_diff($methods, ['GET', 'HEAD', 'OPTIONS', 'TRACE']);
|
||||
if (empty($write_methods)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ class CsrfRequestHeaderAccessCheck implements AccessCheckInterface {
|
|||
// 1. this is a write operation
|
||||
// 2. the user was successfully authenticated and
|
||||
// 3. the request comes with a session cookie.
|
||||
if (!in_array($method, array('GET', 'HEAD', 'OPTIONS', 'TRACE'))
|
||||
if (!in_array($method, ['GET', 'HEAD', 'OPTIONS', 'TRACE'])
|
||||
&& $account->isAuthenticated()
|
||||
&& $this->sessionConfiguration->hasSession($request)
|
||||
) {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Drupal\Core\Access;
|
||||
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Core\Render\BubbleableMetadata;
|
||||
use Drupal\Core\RouteProcessor\OutboundRouteProcessorInterface;
|
||||
use Symfony\Component\Routing\Route;
|
||||
|
@ -24,7 +25,7 @@ class RouteProcessorCsrf implements OutboundRouteProcessorInterface {
|
|||
* @param \Drupal\Core\Access\CsrfTokenGenerator $csrf_token
|
||||
* The CSRF token generator.
|
||||
*/
|
||||
function __construct(CsrfTokenGenerator $csrf_token) {
|
||||
public function __construct(CsrfTokenGenerator $csrf_token) {
|
||||
$this->csrfToken = $csrf_token;
|
||||
}
|
||||
|
||||
|
@ -45,7 +46,7 @@ class RouteProcessorCsrf implements OutboundRouteProcessorInterface {
|
|||
}
|
||||
else {
|
||||
// Generate a placeholder and a render array to replace it.
|
||||
$placeholder = hash('sha1', $path);
|
||||
$placeholder = Crypt::hashBase64($path);
|
||||
$placeholder_render_array = [
|
||||
'#lazy_builder' => ['route_processor_csrf:renderPlaceholderCsrfToken', [$path]],
|
||||
];
|
||||
|
|
|
@ -24,7 +24,7 @@ abstract class ConfigurableActionBase extends ActionBase implements Configurable
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,7 @@ abstract class ConfigurableActionBase extends ActionBase implements Configurable
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,10 +39,10 @@ class AddCssCommand implements CommandInterface {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'add_css',
|
||||
'data' => $this->styles,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ class AfterCommand extends InsertCommand {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'insert',
|
||||
'method' => 'after',
|
||||
'selector' => $this->selector,
|
||||
'data' => $this->getRenderedContent(),
|
||||
'settings' => $this->settings,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class AjaxResponse extends JsonResponse implements AttachmentsInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $commands = array();
|
||||
protected $commands = [];
|
||||
|
||||
/**
|
||||
* Add an AJAX command to the response.
|
||||
|
|
|
@ -167,7 +167,7 @@ class AjaxResponseAttachmentsProcessor implements AttachmentsResponseProcessorIn
|
|||
}
|
||||
|
||||
// Prepend commands to add the assets, preserving their relative order.
|
||||
$resource_commands = array();
|
||||
$resource_commands = [];
|
||||
if ($css_assets) {
|
||||
$css_render_array = $this->cssCollectionRenderer->render($css_assets);
|
||||
$resource_commands[] = new AddCssCommand($this->renderer->renderPlain($css_render_array));
|
||||
|
|
|
@ -31,10 +31,10 @@ class AlertCommand implements CommandInterface {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'alert',
|
||||
'text' => $this->text,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ class AppendCommand extends InsertCommand {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'insert',
|
||||
'method' => 'append',
|
||||
'selector' => $this->selector,
|
||||
'data' => $this->getRenderedContent(),
|
||||
'settings' => $this->settings,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@ class BaseCommand implements CommandInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function render() {
|
||||
return array(
|
||||
return [
|
||||
'command' => $this->command,
|
||||
'data' => $this->data,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ class BeforeCommand extends InsertCommand {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'insert',
|
||||
'method' => 'before',
|
||||
'selector' => $this->selector,
|
||||
'data' => $this->getRenderedContent(),
|
||||
'settings' => $this->settings,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,11 +50,11 @@ class ChangedCommand implements CommandInterface {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'changed',
|
||||
'selector' => $this->selector,
|
||||
'asterisk' => $this->asterisk,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,11 +40,11 @@ class CloseDialogCommand implements CommandInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function render() {
|
||||
return array(
|
||||
return [
|
||||
'command' => 'closeDialog',
|
||||
'selector' => $this->selector,
|
||||
'persist' => $this->persist,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ class CssCommand implements CommandInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $css = array();
|
||||
protected $css = [];
|
||||
|
||||
/**
|
||||
* Constructs a CssCommand object.
|
||||
|
@ -42,7 +42,7 @@ class CssCommand implements CommandInterface {
|
|||
* @param array $css
|
||||
* An array of CSS property/value pairs to set.
|
||||
*/
|
||||
public function __construct($selector, array $css = array()) {
|
||||
public function __construct($selector, array $css = []) {
|
||||
$this->selector = $selector;
|
||||
$this->css = $css;
|
||||
}
|
||||
|
@ -67,11 +67,11 @@ class CssCommand implements CommandInterface {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'css',
|
||||
'selector' => $this->selector,
|
||||
'argument' => $this->css,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -62,12 +62,12 @@ class DataCommand implements CommandInterface {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'data',
|
||||
'selector' => $this->selector,
|
||||
'name' => $this->name,
|
||||
'value' => $this->value,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ class HtmlCommand extends InsertCommand {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'insert',
|
||||
'method' => 'html',
|
||||
'selector' => $this->selector,
|
||||
'data' => $this->getRenderedContent(),
|
||||
'settings' => $this->settings,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -66,13 +66,13 @@ class InsertCommand implements CommandInterface, CommandWithAttachedAssetsInterf
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'insert',
|
||||
'method' => NULL,
|
||||
'selector' => $this->selector,
|
||||
'data' => $this->getRenderedContent(),
|
||||
'settings' => $this->settings,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ class InvokeCommand implements CommandInterface {
|
|||
* @param array $arguments
|
||||
* An optional array of arguments to pass to the method.
|
||||
*/
|
||||
public function __construct($selector, $method, array $arguments = array()) {
|
||||
public function __construct($selector, $method, array $arguments = []) {
|
||||
$this->selector = $selector;
|
||||
$this->method = $method;
|
||||
$this->arguments = $arguments;
|
||||
|
@ -62,12 +62,12 @@ class InvokeCommand implements CommandInterface {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'invoke',
|
||||
'selector' => $this->selector,
|
||||
'method' => $this->method,
|
||||
'args' => $this->arguments,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -70,9 +70,9 @@ class OpenDialogCommand implements CommandInterface, CommandWithAttachedAssetsIn
|
|||
* on the content of the dialog. If left empty, the settings will be
|
||||
* populated automatically from the current request.
|
||||
*/
|
||||
public function __construct($selector, $title, $content, array $dialog_options = array(), $settings = NULL) {
|
||||
public function __construct($selector, $title, $content, array $dialog_options = [], $settings = NULL) {
|
||||
$title = PlainTextOutput::renderFromHtml($title);
|
||||
$dialog_options += array('title' => $title);
|
||||
$dialog_options += ['title' => $title];
|
||||
$this->selector = $selector;
|
||||
$this->content = $content;
|
||||
$this->dialogOptions = $dialog_options;
|
||||
|
@ -128,13 +128,13 @@ class OpenDialogCommand implements CommandInterface, CommandWithAttachedAssetsIn
|
|||
public function render() {
|
||||
// For consistency ensure the modal option is set to TRUE or FALSE.
|
||||
$this->dialogOptions['modal'] = isset($this->dialogOptions['modal']) && $this->dialogOptions['modal'];
|
||||
return array(
|
||||
return [
|
||||
'command' => 'openDialog',
|
||||
'selector' => $this->selector,
|
||||
'settings' => $this->settings,
|
||||
'data' => $this->getRenderedContent(),
|
||||
'dialogOptions' => $this->dialogOptions,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class OpenModalDialogCommand extends OpenDialogCommand {
|
|||
* on the content of the dialog. If left empty, the settings will be
|
||||
* populated automatically from the current request.
|
||||
*/
|
||||
public function __construct($title, $content, array $dialog_options = array(), $settings = NULL) {
|
||||
public function __construct($title, $content, array $dialog_options = [], $settings = NULL) {
|
||||
$dialog_options['modal'] = TRUE;
|
||||
parent::__construct('#drupal-modal', $title, $content, $dialog_options, $settings);
|
||||
}
|
||||
|
|
|
@ -23,13 +23,13 @@ class PrependCommand extends InsertCommand {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'insert',
|
||||
'method' => 'prepend',
|
||||
'selector' => $this->selector,
|
||||
'data' => $this->getRenderedContent(),
|
||||
'settings' => $this->settings,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,10 +31,10 @@ class RedirectCommand implements CommandInterface {
|
|||
* Implements \Drupal\Core\Ajax\CommandInterface:render().
|
||||
*/
|
||||
public function render() {
|
||||
return array(
|
||||
return [
|
||||
'command' => 'redirect',
|
||||
'url' => $this->url,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@ class RemoveCommand implements CommandInterface {
|
|||
* Implements Drupal\Core\Ajax\CommandInterface:render().
|
||||
*/
|
||||
public function render() {
|
||||
return array(
|
||||
return [
|
||||
'command' => 'remove',
|
||||
'selector' => $this->selector,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,13 +24,13 @@ class ReplaceCommand extends InsertCommand {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'insert',
|
||||
'method' => 'replaceWith',
|
||||
'selector' => $this->selector,
|
||||
'data' => $this->getRenderedContent(),
|
||||
'settings' => $this->settings,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,10 +40,10 @@ class RestripeCommand implements CommandInterface {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'restripe',
|
||||
'selector' => $this->selector,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,12 +52,12 @@ class SetDialogOptionCommand implements CommandInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function render() {
|
||||
return array(
|
||||
return [
|
||||
'command' => 'setDialogOption',
|
||||
'selector' => $this->selector,
|
||||
'optionName' => $this->optionName,
|
||||
'optionValue' => $this->optionValue,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,11 +54,11 @@ class SettingsCommand implements CommandInterface {
|
|||
*/
|
||||
public function render() {
|
||||
|
||||
return array(
|
||||
return [
|
||||
'command' => 'settings',
|
||||
'settings' => $this->settings,
|
||||
'merge' => $this->merge,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -99,11 +99,11 @@ class ContextDefinition extends Plugin {
|
|||
* ContextDefinitionInterface implementing class.
|
||||
*/
|
||||
public function __construct(array $values) {
|
||||
$values += array(
|
||||
$values += [
|
||||
'required' => TRUE,
|
||||
'multiple' => FALSE,
|
||||
'default_value' => NULL,
|
||||
);
|
||||
];
|
||||
// Annotation classes extract data from passed annotation classes directly
|
||||
// used in the classes they pass to.
|
||||
foreach (['label', 'description'] as $key) {
|
||||
|
|
|
@ -74,12 +74,12 @@ class Translation extends AnnotationBase {
|
|||
*/
|
||||
public function __construct(array $values) {
|
||||
$string = $values['value'];
|
||||
$arguments = isset($values['arguments']) ? $values['arguments'] : array();
|
||||
$options = array();
|
||||
$arguments = isset($values['arguments']) ? $values['arguments'] : [];
|
||||
$options = [];
|
||||
if (!empty($values['context'])) {
|
||||
$options = array(
|
||||
$options = [
|
||||
'context' => $values['context'],
|
||||
);
|
||||
];
|
||||
}
|
||||
$this->translation = new TranslatableMarkup($string, $arguments, $options);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ interface ArchiverInterface {
|
|||
* @return \Drupal\Core\Archiver\ArchiverInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function extract($path, array $files = array());
|
||||
public function extract($path, array $files = []);
|
||||
|
||||
/**
|
||||
* Lists all files in the archive.
|
||||
|
|
|
@ -36,7 +36,7 @@ class ArchiverManager extends DefaultPluginManager {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createInstance($plugin_id, array $configuration = array()) {
|
||||
public function createInstance($plugin_id, array $configuration = []) {
|
||||
$plugin_definition = $this->getDefinition($plugin_id);
|
||||
$plugin_class = DefaultFactory::getPluginClass($plugin_id, $plugin_definition, 'Drupal\Core\Archiver\ArchiverInterface');
|
||||
return new $plugin_class($configuration['filepath']);
|
||||
|
|
|
@ -52,7 +52,7 @@ class Tar implements ArchiverInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function extract($path, array $files = array()) {
|
||||
public function extract($path, array $files = []) {
|
||||
if ($files) {
|
||||
$this->tar->extractList($files, $path);
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ class Tar implements ArchiverInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function listContents() {
|
||||
$files = array();
|
||||
$files = [];
|
||||
foreach ($this->tar->listContent() as $file_data) {
|
||||
$files[] = $file_data['filename'];
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class Zip implements ArchiverInterface {
|
|||
public function __construct($file_path) {
|
||||
$this->zip = new \ZipArchive();
|
||||
if ($this->zip->open($file_path) !== TRUE) {
|
||||
throw new ArchiverException(t('Cannot open %file_path', array('%file_path' => $file_path)));
|
||||
throw new ArchiverException(t('Cannot open %file_path', ['%file_path' => $file_path]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ class Zip implements ArchiverInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function extract($path, array $files = array()) {
|
||||
public function extract($path, array $files = []) {
|
||||
if ($files) {
|
||||
$this->zip->extractTo($path, $files);
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ class Zip implements ArchiverInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function listContents() {
|
||||
$files = array();
|
||||
$files = [];
|
||||
for ($i = 0; $i < $this->zip->numFiles; $i++) {
|
||||
$files[] = $this->zip->getNameIndex($i);
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class CssCollectionGrouper implements AssetCollectionGrouperInterface {
|
|||
* type, media, and browsers, if needed to accommodate other items in between.
|
||||
*/
|
||||
public function group(array $css_assets) {
|
||||
$groups = array();
|
||||
$groups = [];
|
||||
// If a group can contain multiple items, we track the information that must
|
||||
// be the same for each item in the group, so that when we iterate the next
|
||||
// item, we can determine if it can be put into the current group, or if a
|
||||
|
@ -52,7 +52,7 @@ class CssCollectionGrouper implements AssetCollectionGrouperInterface {
|
|||
// Group file items if their 'preprocess' flag is TRUE.
|
||||
// Help ensure maximum reuse of aggregate files by only grouping
|
||||
// together items that share the same 'group' value.
|
||||
$group_keys = $item['preprocess'] ? array($item['type'], $item['group'], $item['media'], $item['browsers']) : FALSE;
|
||||
$group_keys = $item['preprocess'] ? [$item['type'], $item['group'], $item['media'], $item['browsers']] : FALSE;
|
||||
break;
|
||||
|
||||
case 'external':
|
||||
|
@ -71,7 +71,7 @@ class CssCollectionGrouper implements AssetCollectionGrouperInterface {
|
|||
// the group.
|
||||
$groups[$i] = $item;
|
||||
unset($groups[$i]['data'], $groups[$i]['weight'], $groups[$i]['basename']);
|
||||
$groups[$i]['items'] = array();
|
||||
$groups[$i]['items'] = [];
|
||||
$current_group_keys = $group_keys ? $group_keys : NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,8 @@ class CssCollectionOptimizer implements AssetCollectionOptimizerInterface {
|
|||
// Drupal contrib can override this default CSS aggregator to keep the same
|
||||
// grouping, optimizing and dumping, but change the strategy that is used to
|
||||
// determine when the aggregate should be rebuilt (e.g. mtime, HTTPS …).
|
||||
$map = $this->state->get('drupal_css_cache_files') ?: array();
|
||||
$css_assets = array();
|
||||
$map = $this->state->get('drupal_css_cache_files') ?: [];
|
||||
$css_assets = [];
|
||||
foreach ($css_groups as $order => $css_group) {
|
||||
// We have to return a single asset, not a group of assets. It is now up
|
||||
// to one of the pieces of code in the switch statement below to set the
|
||||
|
@ -155,7 +155,7 @@ class CssCollectionOptimizer implements AssetCollectionOptimizerInterface {
|
|||
* A hash to uniquely identify the given group of CSS assets.
|
||||
*/
|
||||
protected function generateHash(array $css_group) {
|
||||
$css_data = array();
|
||||
$css_data = [];
|
||||
foreach ($css_group['items'] as $css_file) {
|
||||
$css_data[] = $css_file['data'];
|
||||
}
|
||||
|
@ -181,7 +181,7 @@ class CssCollectionOptimizer implements AssetCollectionOptimizerInterface {
|
|||
file_unmanaged_delete($uri);
|
||||
}
|
||||
};
|
||||
file_scan_directory('public://css', '/.*/', array('callback' => $delete_stale));
|
||||
file_scan_directory('public://css', '/.*/', ['callback' => $delete_stale]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ class CssCollectionRenderer implements AssetCollectionRendererInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function render(array $css_assets) {
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
|
||||
// A dummy query-string is added to filenames, to gain control over
|
||||
// browser-caching. The string changes on every update or full cache
|
||||
|
@ -83,22 +83,22 @@ class CssCollectionRenderer implements AssetCollectionRendererInterface {
|
|||
$query_string = $this->state->get('system.css_js_query_string') ?: '0';
|
||||
|
||||
// Defaults for LINK and STYLE elements.
|
||||
$link_element_defaults = array(
|
||||
$link_element_defaults = [
|
||||
'#type' => 'html_tag',
|
||||
'#tag' => 'link',
|
||||
'#attributes' => array(
|
||||
'#attributes' => [
|
||||
'rel' => 'stylesheet',
|
||||
),
|
||||
);
|
||||
$style_element_defaults = array(
|
||||
],
|
||||
];
|
||||
$style_element_defaults = [
|
||||
'#type' => 'html_tag',
|
||||
'#tag' => 'style',
|
||||
);
|
||||
];
|
||||
|
||||
// For filthy IE hack.
|
||||
$current_ie_group_keys = NULL;
|
||||
$get_ie_group_key = function ($css_asset) {
|
||||
return array($css_asset['type'], $css_asset['preprocess'], $css_asset['group'], $css_asset['media'], $css_asset['browsers']);
|
||||
return [$css_asset['type'], $css_asset['preprocess'], $css_asset['group'], $css_asset['media'], $css_asset['browsers']];
|
||||
};
|
||||
|
||||
// Loop through all CSS assets, by key, to allow for the special IE
|
||||
|
@ -151,7 +151,7 @@ class CssCollectionRenderer implements AssetCollectionRendererInterface {
|
|||
// The file CSS asset can be aggregated, but hasn't been: combine
|
||||
// multiple items into as few STYLE tags as possible.
|
||||
else {
|
||||
$import = array();
|
||||
$import = [];
|
||||
// Start with the current CSS asset, iterate over subsequent CSS
|
||||
// assets and find which ones have the same 'type', 'group',
|
||||
// 'preprocess', 'media' and 'browsers' properties.
|
||||
|
|
|
@ -61,7 +61,7 @@ class CssOptimizer implements AssetOptimizerInterface {
|
|||
$this->rewriteFileURIBasePath = $css_base_path . '/';
|
||||
|
||||
// Anchor all paths in the CSS with its base URL, ignoring external and absolute paths.
|
||||
return preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\s*\)/i', array($this, 'rewriteFileURI'), $contents);
|
||||
return preg_replace_callback('/url\(\s*[\'"]?(?![a-z]+:|\/+)([^\'")]+)[\'"]?\s*\)/i', [$this, 'rewriteFileURI'], $contents);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -205,8 +205,10 @@ class CssOptimizer implements AssetOptimizerInterface {
|
|||
// whitespace.
|
||||
// @see http://php.net/manual/regexp.reference.subpatterns.php
|
||||
$contents = preg_replace('<
|
||||
# Do not strip any space from within single or double quotes
|
||||
(' . $double_quot . '|' . $single_quot . ')
|
||||
# Strip leading and trailing whitespace.
|
||||
\s*([@{};,])\s*
|
||||
| \s*([@{};,])\s*
|
||||
# Strip only leading whitespace from:
|
||||
# - Closing parenthesis: Retain "@media (bar) and foo".
|
||||
| \s+([\)])
|
||||
|
@ -214,11 +216,11 @@ class CssOptimizer implements AssetOptimizerInterface {
|
|||
# - Opening parenthesis: Retain "@media (bar) and foo".
|
||||
# - Colon: Retain :pseudo-selectors.
|
||||
| ([\(:])\s+
|
||||
>xS',
|
||||
// Only one of the three capturing groups will match, so its reference
|
||||
>xSs',
|
||||
// Only one of the four capturing groups will match, so its reference
|
||||
// will contain the wanted value and the references for the
|
||||
// two non-matching groups will be replaced with empty strings.
|
||||
'$1$2$3',
|
||||
'$1$2$3$4',
|
||||
$contents
|
||||
);
|
||||
// End the file with a new line.
|
||||
|
@ -228,7 +230,7 @@ class CssOptimizer implements AssetOptimizerInterface {
|
|||
|
||||
// Replaces @import commands with the actual stylesheet content.
|
||||
// This happens recursively but omits external files.
|
||||
$contents = preg_replace_callback('/@import\s*(?:url\(\s*)?[\'"]?(?![a-z]+:)(?!\/\/)([^\'"\()]+)[\'"]?\s*\)?\s*;/', array($this, 'loadNestedFile'), $contents);
|
||||
$contents = preg_replace_callback('/@import\s*(?:url\(\s*)?[\'"]?(?![a-z]+:)(?!\/\/)([^\'"\()]+)[\'"]?\s*\)?\s*;/', [$this, 'loadNestedFile'], $contents);
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class JsCollectionGrouper implements AssetCollectionGrouperInterface {
|
|||
* type and browsers, if needed to accommodate other items in between.
|
||||
*/
|
||||
public function group(array $js_assets) {
|
||||
$groups = array();
|
||||
$groups = [];
|
||||
// If a group can contain multiple items, we track the information that must
|
||||
// be the same for each item in the group, so that when we iterate the next
|
||||
// item, we can determine if it can be put into the current group, or if a
|
||||
|
@ -38,7 +38,7 @@ class JsCollectionGrouper implements AssetCollectionGrouperInterface {
|
|||
// Group file items if their 'preprocess' flag is TRUE.
|
||||
// Help ensure maximum reuse of aggregate files by only grouping
|
||||
// together items that share the same 'group' value.
|
||||
$group_keys = $item['preprocess'] ? array($item['type'], $item['group'], $item['browsers']) : FALSE;
|
||||
$group_keys = $item['preprocess'] ? [$item['type'], $item['group'], $item['browsers']] : FALSE;
|
||||
break;
|
||||
|
||||
case 'external':
|
||||
|
@ -56,7 +56,7 @@ class JsCollectionGrouper implements AssetCollectionGrouperInterface {
|
|||
// unique to the item and should not be carried over to the group.
|
||||
$groups[$index] = $item;
|
||||
unset($groups[$index]['data'], $groups[$index]['weight']);
|
||||
$groups[$index]['items'] = array();
|
||||
$groups[$index]['items'] = [];
|
||||
$current_group_keys = $group_keys ? $group_keys : NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -81,8 +81,8 @@ class JsCollectionOptimizer implements AssetCollectionOptimizerInterface {
|
|||
// Drupal contrib can override this default JS aggregator to keep the same
|
||||
// grouping, optimizing and dumping, but change the strategy that is used to
|
||||
// determine when the aggregate should be rebuilt (e.g. mtime, HTTPS …).
|
||||
$map = $this->state->get('system.js_cache_files') ?: array();
|
||||
$js_assets = array();
|
||||
$map = $this->state->get('system.js_cache_files') ?: [];
|
||||
$js_assets = [];
|
||||
foreach ($js_groups as $order => $js_group) {
|
||||
// We have to return a single asset, not a group of assets. It is now up
|
||||
// to one of the pieces of code in the switch statement below to set the
|
||||
|
@ -159,7 +159,7 @@ class JsCollectionOptimizer implements AssetCollectionOptimizerInterface {
|
|||
* A hash to uniquely identify the given group of JavaScript assets.
|
||||
*/
|
||||
protected function generateHash(array $js_group) {
|
||||
$js_data = array();
|
||||
$js_data = [];
|
||||
foreach ($js_group['items'] as $js_file) {
|
||||
$js_data[] = $js_file['data'];
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ class JsCollectionOptimizer implements AssetCollectionOptimizerInterface {
|
|||
file_unmanaged_delete($uri);
|
||||
}
|
||||
};
|
||||
file_scan_directory('public://js', '/.*/', array('callback' => $delete_stale));
|
||||
file_scan_directory('public://js', '/.*/', ['callback' => $delete_stale]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ class JsCollectionRenderer implements AssetCollectionRendererInterface {
|
|||
* logic for grouping and aggregating files.
|
||||
*/
|
||||
public function render(array $js_assets) {
|
||||
$elements = array();
|
||||
$elements = [];
|
||||
|
||||
// A dummy query-string is added to filenames, to gain control over
|
||||
// browser-caching. The string changes on every update or full cache
|
||||
|
@ -47,11 +47,11 @@ class JsCollectionRenderer implements AssetCollectionRendererInterface {
|
|||
$default_query_string = $this->state->get('system.css_js_query_string') ?: '0';
|
||||
|
||||
// Defaults for each SCRIPT element.
|
||||
$element_defaults = array(
|
||||
$element_defaults = [
|
||||
'#type' => 'html_tag',
|
||||
'#tag' => 'script',
|
||||
'#value' => '',
|
||||
);
|
||||
];
|
||||
|
||||
// Loop through all JS assets.
|
||||
foreach ($js_assets as $js_asset) {
|
||||
|
@ -62,12 +62,12 @@ class JsCollectionRenderer implements AssetCollectionRendererInterface {
|
|||
// Element properties that depend on item type.
|
||||
switch ($js_asset['type']) {
|
||||
case 'setting':
|
||||
$element['#attributes'] = array(
|
||||
$element['#attributes'] = [
|
||||
// This type attribute prevents this from being parsed as an
|
||||
// inline script.
|
||||
'type' => 'application/json',
|
||||
'data-drupal-selector' => 'drupal-settings-json',
|
||||
);
|
||||
];
|
||||
$element['#value'] = Json::encode($js_asset['data']);
|
||||
break;
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class LibraryDiscoveryParser {
|
|||
* Thrown when a js file defines a positive weight.
|
||||
*/
|
||||
public function buildByExtension($extension) {
|
||||
$libraries = array();
|
||||
$libraries = [];
|
||||
|
||||
if ($extension === 'core') {
|
||||
$path = 'core';
|
||||
|
@ -92,7 +92,7 @@ class LibraryDiscoveryParser {
|
|||
if (!isset($library['js']) && !isset($library['css']) && !isset($library['drupalSettings'])) {
|
||||
throw new IncompleteLibraryDefinitionException(sprintf("Incomplete library definition for definition '%s' in extension '%s'", $id, $extension));
|
||||
}
|
||||
$library += array('dependencies' => array(), 'js' => array(), 'css' => array());
|
||||
$library += ['dependencies' => [], 'js' => [], 'css' => []];
|
||||
|
||||
if (isset($library['header']) && !is_bool($library['header'])) {
|
||||
throw new \LogicException(sprintf("The 'header' key in the library definition '%s' in extension '%s' is invalid: it must be a boolean.", $id, $extension));
|
||||
|
@ -116,14 +116,14 @@ class LibraryDiscoveryParser {
|
|||
|
||||
// Assign Drupal's license to libraries that don't have license info.
|
||||
if (!isset($library['license'])) {
|
||||
$library['license'] = array(
|
||||
$library['license'] = [
|
||||
'name' => 'GNU-GPL-2.0-or-later',
|
||||
'url' => 'https://www.drupal.org/licensing/faq',
|
||||
'gpl-compatible' => TRUE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
foreach (array('js', 'css') as $type) {
|
||||
foreach (['js', 'css'] as $type) {
|
||||
// Prepare (flatten) the SMACSS-categorized definitions.
|
||||
// @todo After Asset(ic) changes, retain the definitions as-is and
|
||||
// properly resolve dependencies for all (css) libraries per category,
|
||||
|
@ -145,7 +145,7 @@ class LibraryDiscoveryParser {
|
|||
unset($library[$type][$source]);
|
||||
// Allow to omit the options hashmap in YAML declarations.
|
||||
if (!is_array($options)) {
|
||||
$options = array();
|
||||
$options = [];
|
||||
}
|
||||
if ($type == 'js' && isset($options['weight']) && $options['weight'] > 0) {
|
||||
throw new \UnexpectedValueException("The $extension/$id library defines a positive weight for '$source'. Only negative weights are allowed (but should be avoided). Instead of a positive weight, specify accurate dependencies for this library.");
|
||||
|
|
|
@ -58,10 +58,10 @@ class BatchStorage implements BatchStorageInterface {
|
|||
// Ensure that a session is started before using the CSRF token generator.
|
||||
$this->session->start();
|
||||
try {
|
||||
$batch = $this->connection->query("SELECT batch FROM {batch} WHERE bid = :bid AND token = :token", array(
|
||||
$batch = $this->connection->query("SELECT batch FROM {batch} WHERE bid = :bid AND token = :token", [
|
||||
':bid' => $id,
|
||||
':token' => $this->csrfToken->get($id),
|
||||
))->fetchField();
|
||||
])->fetchField();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->catchException($e);
|
||||
|
@ -93,7 +93,7 @@ class BatchStorage implements BatchStorageInterface {
|
|||
public function update(array $batch) {
|
||||
try {
|
||||
$this->connection->update('batch')
|
||||
->fields(array('batch' => serialize($batch)))
|
||||
->fields(['batch' => serialize($batch)])
|
||||
->condition('bid', $batch['id'])
|
||||
->execute();
|
||||
}
|
||||
|
@ -150,12 +150,12 @@ class BatchStorage implements BatchStorageInterface {
|
|||
*/
|
||||
protected function doCreate(array $batch) {
|
||||
$this->connection->insert('batch')
|
||||
->fields(array(
|
||||
->fields([
|
||||
'bid' => $batch['id'],
|
||||
'timestamp' => REQUEST_TIME,
|
||||
'token' => $this->csrfToken->get($batch['id']),
|
||||
'batch' => serialize($batch),
|
||||
))
|
||||
])
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
namespace Drupal\Core\Block;
|
||||
|
||||
use Drupal\block\BlockInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Plugin\ContextAwarePluginAssignmentTrait;
|
||||
|
@ -83,19 +82,19 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn
|
|||
* An associative array with the default configuration.
|
||||
*/
|
||||
protected function baseConfigurationDefaults() {
|
||||
return array(
|
||||
return [
|
||||
'id' => $this->getPluginId(),
|
||||
'label' => '',
|
||||
'provider' => $this->pluginDefinition['provider'],
|
||||
'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE,
|
||||
);
|
||||
'label_display' => static::BLOCK_LABEL_VISIBLE,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -109,7 +108,7 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -152,29 +151,29 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn
|
|||
*/
|
||||
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
|
||||
$definition = $this->getPluginDefinition();
|
||||
$form['provider'] = array(
|
||||
$form['provider'] = [
|
||||
'#type' => 'value',
|
||||
'#value' => $definition['provider'],
|
||||
);
|
||||
];
|
||||
|
||||
$form['admin_label'] = array(
|
||||
$form['admin_label'] = [
|
||||
'#type' => 'item',
|
||||
'#title' => $this->t('Block description'),
|
||||
'#plain_text' => $definition['admin_label'],
|
||||
);
|
||||
$form['label'] = array(
|
||||
];
|
||||
$form['label'] = [
|
||||
'#type' => 'textfield',
|
||||
'#title' => $this->t('Title'),
|
||||
'#maxlength' => 255,
|
||||
'#default_value' => $this->label(),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['label_display'] = array(
|
||||
];
|
||||
$form['label_display'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Display title'),
|
||||
'#default_value' => ($this->configuration['label_display'] === BlockInterface::BLOCK_LABEL_VISIBLE),
|
||||
'#return_value' => BlockInterface::BLOCK_LABEL_VISIBLE,
|
||||
);
|
||||
'#default_value' => ($this->configuration['label_display'] === static::BLOCK_LABEL_VISIBLE),
|
||||
'#return_value' => static::BLOCK_LABEL_VISIBLE,
|
||||
];
|
||||
|
||||
// Add context mapping UI form elements.
|
||||
$contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
|
||||
|
@ -188,7 +187,7 @@ abstract class BlockBase extends ContextAwarePluginBase implements BlockPluginIn
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function blockForm($form, FormStateInterface $form_state) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -74,7 +74,7 @@ class BlockManager extends DefaultPluginManager implements BlockManagerInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFallbackPluginId($plugin_id, array $configuration = array()) {
|
||||
public function getFallbackPluginId($plugin_id, array $configuration = []) {
|
||||
return 'broken';
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,11 @@ use Drupal\Core\Session\AccountInterface;
|
|||
*/
|
||||
interface BlockPluginInterface extends ConfigurablePluginInterface, PluginFormInterface, PluginInspectionInterface, CacheableDependencyInterface, DerivativeInspectionInterface {
|
||||
|
||||
/**
|
||||
* Indicates the block label (title) should be displayed to end users.
|
||||
*/
|
||||
const BLOCK_LABEL_VISIBLE = 'visible';
|
||||
|
||||
/**
|
||||
* Returns the user-facing block label.
|
||||
*
|
||||
|
@ -97,7 +102,7 @@ interface BlockPluginInterface extends ConfigurablePluginInterface, PluginFormIn
|
|||
* @param \Drupal\Core\Form\FormStateInterface $form_state
|
||||
* The current state of the form.
|
||||
*
|
||||
* @return array $form
|
||||
* @return array
|
||||
* The renderable form array representing the entire configuration form.
|
||||
*/
|
||||
public function blockForm($form, FormStateInterface $form_state);
|
||||
|
|
|
@ -29,7 +29,7 @@ class BreadcrumbManager implements ChainBreadcrumbBuilderInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $builders = array();
|
||||
protected $builders = [];
|
||||
|
||||
/**
|
||||
* Holds the array of breadcrumb builders sorted by priority.
|
||||
|
@ -71,7 +71,7 @@ class BreadcrumbManager implements ChainBreadcrumbBuilderInterface {
|
|||
*/
|
||||
public function build(RouteMatchInterface $route_match) {
|
||||
$breadcrumb = new Breadcrumb();
|
||||
$context = array('builder' => NULL);
|
||||
$context = ['builder' => NULL];
|
||||
// Call the build method of registered breadcrumb builders,
|
||||
// until one of them returns an array.
|
||||
foreach ($this->getSortedBuilders() as $builder) {
|
||||
|
@ -107,7 +107,7 @@ class BreadcrumbManager implements ChainBreadcrumbBuilderInterface {
|
|||
// Sort the builders according to priority.
|
||||
krsort($this->builders);
|
||||
// Merge nested builders from $this->builders into $this->sortedBuilders.
|
||||
$this->sortedBuilders = array();
|
||||
$this->sortedBuilders = [];
|
||||
foreach ($this->builders as $builders) {
|
||||
$this->sortedBuilders = array_merge($this->sortedBuilders, $builders);
|
||||
}
|
||||
|
|
|
@ -80,13 +80,13 @@ class ApcuBackend implements CacheBackendInterface {
|
|||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
// Translate the requested cache item IDs to APCu keys.
|
||||
$map = array();
|
||||
$map = [];
|
||||
foreach ($cids as $cid) {
|
||||
$map[$this->getApcuKey($cid)] = $cid;
|
||||
}
|
||||
|
||||
$result = apcu_fetch(array_keys($map));
|
||||
$cache = array();
|
||||
$cache = [];
|
||||
if ($result) {
|
||||
foreach ($result as $key => $item) {
|
||||
$item = $this->prepareItem($item, $allow_invalid);
|
||||
|
@ -140,7 +140,7 @@ class ApcuBackend implements CacheBackendInterface {
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
$cache->tags = $cache->tags ? explode(' ', $cache->tags) : array();
|
||||
$cache->tags = $cache->tags ? explode(' ', $cache->tags) : [];
|
||||
|
||||
// Check expire time.
|
||||
$cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME;
|
||||
|
@ -160,7 +160,7 @@ class ApcuBackend implements CacheBackendInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = array()) {
|
||||
public function set($cid, $data, $expire = CacheBackendInterface::CACHE_PERMANENT, array $tags = []) {
|
||||
assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($tags)', 'Cache tags must be strings.');
|
||||
$tags = array_unique($tags);
|
||||
$cache = new \stdClass();
|
||||
|
@ -180,9 +180,9 @@ class ApcuBackend implements CacheBackendInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setMultiple(array $items = array()) {
|
||||
public function setMultiple(array $items = []) {
|
||||
foreach ($items as $cid => $item) {
|
||||
$this->set($cid, $item['data'], isset($item['expire']) ? $item['expire'] : CacheBackendInterface::CACHE_PERMANENT, isset($item['tags']) ? $item['tags'] : array());
|
||||
$this->set($cid, $item['data'], isset($item['expire']) ? $item['expire'] : CacheBackendInterface::CACHE_PERMANENT, isset($item['tags']) ? $item['tags'] : []);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,7 +197,7 @@ class ApcuBackend implements CacheBackendInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteMultiple(array $cids) {
|
||||
apcu_delete(array_map(array($this, 'getApcuKey'), $cids));
|
||||
apcu_delete(array_map([$this, 'getApcuKey'], $cids));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -225,7 +225,7 @@ class ApcuBackend implements CacheBackendInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidate($cid) {
|
||||
$this->invalidateMultiple(array($cid));
|
||||
$this->invalidateMultiple([$cid]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $backends = array();
|
||||
protected $backends = [];
|
||||
|
||||
/**
|
||||
* Constructs a DatabaseBackend object.
|
||||
|
@ -91,7 +91,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
$return = array();
|
||||
$return = [];
|
||||
|
||||
foreach ($this->backends as $index => $backend) {
|
||||
$items = $backend->getMultiple($cids, $allow_invalid);
|
||||
|
@ -121,7 +121,7 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
|
||||
foreach ($this->backends as $backend) {
|
||||
$backend->set($cid, $data, $expire, $tags);
|
||||
}
|
||||
|
|
|
@ -152,7 +152,7 @@ class Cache {
|
|||
* An array of cache backend objects keyed by cache bins.
|
||||
*/
|
||||
public static function getBins() {
|
||||
$bins = array();
|
||||
$bins = [];
|
||||
$container = \Drupal::getContainer();
|
||||
foreach ($container->getParameter('cache_bins') as $service_id => $bin) {
|
||||
$bins[$bin] = $container->get($service_id);
|
||||
|
@ -178,7 +178,7 @@ class Cache {
|
|||
*/
|
||||
public static function keyFromQuery(SelectInterface $query) {
|
||||
$query->preExecute();
|
||||
$keys = array((string) $query, $query->getArguments());
|
||||
$keys = [(string) $query, $query->getArguments()];
|
||||
return hash('sha256', serialize($keys));
|
||||
}
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ interface CacheBackendInterface {
|
|||
* @see \Drupal\Core\Cache\CacheBackendInterface::get()
|
||||
* @see \Drupal\Core\Cache\CacheBackendInterface::getMultiple()
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array());
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []);
|
||||
|
||||
/**
|
||||
* Store multiple items in the persistent cache.
|
||||
|
|
|
@ -56,21 +56,21 @@ abstract class CacheCollector implements CacheCollectorInterface, DestructableIn
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $keysToPersist = array();
|
||||
protected $keysToPersist = [];
|
||||
|
||||
/**
|
||||
* An array of keys to remove from the cache on service termination.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $keysToRemove = array();
|
||||
protected $keysToRemove = [];
|
||||
|
||||
/**
|
||||
* Storage for the data itself.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $storage = array();
|
||||
protected $storage = [];
|
||||
|
||||
/**
|
||||
* Stores the cache creation time.
|
||||
|
@ -110,7 +110,7 @@ abstract class CacheCollector implements CacheCollectorInterface, DestructableIn
|
|||
* @param array $tags
|
||||
* (optional) The tags to specify for the cache item.
|
||||
*/
|
||||
public function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $lock, array $tags = array()) {
|
||||
public function __construct($cid, CacheBackendInterface $cache, LockBackendInterface $lock, array $tags = []) {
|
||||
assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($tags)', 'Cache tags must be strings.');
|
||||
$this->cid = $cid;
|
||||
$this->cache = $cache;
|
||||
|
@ -216,7 +216,7 @@ abstract class CacheCollector implements CacheCollectorInterface, DestructableIn
|
|||
* TRUE.
|
||||
*/
|
||||
protected function updateCache($lock = TRUE) {
|
||||
$data = array();
|
||||
$data = [];
|
||||
foreach ($this->keysToPersist as $offset => $persist) {
|
||||
if ($persist) {
|
||||
$data[$offset] = $this->storage[$offset];
|
||||
|
@ -256,8 +256,8 @@ abstract class CacheCollector implements CacheCollectorInterface, DestructableIn
|
|||
}
|
||||
}
|
||||
|
||||
$this->keysToPersist = array();
|
||||
$this->keysToRemove = array();
|
||||
$this->keysToPersist = [];
|
||||
$this->keysToRemove = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -288,9 +288,9 @@ abstract class CacheCollector implements CacheCollectorInterface, DestructableIn
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset() {
|
||||
$this->storage = array();
|
||||
$this->keysToPersist = array();
|
||||
$this->keysToRemove = array();
|
||||
$this->storage = [];
|
||||
$this->keysToPersist = [];
|
||||
$this->keysToRemove = [];
|
||||
$this->cacheLoaded = FALSE;
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ class CacheFactory implements CacheFactoryInterface, ContainerAwareInterface {
|
|||
* (optional) A mapping of bin to backend service name. Mappings in
|
||||
* $settings take precedence over this.
|
||||
*/
|
||||
public function __construct(Settings $settings, array $default_bin_backends = array()) {
|
||||
public function __construct(Settings $settings, array $default_bin_backends = []) {
|
||||
$this->settings = $settings;
|
||||
$this->defaultBinBackends = $default_bin_backends;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ class CacheTagsInvalidator implements CacheTagsInvalidatorInterface {
|
|||
*
|
||||
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface[]
|
||||
*/
|
||||
protected $invalidators = array();
|
||||
protected $invalidators = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -66,7 +66,7 @@ class CacheTagsInvalidator implements CacheTagsInvalidatorInterface {
|
|||
* interface, keyed by their cache bin.
|
||||
*/
|
||||
protected function getInvalidatorCacheBins() {
|
||||
$bins = array();
|
||||
$bins = [];
|
||||
foreach ($this->container->getParameter('cache_bins') as $service_id => $bin) {
|
||||
$service = $this->container->get($service_id);
|
||||
if ($service instanceof CacheTagsInvalidatorInterface) {
|
||||
|
|
|
@ -99,7 +99,7 @@ class ChainedFastBackend implements CacheBackendInterface, CacheTagsInvalidatorI
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($cid, $allow_invalid = FALSE) {
|
||||
$cids = array($cid);
|
||||
$cids = [$cid];
|
||||
$cache = $this->getMultiple($cids, $allow_invalid);
|
||||
return reset($cache);
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ class ChainedFastBackend implements CacheBackendInterface, CacheTagsInvalidatorI
|
|||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
$cids_copy = $cids;
|
||||
$cache = array();
|
||||
$cache = [];
|
||||
|
||||
// If we can determine the time at which the last write to the consistent
|
||||
// backend occurred (we might not be able to if it has been recently
|
||||
|
@ -142,7 +142,7 @@ class ChainedFastBackend implements CacheBackendInterface, CacheTagsInvalidatorI
|
|||
}
|
||||
catch (\Exception $e) {
|
||||
$cids = $cids_copy;
|
||||
$items = array();
|
||||
$items = [];
|
||||
}
|
||||
|
||||
// Even if items were successfully fetched from the fast backend, they
|
||||
|
@ -176,7 +176,7 @@ class ChainedFastBackend implements CacheBackendInterface, CacheTagsInvalidatorI
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
|
||||
$this->consistentBackend->set($cid, $data, $expire, $tags);
|
||||
$this->markAsOutdated();
|
||||
// Don't write the cache tags to the fast backend as any cache tag
|
||||
|
@ -202,7 +202,7 @@ class ChainedFastBackend implements CacheBackendInterface, CacheTagsInvalidatorI
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($cid) {
|
||||
$this->consistentBackend->deleteMultiple(array($cid));
|
||||
$this->consistentBackend->deleteMultiple([$cid]);
|
||||
$this->markAsOutdated();
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ class ChainedFastBackend implements CacheBackendInterface, CacheTagsInvalidatorI
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidate($cid) {
|
||||
$this->invalidateMultiple(array($cid));
|
||||
$this->invalidateMultiple([$cid]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -43,7 +43,7 @@ class ChainedFastBackendFactory implements CacheFactoryInterface {
|
|||
public function __construct(Settings $settings = NULL, $consistent_service_name = NULL, $fast_service_name = NULL) {
|
||||
// Default the consistent backend to the site's default backend.
|
||||
if (!isset($consistent_service_name)) {
|
||||
$cache_settings = isset($settings) ? $settings->get('cache') : array();
|
||||
$cache_settings = isset($settings) ? $settings->get('cache') : [];
|
||||
$consistent_service_name = isset($cache_settings['default']) ? $cache_settings['default'] : 'cache.backend.database';
|
||||
}
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ class CacheContextsManager {
|
|||
* An array of available cache contexts and corresponding labels.
|
||||
*/
|
||||
public function getLabels($include_calculated_cache_contexts = FALSE) {
|
||||
$with_labels = array();
|
||||
$with_labels = [];
|
||||
foreach ($this->contexts as $context) {
|
||||
$service = $this->getService($context);
|
||||
if (!$include_calculated_cache_contexts && $service instanceof CalculatedCacheContextInterface) {
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Core\Cache\Context;
|
||||
|
||||
use Drupal\Core\Cache\CacheableMetadata;
|
||||
use Drupal\Core\Path\PathMatcherInterface;
|
||||
|
||||
/**
|
||||
* Defines a cache context for whether the URL is the front page of the site.
|
||||
*
|
||||
* Cache context ID: 'url.path.is_front'.
|
||||
*/
|
||||
class IsFrontPathCacheContext implements CacheContextInterface {
|
||||
|
||||
/**
|
||||
* @var \Drupal\Core\Path\PathMatcherInterface
|
||||
*/
|
||||
protected $pathMatcher;
|
||||
|
||||
/**
|
||||
* Constructs an IsFrontPathCacheContext object.
|
||||
*
|
||||
* @param \Drupal\Core\Path\PathMatcherInterface $path_matcher
|
||||
*/
|
||||
public function __construct(PathMatcherInterface $path_matcher) {
|
||||
$this->pathMatcher = $path_matcher;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getLabel() {
|
||||
return t('Is front page');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getContext() {
|
||||
return 'is_front.' . (int) $this->pathMatcher->isFrontPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getCacheableMetadata() {
|
||||
$metadata = new CacheableMetadata();
|
||||
$metadata->addCacheTags(['config:system.site']);
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
}
|
|
@ -50,7 +50,7 @@ class LanguagesCacheContext implements CalculatedCacheContextInterface {
|
|||
*/
|
||||
public function getContext($type = NULL) {
|
||||
if ($type === NULL) {
|
||||
$context_parts = array();
|
||||
$context_parts = [];
|
||||
if ($this->languageManager->isMultilingual()) {
|
||||
foreach ($this->languageManager->getLanguageTypes() as $type) {
|
||||
$context_parts[] = $this->languageManager->getCurrentLanguage($type)->getId();
|
||||
|
|
|
@ -59,7 +59,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function get($cid, $allow_invalid = FALSE) {
|
||||
$cids = array($cid);
|
||||
$cids = [$cid];
|
||||
$cache = $this->getMultiple($cids, $allow_invalid);
|
||||
return reset($cache);
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
$cid_mapping = array();
|
||||
$cid_mapping = [];
|
||||
foreach ($cids as $cid) {
|
||||
$cid_mapping[$this->normalizeCid($cid)] = $cid;
|
||||
}
|
||||
|
@ -79,14 +79,14 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
// is used here only due to the performance overhead we would incur
|
||||
// otherwise. When serving an uncached page, the overhead of using
|
||||
// ::select() is a much smaller proportion of the request.
|
||||
$result = array();
|
||||
$result = [];
|
||||
try {
|
||||
$result = $this->connection->query('SELECT cid, data, created, expire, serialized, tags, checksum FROM {' . $this->connection->escapeTable($this->bin) . '} WHERE cid IN ( :cids[] ) ORDER BY cid', array(':cids[]' => array_keys($cid_mapping)));
|
||||
$result = $this->connection->query('SELECT cid, data, created, expire, serialized, tags, checksum FROM {' . $this->connection->escapeTable($this->bin) . '} WHERE cid IN ( :cids[] ) ORDER BY cid', [':cids[]' => array_keys($cid_mapping)]);
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
// Nothing to do.
|
||||
}
|
||||
$cache = array();
|
||||
$cache = [];
|
||||
foreach ($result as $item) {
|
||||
// Map the cache ID back to the original.
|
||||
$item->cid = $cid_mapping[$item->cid];
|
||||
|
@ -119,7 +119,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
$cache->tags = $cache->tags ? explode(' ', $cache->tags) : array();
|
||||
$cache->tags = $cache->tags ? explode(' ', $cache->tags) : [];
|
||||
|
||||
// Check expire time.
|
||||
$cache->valid = $cache->expire == Cache::PERMANENT || $cache->expire >= REQUEST_TIME;
|
||||
|
@ -144,7 +144,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
|
||||
$this->setMultiple([
|
||||
$cid => [
|
||||
'data' => $data,
|
||||
|
@ -186,26 +186,26 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
* @see \Drupal\Core\Cache\CacheBackendInterface::setMultiple()
|
||||
*/
|
||||
protected function doSetMultiple(array $items) {
|
||||
$values = array();
|
||||
$values = [];
|
||||
|
||||
foreach ($items as $cid => $item) {
|
||||
$item += array(
|
||||
$item += [
|
||||
'expire' => CacheBackendInterface::CACHE_PERMANENT,
|
||||
'tags' => array(),
|
||||
);
|
||||
'tags' => [],
|
||||
];
|
||||
|
||||
assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($item[\'tags\'])', 'Cache Tags must be strings.');
|
||||
$item['tags'] = array_unique($item['tags']);
|
||||
// Sort the cache tags so that they are stored consistently in the DB.
|
||||
sort($item['tags']);
|
||||
|
||||
$fields = array(
|
||||
$fields = [
|
||||
'cid' => $this->normalizeCid($cid),
|
||||
'expire' => $item['expire'],
|
||||
'created' => round(microtime(TRUE), 3),
|
||||
'tags' => implode(' ', $item['tags']),
|
||||
'checksum' => $this->checksumProvider->getCurrentChecksum($item['tags']),
|
||||
);
|
||||
];
|
||||
|
||||
if (!is_string($item['data'])) {
|
||||
$fields['data'] = serialize($item['data']);
|
||||
|
@ -223,7 +223,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
$query = $this->connection
|
||||
->upsert($this->bin)
|
||||
->key('cid')
|
||||
->fields(array('cid', 'expire', 'created', 'tags', 'checksum', 'data', 'serialized'));
|
||||
->fields(['cid', 'expire', 'created', 'tags', 'checksum', 'data', 'serialized']);
|
||||
foreach ($values as $fields) {
|
||||
// Only pass the values since the order of $fields matches the order of
|
||||
// the insert fields. This is a performance optimization to avoid
|
||||
|
@ -238,14 +238,14 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($cid) {
|
||||
$this->deleteMultiple(array($cid));
|
||||
$this->deleteMultiple([$cid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteMultiple(array $cids) {
|
||||
$cids = array_values(array_map(array($this, 'normalizeCid'), $cids));
|
||||
$cids = array_values(array_map([$this, 'normalizeCid'], $cids));
|
||||
try {
|
||||
// Delete in chunks when a large array is passed.
|
||||
foreach (array_chunk($cids, 1000) as $cids_chunk) {
|
||||
|
@ -285,19 +285,19 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidate($cid) {
|
||||
$this->invalidateMultiple(array($cid));
|
||||
$this->invalidateMultiple([$cid]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function invalidateMultiple(array $cids) {
|
||||
$cids = array_values(array_map(array($this, 'normalizeCid'), $cids));
|
||||
$cids = array_values(array_map([$this, 'normalizeCid'], $cids));
|
||||
try {
|
||||
// Update in chunks when a large array is passed.
|
||||
foreach (array_chunk($cids, 1000) as $cids_chunk) {
|
||||
$this->connection->update($this->bin)
|
||||
->fields(array('expire' => REQUEST_TIME - 1))
|
||||
->fields(['expire' => REQUEST_TIME - 1])
|
||||
->condition('cid', $cids_chunk, 'IN')
|
||||
->execute();
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
public function invalidateAll() {
|
||||
try {
|
||||
$this->connection->update($this->bin)
|
||||
->fields(array('expire' => REQUEST_TIME - 1))
|
||||
->fields(['expire' => REQUEST_TIME - 1])
|
||||
->execute();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
|
@ -419,62 +419,62 @@ class DatabaseBackend implements CacheBackendInterface {
|
|||
* Defines the schema for the {cache_*} bin tables.
|
||||
*/
|
||||
public function schemaDefinition() {
|
||||
$schema = array(
|
||||
$schema = [
|
||||
'description' => 'Storage for the cache API.',
|
||||
'fields' => array(
|
||||
'cid' => array(
|
||||
'fields' => [
|
||||
'cid' => [
|
||||
'description' => 'Primary Key: Unique cache ID.',
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
'binary' => TRUE,
|
||||
),
|
||||
'data' => array(
|
||||
],
|
||||
'data' => [
|
||||
'description' => 'A collection of data to cache.',
|
||||
'type' => 'blob',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
),
|
||||
'expire' => array(
|
||||
],
|
||||
'expire' => [
|
||||
'description' => 'A Unix timestamp indicating when the cache entry should expire, or ' . Cache::PERMANENT . ' for never.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'created' => array(
|
||||
],
|
||||
'created' => [
|
||||
'description' => 'A timestamp with millisecond precision indicating when the cache entry was created.',
|
||||
'type' => 'numeric',
|
||||
'precision' => 14,
|
||||
'scale' => 3,
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'serialized' => array(
|
||||
],
|
||||
'serialized' => [
|
||||
'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
|
||||
'type' => 'int',
|
||||
'size' => 'small',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
'tags' => array(
|
||||
],
|
||||
'tags' => [
|
||||
'description' => 'Space-separated list of cache tags for this entry.',
|
||||
'type' => 'text',
|
||||
'size' => 'big',
|
||||
'not null' => FALSE,
|
||||
),
|
||||
'checksum' => array(
|
||||
],
|
||||
'checksum' => [
|
||||
'description' => 'The tag invalidation checksum when this entry was saved.',
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
),
|
||||
),
|
||||
'indexes' => array(
|
||||
'expire' => array('expire'),
|
||||
),
|
||||
'primary key' => array('cid'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'indexes' => [
|
||||
'expire' => ['expire'],
|
||||
],
|
||||
'primary key' => ['cid'],
|
||||
];
|
||||
return $schema;
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class DatabaseBackendFactory implements CacheFactoryInterface {
|
|||
* @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
|
||||
* The cache tags checksum provider.
|
||||
*/
|
||||
function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider) {
|
||||
public function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider) {
|
||||
$this->connection = $connection;
|
||||
$this->checksumProvider = $checksum_provider;
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class DatabaseBackendFactory implements CacheFactoryInterface {
|
|||
* @return \Drupal\Core\Cache\DatabaseBackend
|
||||
* The cache backend object for the specified cache bin.
|
||||
*/
|
||||
function get($bin) {
|
||||
public function get($bin) {
|
||||
return new DatabaseBackend($this->connection, $this->checksumProvider, $bin);
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class DatabaseCacheTagsChecksum implements CacheTagsChecksumInterface, CacheTags
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $tagCache = array();
|
||||
protected $tagCache = [];
|
||||
|
||||
/**
|
||||
* A list of tags that have already been invalidated in this request.
|
||||
|
@ -31,7 +31,7 @@ class DatabaseCacheTagsChecksum implements CacheTagsChecksumInterface, CacheTags
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $invalidatedTags = array();
|
||||
protected $invalidatedTags = [];
|
||||
|
||||
/**
|
||||
* Constructs a DatabaseCacheTagsChecksum object.
|
||||
|
@ -56,7 +56,7 @@ class DatabaseCacheTagsChecksum implements CacheTagsChecksumInterface, CacheTags
|
|||
$this->invalidatedTags[$tag] = TRUE;
|
||||
unset($this->tagCache[$tag]);
|
||||
$this->connection->merge('cachetags')
|
||||
->insertFields(array('invalidations' => 1))
|
||||
->insertFields(['invalidations' => 1])
|
||||
->expression('invalidations', 'invalidations + 1')
|
||||
->key('tag', $tag)
|
||||
->execute();
|
||||
|
@ -107,9 +107,9 @@ class DatabaseCacheTagsChecksum implements CacheTagsChecksumInterface, CacheTags
|
|||
|
||||
$query_tags = array_diff($tags, array_keys($this->tagCache));
|
||||
if ($query_tags) {
|
||||
$db_tags = array();
|
||||
$db_tags = [];
|
||||
try {
|
||||
$db_tags = $this->connection->query('SELECT tag, invalidations FROM {cachetags} WHERE tag IN ( :tags[] )', array(':tags[]' => $query_tags))
|
||||
$db_tags = $this->connection->query('SELECT tag, invalidations FROM {cachetags} WHERE tag IN ( :tags[] )', [':tags[]' => $query_tags])
|
||||
->fetchAllKeyed();
|
||||
$this->tagCache += $db_tags;
|
||||
}
|
||||
|
@ -134,8 +134,8 @@ class DatabaseCacheTagsChecksum implements CacheTagsChecksumInterface, CacheTags
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function reset() {
|
||||
$this->tagCache = array();
|
||||
$this->invalidatedTags = array();
|
||||
$this->tagCache = [];
|
||||
$this->invalidatedTags = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -165,25 +165,25 @@ class DatabaseCacheTagsChecksum implements CacheTagsChecksumInterface, CacheTags
|
|||
* Defines the schema for the {cachetags} table.
|
||||
*/
|
||||
public function schemaDefinition() {
|
||||
$schema = array(
|
||||
$schema = [
|
||||
'description' => 'Cache table for tracking cache tag invalidations.',
|
||||
'fields' => array(
|
||||
'tag' => array(
|
||||
'fields' => [
|
||||
'tag' => [
|
||||
'description' => 'Namespace-prefixed tag string.',
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'invalidations' => array(
|
||||
],
|
||||
'invalidations' => [
|
||||
'description' => 'Number incremented when the tag is invalidated.',
|
||||
'type' => 'int',
|
||||
'not null' => TRUE,
|
||||
'default' => 0,
|
||||
),
|
||||
),
|
||||
'primary key' => array('tag'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['tag'],
|
||||
];
|
||||
return $schema;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@ class ListCacheBinsPass implements CompilerPassInterface {
|
|||
* Collects the cache bins into the cache_bins parameter.
|
||||
*/
|
||||
public function process(ContainerBuilder $container) {
|
||||
$cache_bins = array();
|
||||
$cache_default_bin_backends = array();
|
||||
$cache_bins = [];
|
||||
$cache_default_bin_backends = [];
|
||||
foreach ($container->findTaggedServiceIds('cache.bin') as $id => $attributes) {
|
||||
$bin = substr($id, strpos($id, '.') + 1);
|
||||
$cache_bins[$id] = $bin;
|
||||
|
|
|
@ -10,6 +10,11 @@ namespace Drupal\Core\Cache;
|
|||
* Should be used for unit tests and specialist use-cases only, does not
|
||||
* store cached items between requests.
|
||||
*
|
||||
* The functions ::prepareItem()/::set() use unserialize()/serialize(). It
|
||||
* behaves as an external cache backend to avoid changing the cached data by
|
||||
* reference. In ::prepareItem(), the object is not modified by the call to
|
||||
* unserialize() because we make a clone of it.
|
||||
*
|
||||
* @ingroup cache
|
||||
*/
|
||||
class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterface {
|
||||
|
@ -17,16 +22,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
/**
|
||||
* Array to store cache objects.
|
||||
*/
|
||||
protected $cache = array();
|
||||
|
||||
/**
|
||||
* Constructs a MemoryBackend object.
|
||||
*
|
||||
* @param string $bin
|
||||
* The cache bin for which the object is created.
|
||||
*/
|
||||
public function __construct($bin) {
|
||||
}
|
||||
protected $cache = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -44,7 +40,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
$ret = array();
|
||||
$ret = [];
|
||||
|
||||
$items = array_intersect_key($this->cache, array_flip($cids));
|
||||
|
||||
|
@ -101,26 +97,26 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
|
||||
assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($tags)', 'Cache Tags must be strings.');
|
||||
$tags = array_unique($tags);
|
||||
// Sort the cache tags so that they are stored consistently in the database.
|
||||
sort($tags);
|
||||
$this->cache[$cid] = (object) array(
|
||||
$this->cache[$cid] = (object) [
|
||||
'cid' => $cid,
|
||||
'data' => serialize($data),
|
||||
'created' => $this->getRequestTime(),
|
||||
'expire' => $expire,
|
||||
'tags' => $tags,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setMultiple(array $items = array()) {
|
||||
public function setMultiple(array $items = []) {
|
||||
foreach ($items as $cid => $item) {
|
||||
$this->set($cid, $item['data'], isset($item['expire']) ? $item['expire'] : CacheBackendInterface::CACHE_PERMANENT, isset($item['tags']) ? $item['tags'] : array());
|
||||
$this->set($cid, $item['data'], isset($item['expire']) ? $item['expire'] : CacheBackendInterface::CACHE_PERMANENT, isset($item['tags']) ? $item['tags'] : []);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -142,7 +138,7 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteAll() {
|
||||
$this->cache = array();
|
||||
$this->cache = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -159,7 +155,9 @@ class MemoryBackend implements CacheBackendInterface, CacheTagsInvalidatorInterf
|
|||
*/
|
||||
public function invalidateMultiple(array $cids) {
|
||||
foreach ($cids as $cid) {
|
||||
$this->cache[$cid]->expire = $this->getRequestTime() - 1;
|
||||
if (isset($this->cache[$cid])) {
|
||||
$this->cache[$cid]->expire = $this->getRequestTime() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,14 +9,14 @@ class MemoryBackendFactory implements CacheFactoryInterface {
|
|||
*
|
||||
* @var \Drupal\Core\Cache\MemoryBackend[]
|
||||
*/
|
||||
protected $bins = array();
|
||||
protected $bins = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function get($bin) {
|
||||
public function get($bin) {
|
||||
if (!isset($this->bins[$bin])) {
|
||||
$this->bins[$bin] = new MemoryBackend($bin);
|
||||
$this->bins[$bin] = new MemoryBackend();
|
||||
}
|
||||
return $this->bins[$bin];
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ class MemoryCounterBackend extends MemoryBackend {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $counter = array();
|
||||
protected $counter = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -30,7 +30,7 @@ class MemoryCounterBackend extends MemoryBackend {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
|
||||
$this->increaseCounter(__FUNCTION__, $cid);
|
||||
parent::set($cid, $data, $expire, $tags);
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ class MemoryCounterBackend extends MemoryBackend {
|
|||
return isset($this->counter[$method][$cid]) ? $this->counter[$method][$cid] : 0;
|
||||
}
|
||||
elseif ($method) {
|
||||
return isset($this->counter[$method]) ? $this->counter[$method] : array();
|
||||
return isset($this->counter[$method]) ? $this->counter[$method] : [];
|
||||
}
|
||||
else {
|
||||
return $this->counter;
|
||||
|
@ -87,7 +87,7 @@ class MemoryCounterBackend extends MemoryBackend {
|
|||
* Resets the call counter.
|
||||
*/
|
||||
public function resetCounter() {
|
||||
$this->counter = array();
|
||||
$this->counter = [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,18 +36,18 @@ class NullBackend implements CacheBackendInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {}
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setMultiple(array $items = array()) {}
|
||||
public function setMultiple(array $items = []) {}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -7,7 +7,7 @@ class NullBackendFactory implements CacheFactoryInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
function get($bin) {
|
||||
public function get($bin) {
|
||||
return new NullBackend($bin);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ class PhpBackend implements CacheBackendInterface {
|
|||
/**
|
||||
* Array to store cache objects.
|
||||
*/
|
||||
protected $cache = array();
|
||||
protected $cache = [];
|
||||
|
||||
/**
|
||||
* The cache tags checksum provider.
|
||||
|
@ -83,7 +83,7 @@ class PhpBackend implements CacheBackendInterface {
|
|||
*/
|
||||
public function setMultiple(array $items) {
|
||||
foreach ($items as $cid => $item) {
|
||||
$this->set($cid, $item['data'], isset($item['expire']) ? $item['expire'] : CacheBackendInterface::CACHE_PERMANENT, isset($item['tags']) ? $item['tags'] : array());
|
||||
$this->set($cid, $item['data'], isset($item['expire']) ? $item['expire'] : CacheBackendInterface::CACHE_PERMANENT, isset($item['tags']) ? $item['tags'] : []);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ class PhpBackend implements CacheBackendInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMultiple(&$cids, $allow_invalid = FALSE) {
|
||||
$ret = array();
|
||||
$ret = [];
|
||||
|
||||
foreach ($cids as $cid) {
|
||||
if ($item = $this->get($cid, $allow_invalid)) {
|
||||
|
@ -142,16 +142,16 @@ class PhpBackend implements CacheBackendInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = array()) {
|
||||
public function set($cid, $data, $expire = Cache::PERMANENT, array $tags = []) {
|
||||
assert('\Drupal\Component\Assertion\Inspector::assertAllStrings($tags)', 'Cache Tags must be strings.');
|
||||
$item = (object) array(
|
||||
$item = (object) [
|
||||
'cid' => $cid,
|
||||
'data' => $data,
|
||||
'created' => round(microtime(TRUE), 3),
|
||||
'expire' => $expire,
|
||||
'tags' => array_unique($tags),
|
||||
'checksum' => $this->checksumProvider->getCurrentChecksum($tags),
|
||||
);
|
||||
];
|
||||
$this->writeItem($this->normalizeCid($cid), $item);
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ class PhpBackend implements CacheBackendInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function removeBin() {
|
||||
$this->cache = array();
|
||||
$this->cache = [];
|
||||
$this->storage()->deleteAll();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@ class PhpBackendFactory implements CacheFactoryInterface {
|
|||
* @return \Drupal\Core\Cache\PhpBackend
|
||||
* The cache backend object for the specified cache bin.
|
||||
*/
|
||||
function get($bin) {
|
||||
public function get($bin) {
|
||||
return new PhpBackend($bin, $this->checksumProvider);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ use Drupal\Component\PhpStorage\FileStorage;
|
|||
use Composer\Script\Event;
|
||||
use Composer\Installer\PackageEvent;
|
||||
use Composer\Semver\Constraint\Constraint;
|
||||
use PHP_CodeSniffer;
|
||||
|
||||
/**
|
||||
* Provides static functions for composer script events.
|
||||
|
@ -18,6 +19,7 @@ class Composer {
|
|||
'behat/mink' => ['tests', 'driver-testsuite'],
|
||||
'behat/mink-browserkit-driver' => ['tests'],
|
||||
'behat/mink-goutte-driver' => ['tests'],
|
||||
'drupal/coder' => ['coder_sniffer/Drupal/Test', 'coder_sniffer/DrupalPractice/Test'],
|
||||
'doctrine/cache' => ['tests'],
|
||||
'doctrine/collections' => ['tests'],
|
||||
'doctrine/common' => ['tests'],
|
||||
|
@ -82,22 +84,22 @@ class Composer {
|
|||
// Check for our packages, and then optimize them if they're present.
|
||||
if ($repository->findPackage('symfony/http-foundation', $constraint)) {
|
||||
$autoload = $package->getAutoload();
|
||||
$autoload['classmap'] = array_merge($autoload['classmap'], array(
|
||||
$autoload['classmap'] = array_merge($autoload['classmap'], [
|
||||
'vendor/symfony/http-foundation/Request.php',
|
||||
'vendor/symfony/http-foundation/ParameterBag.php',
|
||||
'vendor/symfony/http-foundation/FileBag.php',
|
||||
'vendor/symfony/http-foundation/ServerBag.php',
|
||||
'vendor/symfony/http-foundation/HeaderBag.php',
|
||||
));
|
||||
]);
|
||||
$package->setAutoload($autoload);
|
||||
}
|
||||
if ($repository->findPackage('symfony/http-kernel', $constraint)) {
|
||||
$autoload = $package->getAutoload();
|
||||
$autoload['classmap'] = array_merge($autoload['classmap'], array(
|
||||
$autoload['classmap'] = array_merge($autoload['classmap'], [
|
||||
'vendor/symfony/http-kernel/HttpKernel.php',
|
||||
'vendor/symfony/http-kernel/HttpKernelInterface.php',
|
||||
'vendor/symfony/http-kernel/TerminableInterface.php',
|
||||
));
|
||||
]);
|
||||
$package->setAutoload($autoload);
|
||||
}
|
||||
}
|
||||
|
@ -135,6 +137,28 @@ EOT;
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures phpcs if present.
|
||||
*
|
||||
* @param \Composer\Script\Event $event
|
||||
*/
|
||||
public static function configurePhpcs(Event $event) {
|
||||
// Grab the local repo which tells us what's been installed.
|
||||
$local_repository = $event->getComposer()
|
||||
->getRepositoryManager()
|
||||
->getLocalRepository();
|
||||
// Make sure both phpcs and coder are installed.
|
||||
$phpcs_package = $local_repository->findPackage('squizlabs/php_codesniffer', '*');
|
||||
$coder_package = $local_repository->findPackage('drupal/coder', '*');
|
||||
if (!empty($phpcs_package) && !empty($coder_package)) {
|
||||
$config = $event->getComposer()->getConfig();
|
||||
$vendor_dir = $config->get('vendor-dir');
|
||||
// Set phpcs' installed_paths config to point to our coder_sniffer
|
||||
// directory.
|
||||
PHP_CodeSniffer::setConfigData('installed_paths', $vendor_dir . '/drupal/coder/coder_sniffer');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove possibly problematic test files from vendored projects.
|
||||
*
|
||||
|
|
|
@ -55,7 +55,7 @@ class Condition extends Plugin {
|
|||
*
|
||||
* @var \Drupal\Core\Annotation\ContextDefinition[]
|
||||
*/
|
||||
public $context = array();
|
||||
public $context = [];
|
||||
|
||||
/**
|
||||
* The category under which the condition should listed in the UI.
|
||||
|
|
|
@ -46,7 +46,7 @@ class ConditionManager extends DefaultPluginManager implements ExecutableManager
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createInstance($plugin_id, array $configuration = array()) {
|
||||
public function createInstance($plugin_id, array $configuration = []) {
|
||||
$plugin = $this->getFactory()->createInstance($plugin_id, $configuration);
|
||||
|
||||
// If we receive any context values via config set it into the plugin.
|
||||
|
|
|
@ -53,11 +53,11 @@ abstract class ConditionPluginBase extends ExecutablePluginBase implements Condi
|
|||
}
|
||||
$contexts = $form_state->getTemporaryValue('gathered_contexts') ?: [];
|
||||
$form['context_mapping'] = $this->addContextAssignmentElement($this, $contexts);
|
||||
$form['negate'] = array(
|
||||
$form['negate'] = [
|
||||
'#type' => 'checkbox',
|
||||
'#title' => $this->t('Negate the condition'),
|
||||
'#default_value' => $this->configuration['negate'],
|
||||
);
|
||||
];
|
||||
return $form;
|
||||
}
|
||||
|
||||
|
@ -88,9 +88,9 @@ abstract class ConditionPluginBase extends ExecutablePluginBase implements Condi
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'id' => $this->getPluginId(),
|
||||
) + $this->configuration;
|
||||
] + $this->configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -105,16 +105,16 @@ abstract class ConditionPluginBase extends ExecutablePluginBase implements Condi
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function defaultConfiguration() {
|
||||
return array(
|
||||
return [
|
||||
'negate' => FALSE,
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function calculateDependencies() {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,7 +15,7 @@ class ConditionPluginCollection extends DefaultLazyPluginCollection {
|
|||
*
|
||||
* @var \Drupal\Component\Plugin\Context\ContextInterface[]
|
||||
*/
|
||||
protected $conditionContexts = array();
|
||||
protected $conditionContexts = [];
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
@ -33,7 +33,7 @@ class ConditionPluginCollection extends DefaultLazyPluginCollection {
|
|||
$configuration = parent::getConfiguration();
|
||||
// Remove configuration if it matches the defaults.
|
||||
foreach ($configuration as $instance_id => $instance_config) {
|
||||
$default_config = array();
|
||||
$default_config = [];
|
||||
$default_config['id'] = $instance_id;
|
||||
$default_config += $this->get($instance_id)->defaultConfiguration();
|
||||
// In order to determine if a plugin is configured, we must compare it to
|
||||
|
|
|
@ -34,7 +34,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $findByPrefixCache = array();
|
||||
protected $findByPrefixCache = [];
|
||||
|
||||
/**
|
||||
* Constructs a new CachedStorage.
|
||||
|
@ -80,7 +80,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function readMultiple(array $names) {
|
||||
$data_to_return = array();
|
||||
$data_to_return = [];
|
||||
|
||||
$cache_keys_map = $this->getCacheKeys($names);
|
||||
$cache_keys = array_values($cache_keys_map);
|
||||
|
@ -95,11 +95,11 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
$list = $this->storage->readMultiple($names_to_get);
|
||||
// Cache configuration objects that were loaded from the storage, cache
|
||||
// missing configuration objects as an explicit FALSE.
|
||||
$items = array();
|
||||
$items = [];
|
||||
foreach ($names_to_get as $name) {
|
||||
$data = isset($list[$name]) ? $list[$name] : FALSE;
|
||||
$data_to_return[$name] = $data;
|
||||
$items[$cache_keys_map[$name]] = array('data' => $data);
|
||||
$items[$cache_keys_map[$name]] = ['data' => $data];
|
||||
}
|
||||
|
||||
$this->cache->setMultiple($items);
|
||||
|
@ -125,7 +125,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
// While not all written data is read back, setting the cache instead of
|
||||
// just deleting it avoids cache rebuild stampedes.
|
||||
$this->cache->set($this->getCacheKey($name), $data);
|
||||
$this->findByPrefixCache = array();
|
||||
$this->findByPrefixCache = [];
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
@ -139,7 +139,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
// rebuilding the cache before the storage is gone.
|
||||
if ($this->storage->delete($name)) {
|
||||
$this->cache->delete($this->getCacheKey($name));
|
||||
$this->findByPrefixCache = array();
|
||||
$this->findByPrefixCache = [];
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
@ -154,7 +154,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
if ($this->storage->rename($name, $new_name)) {
|
||||
$this->cache->delete($this->getCacheKey($name));
|
||||
$this->cache->delete($this->getCacheKey($new_name));
|
||||
$this->findByPrefixCache = array();
|
||||
$this->findByPrefixCache = [];
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
|
@ -227,7 +227,7 @@ class CachedStorage implements StorageInterface, StorageCacheInterface {
|
|||
* Clears the static list cache.
|
||||
*/
|
||||
public function resetListCache() {
|
||||
$this->findByPrefixCache = array();
|
||||
$this->findByPrefixCache = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -155,10 +155,10 @@ class Config extends StorableConfigBase {
|
|||
protected function setOverriddenData() {
|
||||
$this->overriddenData = $this->data;
|
||||
if (isset($this->moduleOverrides) && is_array($this->moduleOverrides)) {
|
||||
$this->overriddenData = NestedArray::mergeDeepArray(array($this->overriddenData, $this->moduleOverrides), TRUE);
|
||||
$this->overriddenData = NestedArray::mergeDeepArray([$this->overriddenData, $this->moduleOverrides], TRUE);
|
||||
}
|
||||
if (isset($this->settingsOverrides) && is_array($this->settingsOverrides)) {
|
||||
$this->overriddenData = NestedArray::mergeDeepArray(array($this->overriddenData, $this->settingsOverrides), TRUE);
|
||||
$this->overriddenData = NestedArray::mergeDeepArray([$this->overriddenData, $this->settingsOverrides], TRUE);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ class Config extends StorableConfigBase {
|
|||
* The configuration object.
|
||||
*/
|
||||
public function delete() {
|
||||
$this->data = array();
|
||||
$this->data = [];
|
||||
$this->storage->delete($this->name);
|
||||
Cache::invalidateTags($this->getCacheTags());
|
||||
$this->isNew = TRUE;
|
||||
|
@ -281,10 +281,10 @@ class Config extends StorableConfigBase {
|
|||
if ($apply_overrides) {
|
||||
// Apply overrides.
|
||||
if (isset($this->moduleOverrides) && is_array($this->moduleOverrides)) {
|
||||
$original_data = NestedArray::mergeDeepArray(array($original_data, $this->moduleOverrides), TRUE);
|
||||
$original_data = NestedArray::mergeDeepArray([$original_data, $this->moduleOverrides], TRUE);
|
||||
}
|
||||
if (isset($this->settingsOverrides) && is_array($this->settingsOverrides)) {
|
||||
$original_data = NestedArray::mergeDeepArray(array($original_data, $this->settingsOverrides), TRUE);
|
||||
$original_data = NestedArray::mergeDeepArray([$original_data, $this->settingsOverrides], TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ abstract class ConfigBase implements RefinableCacheableDependencyInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $data = array();
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* The maximum length of a configuration object name.
|
||||
|
@ -247,7 +247,7 @@ abstract class ConfigBase implements RefinableCacheableDependencyInterface {
|
|||
*/
|
||||
public function merge(array $data_to_merge) {
|
||||
// Preserve integer keys so that configuration keys are not changed.
|
||||
$this->setData(NestedArray::mergeDeepArray(array($this->data, $data_to_merge), TRUE));
|
||||
$this->setData(NestedArray::mergeDeepArray([$this->data, $data_to_merge], TRUE));
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ class ConfigCollectionInfo extends Event {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $collections = array();
|
||||
protected $collections = [];
|
||||
|
||||
/**
|
||||
* Adds a collection to the list of possible collections.
|
||||
|
|
|
@ -43,7 +43,7 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
*
|
||||
* @var \Drupal\Core\Config\Config[]
|
||||
*/
|
||||
protected $cache = array();
|
||||
protected $cache = [];
|
||||
|
||||
/**
|
||||
* The typed config manager.
|
||||
|
@ -57,7 +57,7 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
*
|
||||
* @var \Drupal\Core\Config\ConfigFactoryOverrideInterface[]
|
||||
*/
|
||||
protected $configFactoryOverrides = array();
|
||||
protected $configFactoryOverrides = [];
|
||||
|
||||
/**
|
||||
* Constructs the Config factory.
|
||||
|
@ -101,7 +101,7 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
* A configuration object.
|
||||
*/
|
||||
protected function doGet($name, $immutable = TRUE) {
|
||||
if ($config = $this->doLoadMultiple(array($name), $immutable)) {
|
||||
if ($config = $this->doLoadMultiple([$name], $immutable)) {
|
||||
return $config[$name];
|
||||
}
|
||||
else {
|
||||
|
@ -111,7 +111,7 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
|
||||
if ($immutable) {
|
||||
// Get and apply any overrides.
|
||||
$overrides = $this->loadOverrides(array($name));
|
||||
$overrides = $this->loadOverrides([$name]);
|
||||
if (isset($overrides[$name])) {
|
||||
$config->setModuleOverride($overrides[$name]);
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
* List of successfully loaded configuration objects, keyed by name.
|
||||
*/
|
||||
protected function doLoadMultiple(array $names, $immutable = TRUE) {
|
||||
$list = array();
|
||||
$list = [];
|
||||
|
||||
foreach ($names as $key => $name) {
|
||||
$cache_key = $this->getConfigCacheKey($name, $immutable);
|
||||
|
@ -161,7 +161,7 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
// Pre-load remaining configuration files.
|
||||
if (!empty($names)) {
|
||||
// Initialise override information.
|
||||
$module_overrides = array();
|
||||
$module_overrides = [];
|
||||
$storage_data = $this->storage->readMultiple($names);
|
||||
|
||||
if ($immutable && !empty($storage_data)) {
|
||||
|
@ -202,11 +202,11 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
* An array of overrides keyed by the configuration object name.
|
||||
*/
|
||||
protected function loadOverrides(array $names) {
|
||||
$overrides = array();
|
||||
$overrides = [];
|
||||
foreach ($this->configFactoryOverrides as $override) {
|
||||
// Existing overrides take precedence since these will have been added
|
||||
// by events with a higher priority.
|
||||
$overrides = NestedArray::mergeDeepArray(array($override->loadOverrides($names), $overrides), TRUE);
|
||||
$overrides = NestedArray::mergeDeepArray([$override->loadOverrides($names), $overrides], TRUE);
|
||||
}
|
||||
return $overrides;
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
}
|
||||
}
|
||||
else {
|
||||
$this->cache = array();
|
||||
$this->cache = [];
|
||||
}
|
||||
|
||||
// Clear the static list cache if supported by the storage.
|
||||
|
@ -317,7 +317,7 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function clearStaticCache() {
|
||||
$this->cache = array();
|
||||
$this->cache = [];
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -365,9 +365,9 @@ class ConfigFactory implements ConfigFactoryInterface, EventSubscriberInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::SAVE][] = array('onConfigSave', 255);
|
||||
$events[ConfigEvents::DELETE][] = array('onConfigDelete', 255);
|
||||
public static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::SAVE][] = ['onConfigSave', 255];
|
||||
$events[ConfigEvents::DELETE][] = ['onConfigDelete', 255];
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,11 +44,11 @@ abstract class ConfigFactoryOverrideBase implements EventSubscriberInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::COLLECTION_INFO][] = array('addCollections');
|
||||
$events[ConfigEvents::SAVE][] = array('onConfigSave', 20);
|
||||
$events[ConfigEvents::DELETE][] = array('onConfigDelete', 20);
|
||||
$events[ConfigEvents::RENAME][] = array('onConfigRename', 20);
|
||||
public static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::COLLECTION_INFO][] = ['addCollections'];
|
||||
$events[ConfigEvents::SAVE][] = ['onConfigSave', 20];
|
||||
$events[ConfigEvents::DELETE][] = ['onConfigDelete', 20];
|
||||
$events[ConfigEvents::RENAME][] = ['onConfigRename', 20];
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ abstract class ConfigImportValidateEventSubscriberBase implements EventSubscribe
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::IMPORT_VALIDATE][] = array('onConfigImporterValidate', 20);
|
||||
public static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::IMPORT_VALIDATE][] = ['onConfigImporterValidate', 20];
|
||||
return $events;
|
||||
}
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ class ConfigImporter {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $errors = array();
|
||||
protected $errors = [];
|
||||
|
||||
/**
|
||||
* The total number of extensions to process.
|
||||
|
@ -253,16 +253,16 @@ class ConfigImporter {
|
|||
* An empty list of extensions to process.
|
||||
*/
|
||||
protected function getEmptyExtensionsProcessedList() {
|
||||
return array(
|
||||
'module' => array(
|
||||
'install' => array(),
|
||||
'uninstall' => array(),
|
||||
),
|
||||
'theme' => array(
|
||||
'install' => array(),
|
||||
'uninstall' => array(),
|
||||
),
|
||||
);
|
||||
return [
|
||||
'module' => [
|
||||
'install' => [],
|
||||
'uninstall' => [],
|
||||
],
|
||||
'theme' => [
|
||||
'install' => [],
|
||||
'uninstall' => [],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -273,7 +273,7 @@ class ConfigImporter {
|
|||
*/
|
||||
public function hasUnprocessedConfigurationChanges() {
|
||||
foreach ($this->storageComparer->getAllCollectionNames() as $collection) {
|
||||
foreach (array('delete', 'create', 'rename', 'update') as $op) {
|
||||
foreach (['delete', 'create', 'rename', 'update'] as $op) {
|
||||
if (count($this->getUnprocessedConfiguration($op, $collection))) {
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -440,10 +440,10 @@ class ConfigImporter {
|
|||
*/
|
||||
protected function getUnprocessedExtensions($type) {
|
||||
$changelist = $this->getExtensionChangelist($type);
|
||||
return array(
|
||||
return [
|
||||
'install' => array_diff($changelist['install'], $this->processedExtensions[$type]['install']),
|
||||
'uninstall' => array_diff($changelist['uninstall'], $this->processedExtensions[$type]['uninstall']),
|
||||
);
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -459,7 +459,7 @@ class ConfigImporter {
|
|||
$sync_steps = $this->initialize();
|
||||
|
||||
foreach ($sync_steps as $step) {
|
||||
$context = array();
|
||||
$context = [];
|
||||
do {
|
||||
$this->doSyncStep($step, $context);
|
||||
} while ($context['finished'] < 1);
|
||||
|
@ -489,7 +489,7 @@ class ConfigImporter {
|
|||
}
|
||||
elseif (is_callable($sync_step)) {
|
||||
\Drupal::service('config.installer')->setSyncing(TRUE);
|
||||
call_user_func_array($sync_step, array(&$context, $this));
|
||||
call_user_func_array($sync_step, [&$context, $this]);
|
||||
}
|
||||
else {
|
||||
throw new \InvalidArgumentException('Invalid configuration synchronization step');
|
||||
|
@ -517,13 +517,13 @@ class ConfigImporter {
|
|||
throw new ConfigImporterException(sprintf('%s is already importing', static::LOCK_NAME));
|
||||
}
|
||||
|
||||
$sync_steps = array();
|
||||
$sync_steps = [];
|
||||
$modules = $this->getUnprocessedExtensions('module');
|
||||
foreach (array('install', 'uninstall') as $op) {
|
||||
foreach (['install', 'uninstall'] as $op) {
|
||||
$this->totalExtensionsToProcess += count($modules[$op]);
|
||||
}
|
||||
$themes = $this->getUnprocessedExtensions('theme');
|
||||
foreach (array('install', 'uninstall') as $op) {
|
||||
foreach (['install', 'uninstall'] as $op) {
|
||||
$this->totalExtensionsToProcess += count($themes[$op]);
|
||||
}
|
||||
|
||||
|
@ -542,14 +542,14 @@ class ConfigImporter {
|
|||
/**
|
||||
* Processes extensions as a batch operation.
|
||||
*
|
||||
* @param array|\ArrayAccess $context.
|
||||
* @param array|\ArrayAccess $context
|
||||
* The batch context.
|
||||
*/
|
||||
protected function processExtensions(&$context) {
|
||||
$operation = $this->getNextExtensionOperation();
|
||||
if (!empty($operation)) {
|
||||
$this->processExtension($operation['type'], $operation['op'], $operation['name']);
|
||||
$context['message'] = t('Synchronizing extensions: @op @name.', array('@op' => $operation['op'], '@name' => $operation['name']));
|
||||
$context['message'] = t('Synchronizing extensions: @op @name.', ['@op' => $operation['op'], '@name' => $operation['name']]);
|
||||
$processed_count = count($this->processedExtensions['module']['install']) + count($this->processedExtensions['module']['uninstall']);
|
||||
$processed_count += count($this->processedExtensions['theme']['uninstall']) + count($this->processedExtensions['theme']['install']);
|
||||
$context['finished'] = $processed_count / $this->totalExtensionsToProcess;
|
||||
|
@ -562,7 +562,7 @@ class ConfigImporter {
|
|||
/**
|
||||
* Processes configuration as a batch operation.
|
||||
*
|
||||
* @param array|\ArrayAccess $context.
|
||||
* @param array|\ArrayAccess $context
|
||||
* The batch context.
|
||||
*/
|
||||
protected function processConfigurations(&$context) {
|
||||
|
@ -573,7 +573,7 @@ class ConfigImporter {
|
|||
if ($this->totalConfigurationToProcess == 0) {
|
||||
$this->storageComparer->reset();
|
||||
foreach ($this->storageComparer->getAllCollectionNames() as $collection) {
|
||||
foreach (array('delete', 'create', 'rename', 'update') as $op) {
|
||||
foreach (['delete', 'create', 'rename', 'update'] as $op) {
|
||||
$this->totalConfigurationToProcess += count($this->getUnprocessedConfiguration($op, $collection));
|
||||
}
|
||||
}
|
||||
|
@ -584,14 +584,14 @@ class ConfigImporter {
|
|||
$this->processConfiguration($operation['collection'], $operation['op'], $operation['name']);
|
||||
}
|
||||
if ($operation['collection'] == StorageInterface::DEFAULT_COLLECTION) {
|
||||
$context['message'] = $this->t('Synchronizing configuration: @op @name.', array('@op' => $operation['op'], '@name' => $operation['name']));
|
||||
$context['message'] = $this->t('Synchronizing configuration: @op @name.', ['@op' => $operation['op'], '@name' => $operation['name']]);
|
||||
}
|
||||
else {
|
||||
$context['message'] = $this->t('Synchronizing configuration: @op @name in @collection.', array('@op' => $operation['op'], '@name' => $operation['name'], '@collection' => $operation['collection']));
|
||||
$context['message'] = $this->t('Synchronizing configuration: @op @name in @collection.', ['@op' => $operation['op'], '@name' => $operation['name'], '@collection' => $operation['collection']]);
|
||||
}
|
||||
$processed_count = 0;
|
||||
foreach ($this->storageComparer->getAllCollectionNames() as $collection) {
|
||||
foreach (array('delete', 'create', 'rename', 'update') as $op) {
|
||||
foreach (['delete', 'create', 'rename', 'update'] as $op) {
|
||||
$processed_count += count($this->processedConfiguration[$collection][$op]);
|
||||
}
|
||||
}
|
||||
|
@ -605,7 +605,7 @@ class ConfigImporter {
|
|||
/**
|
||||
* Handles processing of missing content.
|
||||
*
|
||||
* @param array|\ArrayAccess $context.
|
||||
* @param array|\ArrayAccess $context
|
||||
* Standard batch context.
|
||||
*/
|
||||
protected function processMissingContent(&$context) {
|
||||
|
@ -637,7 +637,7 @@ class ConfigImporter {
|
|||
/**
|
||||
* Finishes the batch.
|
||||
*
|
||||
* @param array|\ArrayAccess $context.
|
||||
* @param array|\ArrayAccess $context
|
||||
* The batch context.
|
||||
*/
|
||||
protected function finish(&$context) {
|
||||
|
@ -657,15 +657,15 @@ class ConfigImporter {
|
|||
* on. If there is nothing left to do returns FALSE;
|
||||
*/
|
||||
protected function getNextExtensionOperation() {
|
||||
foreach (array('module', 'theme') as $type) {
|
||||
foreach (array('install', 'uninstall') as $op) {
|
||||
foreach (['module', 'theme'] as $type) {
|
||||
foreach (['install', 'uninstall'] as $op) {
|
||||
$unprocessed = $this->getUnprocessedExtensions($type);
|
||||
if (!empty($unprocessed[$op])) {
|
||||
return array(
|
||||
return [
|
||||
'op' => $op,
|
||||
'type' => $type,
|
||||
'name' => array_shift($unprocessed[$op]),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -683,14 +683,14 @@ class ConfigImporter {
|
|||
// The order configuration operations is processed is important. Deletes
|
||||
// have to come first so that recreates can work.
|
||||
foreach ($this->storageComparer->getAllCollectionNames() as $collection) {
|
||||
foreach (array('delete', 'create', 'rename', 'update') as $op) {
|
||||
foreach (['delete', 'create', 'rename', 'update'] as $op) {
|
||||
$config_names = $this->getUnprocessedConfiguration($op, $collection);
|
||||
if (!empty($config_names)) {
|
||||
return array(
|
||||
return [
|
||||
'op' => $op,
|
||||
'name' => array_shift($config_names),
|
||||
'collection' => $collection,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -716,11 +716,11 @@ class ConfigImporter {
|
|||
$old_entity_type_id = $this->configManager->getEntityTypeIdByName($names['old_name']);
|
||||
$new_entity_type_id = $this->configManager->getEntityTypeIdByName($names['new_name']);
|
||||
if ($old_entity_type_id != $new_entity_type_id) {
|
||||
$this->logError($this->t('Entity type mismatch on rename. @old_type not equal to @new_type for existing configuration @old_name and staged configuration @new_name.', array('@old_type' => $old_entity_type_id, '@new_type' => $new_entity_type_id, '@old_name' => $names['old_name'], '@new_name' => $names['new_name'])));
|
||||
$this->logError($this->t('Entity type mismatch on rename. @old_type not equal to @new_type for existing configuration @old_name and staged configuration @new_name.', ['@old_type' => $old_entity_type_id, '@new_type' => $new_entity_type_id, '@old_name' => $names['old_name'], '@new_name' => $names['new_name']]));
|
||||
}
|
||||
// Has to be a configuration entity.
|
||||
if (!$old_entity_type_id) {
|
||||
$this->logError($this->t('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', array('@old_name' => $names['old_name'], '@new_name' => $names['new_name'])));
|
||||
$this->logError($this->t('Rename operation for simple configuration. Existing configuration @old_name and staged configuration @new_name.', ['@old_name' => $names['old_name'], '@new_name' => $names['new_name']]));
|
||||
}
|
||||
}
|
||||
$this->eventDispatcher->dispatch(ConfigEvents::IMPORT_VALIDATE, new ConfigImporterEvent($this));
|
||||
|
@ -760,7 +760,7 @@ class ConfigImporter {
|
|||
}
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->logError($this->t('Unexpected error during import with operation @op for @name: @message', array('@op' => $op, '@name' => $name, '@message' => $e->getMessage())));
|
||||
$this->logError($this->t('Unexpected error during import with operation @op for @name: @message', ['@op' => $op, '@name' => $name, '@message' => $e->getMessage()]));
|
||||
// Error for that operation was logged, mark it as processed so that
|
||||
// the import can continue.
|
||||
$this->setProcessedConfiguration($collection, $op, $name);
|
||||
|
@ -783,7 +783,7 @@ class ConfigImporter {
|
|||
\Drupal::service('config.installer')
|
||||
->setSourceStorage($this->storageComparer->getSourceStorage());
|
||||
if ($type == 'module') {
|
||||
$this->moduleInstaller->$op(array($name), FALSE);
|
||||
$this->moduleInstaller->$op([$name], FALSE);
|
||||
// Installing a module can cause a kernel boot therefore reinject all the
|
||||
// services.
|
||||
$this->reInjectMe();
|
||||
|
@ -803,7 +803,7 @@ class ConfigImporter {
|
|||
$this->configManager->getConfigFactory()->reset('system.theme');
|
||||
$this->processedSystemTheme = TRUE;
|
||||
}
|
||||
$this->themeHandler->$op(array($name));
|
||||
$this->themeHandler->$op([$name]);
|
||||
}
|
||||
|
||||
$this->setProcessedExtension($type, $op, $name);
|
||||
|
@ -863,11 +863,11 @@ class ConfigImporter {
|
|||
$entity_type = $this->configManager->getEntityManager()->getDefinition($entity_type_id);
|
||||
$entity = $entity_storage->load($entity_storage->getIDFromConfigName($name, $entity_type->getConfigPrefix()));
|
||||
$entity->delete();
|
||||
$this->logError($this->t('Deleted and replaced configuration entity "@name"', array('@name' => $name)));
|
||||
$this->logError($this->t('Deleted and replaced configuration entity "@name"', ['@name' => $name]));
|
||||
}
|
||||
else {
|
||||
$this->storageComparer->getTargetStorage($collection)->delete($name);
|
||||
$this->logError($this->t('Deleted and replaced configuration "@name"', array('@name' => $name)));
|
||||
$this->logError($this->t('Deleted and replaced configuration "@name"', ['@name' => $name]));
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -875,7 +875,7 @@ class ConfigImporter {
|
|||
|
||||
case 'update':
|
||||
if (!$target_exists) {
|
||||
$this->logError($this->t('Update target "@name" is missing.', array('@name' => $name)));
|
||||
$this->logError($this->t('Update target "@name" is missing.', ['@name' => $name]));
|
||||
// Mark as processed so that the synchronization continues. Once the
|
||||
// the current synchronization is complete it will show up as a
|
||||
// create.
|
||||
|
@ -912,7 +912,7 @@ class ConfigImporter {
|
|||
}
|
||||
else {
|
||||
$data = $this->storageComparer->getSourceStorage($collection)->read($name);
|
||||
$config->setData($data ? $data : array());
|
||||
$config->setData($data ? $data : []);
|
||||
$config->save();
|
||||
}
|
||||
$this->setProcessedConfiguration($collection, $op, $name);
|
||||
|
@ -1037,7 +1037,7 @@ class ConfigImporter {
|
|||
* keep the services used by the importer in sync.
|
||||
*/
|
||||
protected function reInjectMe() {
|
||||
$this->_serviceIds = array();
|
||||
$this->_serviceIds = [];
|
||||
$vars = get_object_vars($this);
|
||||
foreach ($vars as $key => $value) {
|
||||
if (is_object($value) && isset($value->_serviceId)) {
|
||||
|
|
|
@ -6,7 +6,6 @@ use Drupal\Component\Utility\Crypt;
|
|||
use Drupal\Component\Utility\Unicode;
|
||||
use Drupal\Core\Config\Entity\ConfigDependencyManager;
|
||||
use Drupal\Core\Config\Entity\ConfigEntityDependency;
|
||||
use Drupal\Core\Site\Settings;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class ConfigInstaller implements ConfigInstallerInterface {
|
||||
|
@ -60,6 +59,13 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
*/
|
||||
protected $isSyncing = FALSE;
|
||||
|
||||
/**
|
||||
* The name of the currently active installation profile.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $installProfile;
|
||||
|
||||
/**
|
||||
* Constructs the configuration installer.
|
||||
*
|
||||
|
@ -73,13 +79,16 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
* The configuration manager.
|
||||
* @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
|
||||
* The event dispatcher.
|
||||
* @param string $install_profile
|
||||
* The name of the currently active installation profile.
|
||||
*/
|
||||
public function __construct(ConfigFactoryInterface $config_factory, StorageInterface $active_storage, TypedConfigManagerInterface $typed_config, ConfigManagerInterface $config_manager, EventDispatcherInterface $event_dispatcher) {
|
||||
public function __construct(ConfigFactoryInterface $config_factory, StorageInterface $active_storage, TypedConfigManagerInterface $typed_config, ConfigManagerInterface $config_manager, EventDispatcherInterface $event_dispatcher, $install_profile) {
|
||||
$this->configFactory = $config_factory;
|
||||
$this->activeStorages[$active_storage->getCollectionName()] = $active_storage;
|
||||
$this->typedConfig = $typed_config;
|
||||
$this->configManager = $config_manager;
|
||||
$this->eventDispatcher = $event_dispatcher;
|
||||
$this->installProfile = $install_profile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -140,7 +149,7 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
// Install any optional configuration entities whose dependencies can now
|
||||
// be met. This searches all the installed modules config/optional
|
||||
// directories.
|
||||
$storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE);
|
||||
$storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, FALSE, $this->installProfile);
|
||||
$this->installOptionalConfig($storage, [$type => $name]);
|
||||
}
|
||||
|
||||
|
@ -156,11 +165,11 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
$optional_profile_config = [];
|
||||
if (!$storage) {
|
||||
// Search the install profile's optional configuration too.
|
||||
$storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, TRUE);
|
||||
$storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_OPTIONAL_DIRECTORY, StorageInterface::DEFAULT_COLLECTION, TRUE, $this->installProfile);
|
||||
// The extension install storage ensures that overrides are used.
|
||||
$profile_storage = NULL;
|
||||
}
|
||||
elseif (isset($profile)) {
|
||||
elseif (!empty($profile)) {
|
||||
// Creates a profile storage to search for overrides.
|
||||
$profile_install_path = $this->drupalGetPath('module', $profile) . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY;
|
||||
$profile_storage = new FileStorage($profile_install_path, StorageInterface::DEFAULT_COLLECTION);
|
||||
|
@ -331,7 +340,7 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function installCollectionDefaultConfig($collection) {
|
||||
$storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_INSTALL_DIRECTORY, $collection, $this->drupalInstallationAttempted());
|
||||
$storage = new ExtensionInstallStorage($this->getActiveStorages(StorageInterface::DEFAULT_COLLECTION), InstallStorage::CONFIG_INSTALL_DIRECTORY, $collection, $this->drupalInstallationAttempted(), $this->installProfile);
|
||||
// Only install configuration for enabled extensions.
|
||||
$enabled_extensions = $this->getEnabledExtensions();
|
||||
$config_to_install = array_filter($storage->listAll(), function ($config_name) use ($enabled_extensions) {
|
||||
|
@ -416,7 +425,7 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
* collection.
|
||||
*/
|
||||
protected function findPreExistingConfiguration(StorageInterface $storage) {
|
||||
$existing_configuration = array();
|
||||
$existing_configuration = [];
|
||||
// Gather information about all the supported collections.
|
||||
$collection_info = $this->configManager->getConfigCollectionInfo();
|
||||
|
||||
|
@ -455,9 +464,9 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
$profile_storages = $this->getProfileStorages($name);
|
||||
|
||||
// Check the dependencies of configuration provided by the module.
|
||||
$invalid_default_config = $this->findDefaultConfigWithUnmetDependencies($storage, $enabled_extensions, $profile_storages);
|
||||
list($invalid_default_config, $missing_dependencies) = $this->findDefaultConfigWithUnmetDependencies($storage, $enabled_extensions, $profile_storages);
|
||||
if (!empty($invalid_default_config)) {
|
||||
throw UnmetDependenciesException::create($name, $invalid_default_config);
|
||||
throw UnmetDependenciesException::create($name, array_unique($missing_dependencies));
|
||||
}
|
||||
|
||||
// Install profiles can not have config clashes. Configuration that
|
||||
|
@ -485,14 +494,24 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
* for overrides.
|
||||
*
|
||||
* @return array
|
||||
* List of configuration that has unmet dependencies
|
||||
* An array containing:
|
||||
* - A list of configuration that has unmet dependencies.
|
||||
* - An array that will be filled with the missing dependency names, keyed
|
||||
* by the dependents' names.
|
||||
*/
|
||||
protected function findDefaultConfigWithUnmetDependencies(StorageInterface $storage, array $enabled_extensions, array $profile_storages = []) {
|
||||
$missing_dependencies = [];
|
||||
$config_to_create = $this->getConfigToCreate($storage, StorageInterface::DEFAULT_COLLECTION, '', $profile_storages);
|
||||
$all_config = array_merge($this->configFactory->listAll(), array_keys($config_to_create));
|
||||
return array_filter(array_keys($config_to_create), function($config_name) use ($enabled_extensions, $all_config, $config_to_create) {
|
||||
return !$this->validateDependencies($config_name, $config_to_create[$config_name], $enabled_extensions, $all_config);
|
||||
});
|
||||
foreach ($config_to_create as $config_name => $config) {
|
||||
if ($missing = $this->getMissingDependencies($config_name, $config, $enabled_extensions, $all_config)) {
|
||||
$missing_dependencies[$config_name] = $missing;
|
||||
}
|
||||
}
|
||||
return [
|
||||
array_intersect_key($config_to_create, $missing_dependencies),
|
||||
$missing_dependencies,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -508,11 +527,38 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
* A list of all the active configuration names.
|
||||
*
|
||||
* @return bool
|
||||
* TRUE if the dependencies are met, FALSE if not.
|
||||
* TRUE if all dependencies are present, FALSE otherwise.
|
||||
*/
|
||||
protected function validateDependencies($config_name, array $data, array $enabled_extensions, array $all_config) {
|
||||
list($provider) = explode('.', $config_name, 2);
|
||||
if (!isset($data['dependencies'])) {
|
||||
// Simple config or a config entity without dependencies.
|
||||
list($provider) = explode('.', $config_name, 2);
|
||||
return in_array($provider, $enabled_extensions, TRUE);
|
||||
}
|
||||
|
||||
$missing = $this->getMissingDependencies($config_name, $data, $enabled_extensions, $all_config);
|
||||
return empty($missing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of missing dependencies for a config object.
|
||||
*
|
||||
* @param string $config_name
|
||||
* The name of the configuration object that is being validated.
|
||||
* @param array $data
|
||||
* Configuration data.
|
||||
* @param array $enabled_extensions
|
||||
* A list of all the currently enabled modules and themes.
|
||||
* @param array $all_config
|
||||
* A list of all the active configuration names.
|
||||
*
|
||||
* @return array
|
||||
* A list of missing config dependencies.
|
||||
*/
|
||||
protected function getMissingDependencies($config_name, array $data, array $enabled_extensions, array $all_config) {
|
||||
$missing = [];
|
||||
if (isset($data['dependencies'])) {
|
||||
list($provider) = explode('.', $config_name, 2);
|
||||
$all_dependencies = $data['dependencies'];
|
||||
|
||||
// Ensure enforced dependencies are included.
|
||||
|
@ -522,10 +568,7 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
}
|
||||
// Ensure the configuration entity type provider is in the list of
|
||||
// dependencies.
|
||||
if (!isset($all_dependencies['module'])) {
|
||||
$all_dependencies['module'][] = $provider;
|
||||
}
|
||||
elseif (!in_array($provider, $all_dependencies['module'])) {
|
||||
if (!isset($all_dependencies['module']) || !in_array($provider, $all_dependencies['module'])) {
|
||||
$all_dependencies['module'][] = $provider;
|
||||
}
|
||||
|
||||
|
@ -541,18 +584,12 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
break;
|
||||
}
|
||||
if (!empty($list_to_check)) {
|
||||
$missing = array_diff($dependencies, $list_to_check);
|
||||
if (!empty($missing)) {
|
||||
return FALSE;
|
||||
}
|
||||
$missing = array_merge($missing, array_diff($dependencies, $list_to_check));
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Simple config or a config entity without dependencies.
|
||||
return in_array($provider, $enabled_extensions, TRUE);
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
return $missing;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -638,15 +675,13 @@ class ConfigInstaller implements ConfigInstallerInterface {
|
|||
/**
|
||||
* Gets the install profile from settings.
|
||||
*
|
||||
* @return string|null $profile
|
||||
* @return string|null
|
||||
* The name of the installation profile or NULL if no installation profile
|
||||
* is currently active. This is the case for example during the first steps
|
||||
* of the installer or during unit tests.
|
||||
*/
|
||||
protected function drupalGetProfile() {
|
||||
// Settings is safe to use because settings.php is written before any module
|
||||
// is installed.
|
||||
return Settings::get('install_profile');
|
||||
return $this->installProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -148,17 +148,17 @@ class ConfigManager implements ConfigManagerInterface {
|
|||
$target_data = explode("\n", Yaml::encode($target_storage->read($target_name)));
|
||||
|
||||
// Check for new or removed files.
|
||||
if ($source_data === array('false')) {
|
||||
if ($source_data === ['false']) {
|
||||
// Added file.
|
||||
// Cast the result of t() to a string, as the diff engine doesn't know
|
||||
// about objects.
|
||||
$source_data = array((string) $this->t('File added'));
|
||||
$source_data = [(string) $this->t('File added')];
|
||||
}
|
||||
if ($target_data === array('false')) {
|
||||
if ($target_data === ['false']) {
|
||||
// Deleted file.
|
||||
// Cast the result of t() to a string, as the diff engine doesn't know
|
||||
// about objects.
|
||||
$target_data = array((string) $this->t('File removed'));
|
||||
$target_data = [(string) $this->t('File removed')];
|
||||
}
|
||||
|
||||
return new Diff($source_data, $target_data);
|
||||
|
@ -251,7 +251,7 @@ class ConfigManager implements ConfigManagerInterface {
|
|||
if (!$dependency_manager) {
|
||||
$dependency_manager = $this->getConfigDependencyManager();
|
||||
}
|
||||
$dependencies = array();
|
||||
$dependencies = [];
|
||||
foreach ($names as $name) {
|
||||
$dependencies = array_merge($dependencies, $dependency_manager->getDependentEntities($type, $name));
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ class ConfigManager implements ConfigManagerInterface {
|
|||
*/
|
||||
public function findConfigEntityDependentsAsEntities($type, array $names, ConfigDependencyManager $dependency_manager = NULL) {
|
||||
$dependencies = $this->findConfigEntityDependents($type, $names, $dependency_manager);
|
||||
$entities = array();
|
||||
$entities = [];
|
||||
$definitions = $this->entityManager->getDefinitions();
|
||||
foreach ($dependencies as $config_name => $dependency) {
|
||||
// Group by entity type to efficient load entities using
|
||||
|
@ -278,7 +278,7 @@ class ConfigManager implements ConfigManagerInterface {
|
|||
$entities[$entity_type_id][] = $id;
|
||||
}
|
||||
}
|
||||
$entities_to_return = array();
|
||||
$entities_to_return = [];
|
||||
foreach ($entities as $entity_type_id => $entities_to_load) {
|
||||
$storage = $this->entityManager->getStorage($entity_type_id);
|
||||
// Remove the keys since there are potential ID clashes from different
|
||||
|
@ -411,12 +411,12 @@ class ConfigManager implements ConfigManagerInterface {
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
$affected_dependencies = array(
|
||||
'config' => array(),
|
||||
'content' => array(),
|
||||
'module' => array(),
|
||||
'theme' => array(),
|
||||
);
|
||||
$affected_dependencies = [
|
||||
'config' => [],
|
||||
'content' => [],
|
||||
'module' => [],
|
||||
'theme' => [],
|
||||
];
|
||||
|
||||
// Work out if any of the entity's dependencies are going to be affected.
|
||||
if (isset($entity_dependencies[$type])) {
|
||||
|
@ -465,8 +465,8 @@ class ConfigManager implements ConfigManagerInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function findMissingContentDependencies() {
|
||||
$content_dependencies = array();
|
||||
$missing_dependencies = array();
|
||||
$content_dependencies = [];
|
||||
$missing_dependencies = [];
|
||||
foreach ($this->activeStorage->readMultiple($this->activeStorage->listAll()) as $config_data) {
|
||||
if (isset($config_data['dependencies']['content'])) {
|
||||
$content_dependencies = array_merge($content_dependencies, $config_data['dependencies']['content']);
|
||||
|
@ -479,11 +479,11 @@ class ConfigManager implements ConfigManagerInterface {
|
|||
// Format of the dependency is entity_type:bundle:uuid.
|
||||
list($entity_type, $bundle, $uuid) = explode(':', $content_dependency, 3);
|
||||
if (!$this->entityManager->loadEntityByUuid($entity_type, $uuid)) {
|
||||
$missing_dependencies[$uuid] = array(
|
||||
$missing_dependencies[$uuid] = [
|
||||
'entity_type' => $entity_type,
|
||||
'bundle' => $bundle,
|
||||
'uuid' => $uuid,
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
return $missing_dependencies;
|
||||
|
|
|
@ -43,7 +43,7 @@ class ConfigModuleOverridesEvent extends Event {
|
|||
public function __construct(array $names, LanguageInterface $language = NULL) {
|
||||
$this->names = $names;
|
||||
$this->language = $language;
|
||||
$this->overrides = array();
|
||||
$this->overrides = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,7 +69,7 @@ class ConfigModuleOverridesEvent extends Event {
|
|||
/**
|
||||
* Get configuration overrides.
|
||||
*
|
||||
* @return array.
|
||||
* @return array
|
||||
* The array of configuration overrides.
|
||||
*/
|
||||
public function getOverrides() {
|
||||
|
@ -91,7 +91,7 @@ class ConfigModuleOverridesEvent extends Event {
|
|||
if (isset($this->overrides[$name])) {
|
||||
// Existing overrides take precedence since these will have been added
|
||||
// by events with a higher priority.
|
||||
$this->overrides[$name] = NestedArray::mergeDeepArray(array($values, $this->overrides[$name]), TRUE);
|
||||
$this->overrides[$name] = NestedArray::mergeDeepArray([$values, $this->overrides[$name]], TRUE);
|
||||
}
|
||||
else {
|
||||
$this->overrides[$name] = $values;
|
||||
|
|
|
@ -32,7 +32,7 @@ class DatabaseStorage implements StorageInterface {
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options = array();
|
||||
protected $options = [];
|
||||
|
||||
/**
|
||||
* The storage collection.
|
||||
|
@ -54,7 +54,7 @@ class DatabaseStorage implements StorageInterface {
|
|||
* (optional) The collection to store configuration in. Defaults to the
|
||||
* default collection.
|
||||
*/
|
||||
public function __construct(Connection $connection, $table, array $options = array(), $collection = StorageInterface::DEFAULT_COLLECTION) {
|
||||
public function __construct(Connection $connection, $table, array $options = [], $collection = StorageInterface::DEFAULT_COLLECTION) {
|
||||
$this->connection = $connection;
|
||||
$this->table = $table;
|
||||
$this->options = $options;
|
||||
|
@ -66,10 +66,10 @@ class DatabaseStorage implements StorageInterface {
|
|||
*/
|
||||
public function exists($name) {
|
||||
try {
|
||||
return (bool) $this->connection->queryRange('SELECT 1 FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name = :name', 0, 1, array(
|
||||
return (bool) $this->connection->queryRange('SELECT 1 FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name = :name', 0, 1, [
|
||||
':collection' => $this->collection,
|
||||
':name' => $name,
|
||||
), $this->options)->fetchField();
|
||||
], $this->options)->fetchField();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
// If we attempt a read without actually having the database or the table
|
||||
|
@ -84,7 +84,7 @@ class DatabaseStorage implements StorageInterface {
|
|||
public function read($name) {
|
||||
$data = FALSE;
|
||||
try {
|
||||
$raw = $this->connection->query('SELECT data FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name = :name', array(':collection' => $this->collection, ':name' => $name), $this->options)->fetchField();
|
||||
$raw = $this->connection->query('SELECT data FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name = :name', [':collection' => $this->collection, ':name' => $name], $this->options)->fetchField();
|
||||
if ($raw !== FALSE) {
|
||||
$data = $this->decode($raw);
|
||||
}
|
||||
|
@ -100,9 +100,9 @@ class DatabaseStorage implements StorageInterface {
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function readMultiple(array $names) {
|
||||
$list = array();
|
||||
$list = [];
|
||||
try {
|
||||
$list = $this->connection->query('SELECT name, data FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name IN ( :names[] )', array(':collection' => $this->collection, ':names[]' => $names), $this->options)->fetchAllKeyed();
|
||||
$list = $this->connection->query('SELECT name, data FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection = :collection AND name IN ( :names[] )', [':collection' => $this->collection, ':names[]' => $names], $this->options)->fetchAllKeyed();
|
||||
foreach ($list as &$data) {
|
||||
$data = $this->decode($data);
|
||||
}
|
||||
|
@ -143,10 +143,10 @@ class DatabaseStorage implements StorageInterface {
|
|||
* @return bool
|
||||
*/
|
||||
protected function doWrite($name, $data) {
|
||||
$options = array('return' => Database::RETURN_AFFECTED) + $this->options;
|
||||
$options = ['return' => Database::RETURN_AFFECTED] + $this->options;
|
||||
return (bool) $this->connection->merge($this->table, $options)
|
||||
->keys(array('collection', 'name'), array($this->collection, $name))
|
||||
->fields(array('data' => $data))
|
||||
->keys(['collection', 'name'], [$this->collection, $name])
|
||||
->fields(['data' => $data])
|
||||
->execute();
|
||||
}
|
||||
|
||||
|
@ -182,32 +182,32 @@ class DatabaseStorage implements StorageInterface {
|
|||
* Defines the schema for the configuration table.
|
||||
*/
|
||||
protected static function schemaDefinition() {
|
||||
$schema = array(
|
||||
$schema = [
|
||||
'description' => 'The base table for configuration data.',
|
||||
'fields' => array(
|
||||
'collection' => array(
|
||||
'fields' => [
|
||||
'collection' => [
|
||||
'description' => 'Primary Key: Config object collection.',
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'name' => array(
|
||||
],
|
||||
'name' => [
|
||||
'description' => 'Primary Key: Config object name.',
|
||||
'type' => 'varchar_ascii',
|
||||
'length' => 255,
|
||||
'not null' => TRUE,
|
||||
'default' => '',
|
||||
),
|
||||
'data' => array(
|
||||
],
|
||||
'data' => [
|
||||
'description' => 'A serialized configuration object data.',
|
||||
'type' => 'blob',
|
||||
'not null' => FALSE,
|
||||
'size' => 'big',
|
||||
),
|
||||
),
|
||||
'primary key' => array('collection', 'name'),
|
||||
);
|
||||
],
|
||||
],
|
||||
'primary key' => ['collection', 'name'],
|
||||
];
|
||||
return $schema;
|
||||
}
|
||||
|
||||
|
@ -219,7 +219,7 @@ class DatabaseStorage implements StorageInterface {
|
|||
* @todo Ignore replica targets for data manipulation operations.
|
||||
*/
|
||||
public function delete($name) {
|
||||
$options = array('return' => Database::RETURN_AFFECTED) + $this->options;
|
||||
$options = ['return' => Database::RETURN_AFFECTED] + $this->options;
|
||||
return (bool) $this->connection->delete($this->table, $options)
|
||||
->condition('collection', $this->collection)
|
||||
->condition('name', $name)
|
||||
|
@ -233,9 +233,9 @@ class DatabaseStorage implements StorageInterface {
|
|||
* @throws PDOException
|
||||
*/
|
||||
public function rename($name, $new_name) {
|
||||
$options = array('return' => Database::RETURN_AFFECTED) + $this->options;
|
||||
$options = ['return' => Database::RETURN_AFFECTED] + $this->options;
|
||||
return (bool) $this->connection->update($this->table, $options)
|
||||
->fields(array('name' => $new_name))
|
||||
->fields(['name' => $new_name])
|
||||
->condition('name', $name)
|
||||
->condition('collection', $this->collection)
|
||||
->execute();
|
||||
|
@ -266,14 +266,14 @@ class DatabaseStorage implements StorageInterface {
|
|||
public function listAll($prefix = '') {
|
||||
try {
|
||||
$query = $this->connection->select($this->table);
|
||||
$query->fields($this->table, array('name'));
|
||||
$query->fields($this->table, ['name']);
|
||||
$query->condition('collection', $this->collection, '=');
|
||||
$query->condition('name', $prefix . '%', 'LIKE');
|
||||
$query->orderBy('collection')->orderBy('name');
|
||||
return $query->execute()->fetchCol();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ class DatabaseStorage implements StorageInterface {
|
|||
*/
|
||||
public function deleteAll($prefix = '') {
|
||||
try {
|
||||
$options = array('return' => Database::RETURN_AFFECTED) + $this->options;
|
||||
$options = ['return' => Database::RETURN_AFFECTED] + $this->options;
|
||||
return (bool) $this->connection->delete($this->table, $options)
|
||||
->condition('name', $prefix . '%', 'LIKE')
|
||||
->condition('collection', $this->collection)
|
||||
|
@ -317,12 +317,12 @@ class DatabaseStorage implements StorageInterface {
|
|||
*/
|
||||
public function getAllCollectionNames() {
|
||||
try {
|
||||
return $this->connection->query('SELECT DISTINCT collection FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection <> :collection ORDER by collection', array(
|
||||
':collection' => StorageInterface::DEFAULT_COLLECTION)
|
||||
return $this->connection->query('SELECT DISTINCT collection FROM {' . $this->connection->escapeTable($this->table) . '} WHERE collection <> :collection ORDER by collection', [
|
||||
':collection' => StorageInterface::DEFAULT_COLLECTION]
|
||||
)->fetchCol();
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Core\Config\Development;
|
||||
|
||||
use Drupal\Component\Utility\Crypt;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Config\ConfigCrudEvent;
|
||||
use Drupal\Core\Config\ConfigEvents;
|
||||
use Drupal\Core\Config\Schema\SchemaCheckTrait;
|
||||
use Drupal\Core\Config\Schema\SchemaIncompleteException;
|
||||
use Drupal\Core\Config\StorageInterface;
|
||||
use Drupal\Core\Config\TypedConfigManagerInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* Listens to the config save event and validates schema.
|
||||
*
|
||||
* If tests have the $strictConfigSchema property set to TRUE this event
|
||||
* listener will be added to the container and throw exceptions if configuration
|
||||
* is invalid.
|
||||
*
|
||||
* @see \Drupal\KernelTests\KernelTestBase::register()
|
||||
* @see \Drupal\simpletest\WebTestBase::setUp()
|
||||
* @see \Drupal\simpletest\KernelTestBase::containerBuild()
|
||||
*/
|
||||
class ConfigSchemaChecker implements EventSubscriberInterface {
|
||||
use SchemaCheckTrait;
|
||||
|
||||
/**
|
||||
* The typed config manger.
|
||||
*
|
||||
* @var \Drupal\Core\Config\TypedConfigManagerInterface
|
||||
*/
|
||||
protected $typedManager;
|
||||
|
||||
/**
|
||||
* An array of config checked already. Keyed by config name and a checksum.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $checked = [];
|
||||
|
||||
/**
|
||||
* An array of config object names that are excluded from schema checking.
|
||||
*
|
||||
* @var string[]
|
||||
*/
|
||||
protected $exclude = [];
|
||||
|
||||
/**
|
||||
* Constructs the ConfigSchemaChecker object.
|
||||
*
|
||||
* @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_manager
|
||||
* The typed config manager.
|
||||
* @param string[] $exclude
|
||||
* An array of config object names that are excluded from schema checking.
|
||||
*/
|
||||
public function __construct(TypedConfigManagerInterface $typed_manager, array $exclude = []) {
|
||||
$this->typedManager = $typed_manager;
|
||||
$this->exclude = $exclude;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks that configuration complies with its schema on config save.
|
||||
*
|
||||
* @param \Drupal\Core\Config\ConfigCrudEvent $event
|
||||
* The configuration event.
|
||||
*
|
||||
* @throws \Drupal\Core\Config\Schema\SchemaIncompleteException
|
||||
* Exception thrown when configuration does not match its schema.
|
||||
*/
|
||||
public function onConfigSave(ConfigCrudEvent $event) {
|
||||
// Only validate configuration if in the default collection. Other
|
||||
// collections may have incomplete configuration (for example language
|
||||
// overrides only). These are not valid in themselves.
|
||||
$saved_config = $event->getConfig();
|
||||
if ($saved_config->getStorage()->getCollectionName() != StorageInterface::DEFAULT_COLLECTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
$name = $saved_config->getName();
|
||||
$data = $saved_config->get();
|
||||
$checksum = Crypt::hashBase64(serialize($data));
|
||||
if (!in_array($name, $this->exclude) && !isset($this->checked[$name . ':' . $checksum])) {
|
||||
$this->checked[$name . ':' . $checksum] = TRUE;
|
||||
$errors = $this->checkConfigSchema($this->typedManager, $name, $data);
|
||||
if ($errors === FALSE) {
|
||||
throw new SchemaIncompleteException("No schema for $name");
|
||||
}
|
||||
elseif (is_array($errors)) {
|
||||
$text_errors = [];
|
||||
foreach ($errors as $key => $error) {
|
||||
$text_errors[] = SafeMarkup::format('@key @error', ['@key' => $key, '@error' => $error]);
|
||||
}
|
||||
throw new SchemaIncompleteException("Schema errors for $name with the following errors: " . implode(', ', $text_errors));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function getSubscribedEvents() {
|
||||
$events[ConfigEvents::SAVE][] = ['onConfigSave', 255];
|
||||
return $events;
|
||||
}
|
||||
|
||||
}
|
|
@ -17,7 +17,7 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
*
|
||||
* Provided by \Drupal\Core\StringTranslation\StringTranslationTrait.
|
||||
*/
|
||||
abstract protected function t($string, array $args = array(), array $options = array());
|
||||
abstract protected function t($string, array $args = [], array $options = []);
|
||||
|
||||
/**
|
||||
* Adds form elements to list affected configuration entities.
|
||||
|
@ -41,15 +41,15 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
protected function addDependencyListsToForm(array &$form, $type, array $names, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager) {
|
||||
// Get the dependent entities.
|
||||
$dependent_entities = $config_manager->getConfigEntitiesToChangeOnDependencyRemoval($type, $names);
|
||||
$entity_types = array();
|
||||
$entity_types = [];
|
||||
|
||||
$form['entity_updates'] = array(
|
||||
$form['entity_updates'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Configuration updates'),
|
||||
'#description' => $this->t('The listed configuration will be updated.'),
|
||||
'#open' => TRUE,
|
||||
'#access' => FALSE,
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($dependent_entities['update'] as $entity) {
|
||||
/** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
|
||||
|
@ -59,11 +59,11 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
// Store the ID and label to sort the entity types and entities later.
|
||||
$label = $entity_type->getLabel();
|
||||
$entity_types[$entity_type_id] = $label;
|
||||
$form['entity_updates'][$entity_type_id] = array(
|
||||
$form['entity_updates'][$entity_type_id] = [
|
||||
'#theme' => 'item_list',
|
||||
'#title' => $label,
|
||||
'#items' => array(),
|
||||
);
|
||||
'#items' => [],
|
||||
];
|
||||
}
|
||||
$form['entity_updates'][$entity_type_id]['#items'][$entity->id()] = $entity->label() ?: $entity->id();
|
||||
}
|
||||
|
@ -81,13 +81,13 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
}
|
||||
}
|
||||
|
||||
$form['entity_deletes'] = array(
|
||||
$form['entity_deletes'] = [
|
||||
'#type' => 'details',
|
||||
'#title' => $this->t('Configuration deletions'),
|
||||
'#description' => $this->t('The listed configuration will be deleted.'),
|
||||
'#open' => TRUE,
|
||||
'#access' => FALSE,
|
||||
);
|
||||
];
|
||||
|
||||
foreach ($dependent_entities['delete'] as $entity) {
|
||||
$entity_type_id = $entity->getEntityTypeId();
|
||||
|
@ -96,11 +96,11 @@ trait ConfigDependencyDeleteFormTrait {
|
|||
// Store the ID and label to sort the entity types and entities later.
|
||||
$label = $entity_type->getLabel();
|
||||
$entity_types[$entity_type_id] = $label;
|
||||
$form['entity_deletes'][$entity_type_id] = array(
|
||||
$form['entity_deletes'][$entity_type_id] = [
|
||||
'#theme' => 'item_list',
|
||||
'#title' => $label,
|
||||
'#items' => array(),
|
||||
);
|
||||
'#items' => [],
|
||||
];
|
||||
}
|
||||
$form['entity_deletes'][$entity_type_id]['#items'][$entity->id()] = $entity->label() ?: $entity->id();
|
||||
}
|
||||
|
|
|
@ -126,7 +126,7 @@ class ConfigDependencyManager {
|
|||
*
|
||||
* @var \Drupal\Core\Config\Entity\ConfigEntityDependency[]
|
||||
*/
|
||||
protected $data = array();
|
||||
protected $data = [];
|
||||
|
||||
/**
|
||||
* The directed acyclic graph.
|
||||
|
@ -150,9 +150,9 @@ class ConfigDependencyManager {
|
|||
* An array of config entity dependency objects that are dependent.
|
||||
*/
|
||||
public function getDependentEntities($type, $name) {
|
||||
$dependent_entities = array();
|
||||
$dependent_entities = [];
|
||||
|
||||
$entities_to_check = array();
|
||||
$entities_to_check = [];
|
||||
if ($type == 'config') {
|
||||
$entities_to_check[] = $name;
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ class ConfigDependencyManager {
|
|||
* supplied entities to check.
|
||||
*/
|
||||
protected function createGraphConfigEntityDependencies($entities_to_check) {
|
||||
$dependent_entities = array();
|
||||
$dependent_entities = [];
|
||||
$graph = $this->getGraph();
|
||||
|
||||
foreach ($entities_to_check as $entity) {
|
||||
|
@ -304,7 +304,7 @@ class ConfigDependencyManager {
|
|||
*/
|
||||
protected function getGraph() {
|
||||
if (!isset($this->graph)) {
|
||||
$graph = array();
|
||||
$graph = [];
|
||||
foreach ($this->data as $entity) {
|
||||
$graph_key = $entity->getConfigDependencyName();
|
||||
if (!isset($graph[$graph_key])) {
|
||||
|
|
|
@ -86,7 +86,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
|||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $third_party_settings = array();
|
||||
protected $third_party_settings = [];
|
||||
|
||||
/**
|
||||
* Information maintained by Drupal core about configuration.
|
||||
|
@ -263,7 +263,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() {
|
||||
$properties = array();
|
||||
$properties = [];
|
||||
/** @var \Drupal\Core\Config\Entity\ConfigEntityTypeInterface $entity_type */
|
||||
$entity_type = $this->getEntityType();
|
||||
|
||||
|
@ -411,7 +411,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function url($rel = 'edit-form', $options = array()) {
|
||||
public function url($rel = 'edit-form', $options = []) {
|
||||
// Do not remove this override: the default value of $rel is different.
|
||||
return parent::url($rel, $options);
|
||||
}
|
||||
|
@ -551,7 +551,7 @@ abstract class ConfigEntityBase extends Entity implements ConfigEntityInterface
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function getThirdPartySettings($module) {
|
||||
return isset($this->third_party_settings[$module]) ? $this->third_party_settings[$module] : array();
|
||||
return isset($this->third_party_settings[$module]) ? $this->third_party_settings[$module] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -109,7 +109,7 @@ abstract class ConfigEntityBundleBase extends ConfigEntityBase {
|
|||
$storage = $this->entityManager()->getStorage($entity_type_id);
|
||||
return $storage->loadMultiple($ids);
|
||||
}
|
||||
return array();
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -57,7 +57,7 @@ class ConfigEntityDependency {
|
|||
* The list of dependencies of the supplied type.
|
||||
*/
|
||||
public function getDependencies($type) {
|
||||
$dependencies = array();
|
||||
$dependencies = [];
|
||||
if (isset($this->dependencies[$type])) {
|
||||
$dependencies = $this->dependencies[$type];
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ class ConfigEntityListBuilder extends EntityListBuilder {
|
|||
|
||||
// Sort the entities using the entity class's sort() method.
|
||||
// See \Drupal\Core\Config\Entity\ConfigEntityBase::sort().
|
||||
uasort($entities, array($this->entityType->getClass(), 'sort'));
|
||||
uasort($entities, [$this->entityType->getClass(), 'sort']);
|
||||
return $entities;
|
||||
}
|
||||
|
||||
|
@ -34,18 +34,18 @@ class ConfigEntityListBuilder extends EntityListBuilder {
|
|||
|
||||
if ($this->entityType->hasKey('status')) {
|
||||
if (!$entity->status() && $entity->hasLinkTemplate('enable')) {
|
||||
$operations['enable'] = array(
|
||||
$operations['enable'] = [
|
||||
'title' => t('Enable'),
|
||||
'weight' => -10,
|
||||
'url' => $entity->urlInfo('enable'),
|
||||
);
|
||||
];
|
||||
}
|
||||
elseif ($entity->hasLinkTemplate('disable')) {
|
||||
$operations['disable'] = array(
|
||||
$operations['disable'] = [
|
||||
'title' => t('Disable'),
|
||||
'weight' => 40,
|
||||
'url' => $entity->urlInfo('disable'),
|
||||
);
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Reference in a new issue