diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 2b12946..1d05b4a 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -174,7 +174,7 @@ function config_get_config_directory($type = CONFIG_ACTIVE_DIRECTORY) { if (!empty($config_directories[$type])) { return $config_directories[$type]; } - throw new \Exception(format_string('The configuration directory type %type does not exist.', array('%type' => $type))); + throw new \Exception("The configuration directory type '$type' does not exist"); } /** diff --git a/core/lib/Drupal/Component/Utility/UrlHelper.php b/core/lib/Drupal/Component/Utility/UrlHelper.php index 6c87822..2039d83 100644 --- a/core/lib/Drupal/Component/Utility/UrlHelper.php +++ b/core/lib/Drupal/Component/Utility/UrlHelper.php @@ -244,7 +244,7 @@ public static function externalIsLocal($url, $base_url) { $base_parts = parse_url($base_url); if (empty($base_parts['host']) || empty($url_parts['host'])) { - throw new \InvalidArgumentException(SafeMarkup::format('A path was passed when a fully qualified domain was expected.')); + throw new \InvalidArgumentException('A path was passed when a fully qualified domain was expected.'); } if (!isset($url_parts['path']) || !isset($base_parts['path'])) { diff --git a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php index 0099897..0015bf3 100644 --- a/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php +++ b/core/lib/Drupal/Core/Breadcrumb/BreadcrumbManager.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Breadcrumb; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Routing\RouteMatchInterface; @@ -95,7 +94,7 @@ public function build(RouteMatchInterface $route_match) { break; } else { - throw new \UnexpectedValueException(SafeMarkup::format('Invalid breadcrumb returned by !class::build().', array('!class' => get_class($builder)))); + throw new \UnexpectedValueException('Invalid breadcrumb returned by ' . get_class($builder) . '::build().'); } } // Allow modules to alter the breadcrumb. diff --git a/core/lib/Drupal/Core/Config/ConfigBase.php b/core/lib/Drupal/Core/Config/ConfigBase.php index 1ffe7c0..6fbdd29 100644 --- a/core/lib/Drupal/Core/Config/ConfigBase.php +++ b/core/lib/Drupal/Core/Config/ConfigBase.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Config; use Drupal\Component\Utility\NestedArray; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\RefinableCacheableDependencyInterface; use Drupal\Core\Cache\RefinableCacheableDependencyTrait; @@ -99,24 +98,17 @@ public function setName($name) { public static function validateName($name) { // The name must be namespaced by owner. if (strpos($name, '.') === FALSE) { - throw new ConfigNameException(SafeMarkup::format('Missing namespace in Config object name @name.', array( - '@name' => $name, - ))); + throw new ConfigNameException("Missing namespace in Config object name $name."); } // The name must be shorter than Config::MAX_NAME_LENGTH characters. if (strlen($name) > self::MAX_NAME_LENGTH) { - throw new ConfigNameException(SafeMarkup::format('Config object name @name exceeds maximum allowed length of @length characters.', array( - '@name' => $name, - '@length' => self::MAX_NAME_LENGTH, - ))); + throw new ConfigNameException("Config object name $name exceeds maximum allowed length of " . static::MAX_NAME_LENGTH . " characters."); } // The name must not contain any of the following characters: // : ? * < > " ' / \ if (preg_match('/[:?*<>"\'\/\\\\]/', $name)) { - throw new ConfigNameException(SafeMarkup::format('Invalid character in Config object name @name.', array( - '@name' => $name, - ))); + throw new ConfigNameException("Invalid character in Config object name $name."); } } @@ -224,7 +216,7 @@ public function set($key, $value) { protected function validateKeys(array $data) { foreach ($data as $key => $value) { if (strpos($key, '.') !== FALSE) { - throw new ConfigValueException(SafeMarkup::format('@key key contains a dot which is not supported.', array('@key' => $key))); + throw new ConfigValueException("$key key contains a dot which is not supported."); } if (is_array($value)) { $this->validateKeys($value); diff --git a/core/lib/Drupal/Core/Config/ConfigImporter.php b/core/lib/Drupal/Core/Config/ConfigImporter.php index ed50735..e0d4e0d 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporter.php +++ b/core/lib/Drupal/Core/Config/ConfigImporter.php @@ -11,7 +11,6 @@ use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Extension\ModuleInstallerInterface; use Drupal\Core\Extension\ThemeHandlerInterface; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Config\Entity\ImportableEntityStorageInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Entity\EntityStorageException; @@ -763,7 +762,7 @@ protected function processConfiguration($collection, $op, $name) { } } 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', array('@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); @@ -972,7 +971,7 @@ protected function importInvokeOwner($collection, $op, $name) { // Call to the configuration entity's storage to handle the configuration // change. if (!($entity_storage instanceof ImportableEntityStorageInterface)) { - throw new EntityStorageException(SafeMarkup::format('The entity storage "@storage" for the "@entity_type" entity type does not support imports', array('@storage' => get_class($entity_storage), '@entity_type' => $entity_type))); + throw new EntityStorageException(sprintf('The entity storage "%s" for the "%s" entity type does not support imports', get_class($entity_storage), $entity_type)); } $entity_storage->$method($name, $new_config, $old_config); $this->setProcessedConfiguration($collection, $op, $name); @@ -1018,7 +1017,7 @@ protected function importInvokeRename($collection, $rename_name) { // Call to the configuration entity's storage to handle the configuration // change. if (!($entity_storage instanceof ImportableEntityStorageInterface)) { - throw new EntityStorageException(SafeMarkup::format('The entity storage "@storage" for the "@entity_type" entity type does not support imports', array('@storage' => get_class($entity_storage), '@entity_type' => $entity_type_id))); + throw new EntityStorageException(sprintf("The entity storage '%s' for the '%s' entity type does not support imports", get_class($entity_storage), $entity_type_id)); } $entity_storage->importRename($names['old_name'], $new_config, $old_config); $this->setProcessedConfiguration($collection, 'rename', $rename_name); diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php index db08412..5b4688f 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Config\Entity; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\ConfigException; use Drupal\Core\Config\Schema\SchemaIncompleteException; @@ -278,7 +277,7 @@ public function toArray() { $config_name = $entity_type->getConfigPrefix() . '.' . $this->id(); $definition = $this->getTypedConfig()->getDefinition($config_name); if (!isset($definition['mapping'])) { - throw new SchemaIncompleteException(SafeMarkup::format('Incomplete or missing schema for @config_name', array('@config_name' => $config_name))); + throw new SchemaIncompleteException("Incomplete or missing schema for $config_name"); } $properties_to_export = array_combine(array_keys($definition['mapping']), array_keys($definition['mapping'])); } @@ -331,7 +330,7 @@ public function preSave(EntityStorageInterface $storage) { ->execute(); $matched_entity = reset($matching_entities); if (!empty($matched_entity) && ($matched_entity != $this->id()) && $matched_entity != $this->getOriginalId()) { - throw new ConfigDuplicateUUIDException(SafeMarkup::format('Attempt to save a configuration entity %id with UUID %uuid when this UUID is already used for %matched', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%matched' => $matched_entity))); + throw new ConfigDuplicateUUIDException("Attempt to save a configuration entity '{$this->id()}' with UUID '{$this->uuid()}' when this UUID is already used for '$matched_entity'"); } // If this entity is not new, load the original entity for comparison. @@ -339,7 +338,7 @@ public function preSave(EntityStorageInterface $storage) { $original = $storage->loadUnchanged($this->getOriginalId()); // Ensure that the UUID cannot be changed for an existing entity. if ($original && ($original->uuid() != $this->uuid())) { - throw new ConfigDuplicateUUIDException(SafeMarkup::format('Attempt to save a configuration entity %id with UUID %uuid when this entity already exists with UUID %original_uuid', array('%id' => $this->id(), '%uuid' => $this->uuid(), '%original_uuid' => $original->uuid()))); + throw new ConfigDuplicateUUIDException("Attempt to save a configuration entity '{$this->id()}' with UUID '{$this->uuid()}' when this entity already exists with UUID '{$original->uuid()}'"); } } if (!$this->isSyncing() && !$this->trustedData) { diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php index 8e3ccf8..4912dc6 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Config\Entity; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Config\ConfigImporterException; @@ -259,10 +258,7 @@ public function save(EntityInterface $entity) { // @todo Consider moving this to a protected method on the parent class, and // abstracting it for all entity types. if (strlen($entity->get($this->idKey)) > self::MAX_ID_LENGTH) { - throw new ConfigEntityIdLengthException(SafeMarkup::format('Configuration entity ID @id exceeds maximum allowed length of @length characters.', array( - '@id' => $entity->get($this->idKey), - '@length' => self::MAX_ID_LENGTH, - ))); + throw new ConfigEntityIdLengthException("Configuration entity ID {$entity->get($this->idKey)} exceeds maximum allowed length of " . self::MAX_ID_LENGTH . " characters."); } return parent::save($entity); @@ -404,7 +400,7 @@ public function importUpdate($name, Config $new_config, Config $old_config) { $id = static::getIDFromConfigName($name, $this->entityType->getConfigPrefix()); $entity = $this->load($id); if (!$entity) { - throw new ConfigImporterException(SafeMarkup::format('Attempt to update non-existing entity "@id".', array('@id' => $id))); + throw new ConfigImporterException("Attempt to update non-existing entity '$id'."); } $entity->setSyncing(TRUE); $entity = $this->updateFromStorageRecord($entity, $new_config->get()); diff --git a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php index 33cefbd..ab94c27 100644 --- a/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php +++ b/core/lib/Drupal/Core/Config/Entity/ConfigEntityType.php @@ -10,7 +10,6 @@ use Drupal\Core\Config\Entity\Exception\ConfigEntityStorageClassException; use Drupal\Core\Entity\EntityType; use Drupal\Core\Config\ConfigPrefixLengthException; -use Drupal\Component\Utility\SafeMarkup; /** * Provides an implementation of a configuration entity type and its metadata. @@ -93,10 +92,7 @@ public function getConfigPrefix() { } if (strlen($config_prefix) > static::PREFIX_LENGTH) { - throw new ConfigPrefixLengthException(SafeMarkup::format('The configuration file name prefix @config_prefix exceeds the maximum character limit of @max_char.', array( - '@config_prefix' => $config_prefix, - '@max_char' => static::PREFIX_LENGTH, - ))); + throw new ConfigPrefixLengthException("The configuration file name prefix $config_prefix exceeds the maximum character limit of " . static::PREFIX_LENGTH); } return $config_prefix; } @@ -158,7 +154,7 @@ public function setStorageClass($class) { */ protected function checkStorageClass($class) { if (!is_a($class, 'Drupal\Core\Config\Entity\ConfigEntityStorage', TRUE)) { - throw new ConfigEntityStorageClassException(SafeMarkup::format('@class is not \Drupal\Core\Config\Entity\ConfigEntityStorage or it does not extend it', ['@class' => $class])); + throw new ConfigEntityStorageClassException("$class is not \\Drupal\\Core\\Config\\Entity\\ConfigEntityStorage or it does not extend it"); } } diff --git a/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php index ec199e7..0f5b45a 100644 --- a/core/lib/Drupal/Core/Config/FileStorage.php +++ b/core/lib/Drupal/Core/Config/FileStorage.php @@ -9,7 +9,6 @@ use Drupal\Component\Serialization\Yaml; use Drupal\Component\Serialization\Exception\InvalidDataTypeException; -use Drupal\Component\Utility\SafeMarkup; /** * Defines the file storage. @@ -101,10 +100,7 @@ public function read($name) { $data = $this->decode($data); } catch (InvalidDataTypeException $e) { - throw new UnsupportedDataTypeConfigException(SafeMarkup::format('Invalid data type in config @name: !message', array( - '@name' => $name, - '!message' => $e->getMessage(), - ))); + throw new UnsupportedDataTypeConfigException("Invalid data type in config $name: {$e->getMessage()}"); } return $data; } @@ -130,10 +126,7 @@ public function write($name, array $data) { $data = $this->encode($data); } catch (InvalidDataTypeException $e) { - throw new StorageException(SafeMarkup::format('Invalid data type in config @name: !message', array( - '@name' => $name, - '!message' => $e->getMessage(), - ))); + throw new StorageException("Invalid data type in config $name: {$e->getMessage()}"); } $target = $this->getFilePath($name); diff --git a/core/lib/Drupal/Core/Config/ImmutableConfig.php b/core/lib/Drupal/Core/Config/ImmutableConfig.php index 8435f71..511a9c4 100644 --- a/core/lib/Drupal/Core/Config/ImmutableConfig.php +++ b/core/lib/Drupal/Core/Config/ImmutableConfig.php @@ -7,8 +7,6 @@ namespace Drupal\Core\Config; -use Drupal\Component\Utility\SafeMarkup; - /** * Defines the immutable configuration object. * @@ -31,21 +29,21 @@ class ImmutableConfig extends Config { * {@inheritdoc} */ public function set($key, $value) { - throw new ImmutableConfigException(SafeMarkup::format('Can not set values on immutable configuration !name:!key. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object', ['!name' => $this->getName(), '!key' => $key])); + throw new ImmutableConfigException("Can not set values on immutable configuration {$this->getName()}:$key. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object"); } /** * {@inheritdoc} */ public function clear($key) { - throw new ImmutableConfigException(SafeMarkup::format('Can not clear !key key in immutable configuration !name. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object', ['!name' => $this->getName(), '!key' => $key])); + throw new ImmutableConfigException("Can not clear $key key in immutable configuration {$this->getName()}. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object"); } /** * {@inheritdoc} */ public function save($has_trusted_data = FALSE) { - throw new ImmutableConfigException(SafeMarkup::format('Can not save immutable configuration !name. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object', ['!name' => $this->getName()])); + throw new ImmutableConfigException("Can not save immutable configuration {$this->getName()}. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object"); } /** @@ -55,7 +53,7 @@ public function save($has_trusted_data = FALSE) { * The configuration object. */ public function delete() { - throw new ImmutableConfigException(SafeMarkup::format('Can not delete immutable configuration !name. Use \Drupal\Core\Config\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object', ['!name' => $this->getName()])); + throw new ImmutableConfigException("Can not delete immutable configuration {$this->getName()}. Use \\Drupal\\Core\\Config\\ConfigFactoryInterface::getEditable() to retrieve a mutable configuration object"); } } diff --git a/core/lib/Drupal/Core/Config/InstallStorage.php b/core/lib/Drupal/Core/Config/InstallStorage.php index f3a3298..5c1d65a 100644 --- a/core/lib/Drupal/Core/Config/InstallStorage.php +++ b/core/lib/Drupal/Core/Config/InstallStorage.php @@ -91,9 +91,7 @@ public function getFilePath($name) { } // If any code in the early installer requests a configuration object that // does not exist anywhere as default config, then that must be mistake. - throw new StorageException(format_string('Missing configuration file: @name', array( - '@name' => $name, - ))); + throw new StorageException("Missing configuration file: $name"); } /** diff --git a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php index 35e932a..88914c0 100644 --- a/core/lib/Drupal/Core/Config/Schema/ArrayElement.php +++ b/core/lib/Drupal/Core/Config/Schema/ArrayElement.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Config\Schema; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Config\TypedConfigManagerInterface; use Drupal\Core\TypedData\TypedData; @@ -94,7 +93,7 @@ public function get($name) { return $element; } else { - throw new \InvalidArgumentException(SafeMarkup::format("The configuration property @key doesn't exist.", array('@key' => $name))); + throw new \InvalidArgumentException("The configuration property $name doesn't exist."); } } diff --git a/core/lib/Drupal/Core/Config/StorableConfigBase.php b/core/lib/Drupal/Core/Config/StorableConfigBase.php index 92abc28..a0ad7a2 100644 --- a/core/lib/Drupal/Core/Config/StorableConfigBase.php +++ b/core/lib/Drupal/Core/Config/StorableConfigBase.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Config; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Config\Schema\Ignore; use Drupal\Core\TypedData\PrimitiveInterface; use Drupal\Core\TypedData\Type\FloatInterface; @@ -163,10 +162,7 @@ protected function validateValue($key, $value) { } } elseif ($value !== NULL && !is_scalar($value)) { - throw new UnsupportedDataTypeConfigException(SafeMarkup::format('Invalid data type for config element @name:@key', array( - '@name' => $this->getName(), - '@key' => $key, - ))); + throw new UnsupportedDataTypeConfigException("Invalid data type for config element {$this->getName()}:$key"); } } @@ -213,10 +209,7 @@ protected function castValue($key, $value) { else { // Throw exception on any non-scalar or non-array value. if (!is_array($value)) { - throw new UnsupportedDataTypeConfigException(SafeMarkup::format('Invalid data type for config element @name:@key', array( - '@name' => $this->getName(), - '@key' => $key, - ))); + throw new UnsupportedDataTypeConfigException("Invalid data type for config element {$this->getName()}:$key"); } // Recurse into any nested keys. foreach ($value as $nested_value_key => $nested_value) { diff --git a/core/lib/Drupal/Core/Config/StorageComparer.php b/core/lib/Drupal/Core/Config/StorageComparer.php index 2e61f96..a3fa7ee4 100644 --- a/core/lib/Drupal/Core/Config/StorageComparer.php +++ b/core/lib/Drupal/Core/Config/StorageComparer.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Config; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\MemoryBackend; use Drupal\Core\Config\Entity\ConfigDependencyManager; use Drupal\Core\DependencyInjection\DependencySerializationTrait; @@ -196,7 +195,7 @@ protected function addChangeList($collection, $op, array $changes, array $sort_o // ensure the array is keyed from 0. $this->changelist[$collection][$op] = array_values(array_intersect($sort_order, $this->changelist[$collection][$op])); if ($count != count($this->changelist[$collection][$op])) { - throw new \InvalidArgumentException(SafeMarkup::format('Sorting the @op changelist should not change its length.', array('@op' => $op))); + throw new \InvalidArgumentException("Sorting the $op changelist should not change its length."); } } } diff --git a/core/lib/Drupal/Core/Config/Testing/ConfigSchemaChecker.php b/core/lib/Drupal/Core/Config/Testing/ConfigSchemaChecker.php index 5e4fe57..06c836a 100644 --- a/core/lib/Drupal/Core/Config/Testing/ConfigSchemaChecker.php +++ b/core/lib/Drupal/Core/Config/Testing/ConfigSchemaChecker.php @@ -88,14 +88,14 @@ public function onConfigSave(ConfigCrudEvent $event) { $this->checked[$name . ':' . $checksum] = TRUE; $errors = $this->checkConfigSchema($this->typedManager, $name, $data); if ($errors === FALSE) { - throw new SchemaIncompleteException(SafeMarkup::format('No schema for @config_name', array('@config_name' => $name))); + throw new SchemaIncompleteException("No schema for $name"); } elseif (is_array($errors)) { $text_errors = []; foreach ($errors as $key => $error) { $text_errors[] = SafeMarkup::format('@key @error', array('@key' => $key, '@error' => $error)); } - throw new SchemaIncompleteException(SafeMarkup::format('Schema errors for @config_name with the following errors: @errors', array('@config_name' => $name, '@errors' => implode(', ', $text_errors)))); + throw new SchemaIncompleteException("Schema errors for $name with the following errors: " . implode(', ', $text_errors)); } } } diff --git a/core/lib/Drupal/Core/Config/TypedConfigManager.php b/core/lib/Drupal/Core/Config/TypedConfigManager.php index 6bd33cc..500fc3c 100644 --- a/core/lib/Drupal/Core/Config/TypedConfigManager.php +++ b/core/lib/Drupal/Core/Config/TypedConfigManager.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Config; use Drupal\Component\Utility\NestedArray; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\Schema\ArrayElement; use Drupal\Core\Config\Schema\ConfigSchemaAlterException; @@ -324,18 +323,18 @@ protected function alterDefinitions(&$definitions) { parent::alterDefinitions($definitions); $altered_schema = array_keys($definitions); if ($discovered_schema != $altered_schema) { - $added_keys = array_diff($altered_schema, $discovered_schema); - $removed_keys = array_diff($discovered_schema, $altered_schema); + $added_keys = implode(',', array_diff($altered_schema, $discovered_schema)); + $removed_keys = implode(',', array_diff($discovered_schema, $altered_schema)); if (!empty($added_keys) && !empty($removed_keys)) { - $message = 'Invoking hook_config_schema_info_alter() has added (@added) and removed (@removed) schema definitions'; + $message = "Invoking hook_config_schema_info_alter() has added ($added_keys) and removed ($removed_keys) schema definitions"; } elseif (!empty($added_keys)) { - $message = 'Invoking hook_config_schema_info_alter() has added (@added) schema definitions'; + $message = "Invoking hook_config_schema_info_alter() has added ($added_keys) schema definitions"; } else { - $message = 'Invoking hook_config_schema_info_alter() has removed (@removed) schema definitions'; + $message = "Invoking hook_config_schema_info_alter() has removed ($removed_keys) schema definitions"; } - throw new ConfigSchemaAlterException(SafeMarkup::format($message, ['@added' => implode(',', $added_keys), '@removed' => implode(',', $removed_keys)])); + throw new ConfigSchemaAlterException($message); } } diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php index 27d130f..491311d 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php @@ -263,7 +263,7 @@ public function postCreate(EntityStorageInterface $storage) { */ public function setNewRevision($value = TRUE) { if (!$this->getEntityType()->hasKey('revision')) { - throw new \LogicException(SafeMarkup::format('Entity type @entity_type does not support revisions.', ['@entity_type' => $this->getEntityTypeId()])); + throw new \LogicException("Entity type {$this->getEntityTypeId()} does not support revisions."); } if ($value && !$this->newRevision) { @@ -464,15 +464,14 @@ public function get($field_name) { */ protected function getTranslatedField($name, $langcode) { if ($this->translations[$this->activeLangcode]['status'] == static::TRANSLATION_REMOVED) { - $message = 'The entity object refers to a removed translation (@langcode) and cannot be manipulated.'; - throw new \InvalidArgumentException(SafeMarkup::format($message, array('@langcode' => $this->activeLangcode))); + throw new \InvalidArgumentException("The entity object refers to a removed translation ({$this->activeLangcode}) and cannot be manipulated."); } // Populate $this->fields to speed-up further look-ups and to keep track of // fields objects, possibly holding changes to field values. if (!isset($this->fields[$name][$langcode])) { $definition = $this->getFieldDefinition($name); if (!$definition) { - throw new \InvalidArgumentException('Field ' . SafeMarkup::checkPlain($name) . ' is unknown.'); + throw new \InvalidArgumentException("Field $name is unknown."); } // Non-translatable fields are always stored with // LanguageInterface::LANGCODE_DEFAULT as key. @@ -757,8 +756,7 @@ public function getTranslation($langcode) { } if (empty($translation)) { - $message = 'Invalid translation language (@langcode) specified.'; - throw new \InvalidArgumentException(SafeMarkup::format($message, array('@langcode' => $langcode))); + throw new \InvalidArgumentException("Invalid translation language ($langcode) specified."); } return $translation; @@ -825,8 +823,7 @@ public function hasTranslation($langcode) { public function addTranslation($langcode, array $values = array()) { $this->getLanguages(); if (!isset($this->languages[$langcode]) || $this->hasTranslation($langcode)) { - $message = 'Invalid translation language (@langcode) specified.'; - throw new \InvalidArgumentException(SafeMarkup::format($message, array('@langcode' => $langcode))); + throw new \InvalidArgumentException("Invalid translation language ($langcode) specified."); } // Instantiate a new empty entity so default values will be populated in the @@ -876,8 +873,7 @@ public function removeTranslation($langcode) { $this->translations[$langcode]['status'] = static::TRANSLATION_REMOVED; } else { - $message = 'The specified translation (@langcode) cannot be removed.'; - throw new \InvalidArgumentException(SafeMarkup::format($message, array('@langcode' => $langcode))); + throw new \InvalidArgumentException("The specified translation ($langcode) cannot be removed."); } } @@ -1010,8 +1006,7 @@ public function __unset($name) { */ public function createDuplicate() { if ($this->translations[$this->activeLangcode]['status'] == static::TRANSLATION_REMOVED) { - $message = 'The entity object refers to a removed translation (@langcode) and cannot be manipulated.'; - throw new \InvalidArgumentException(SafeMarkup::format($message, array('@langcode' => $this->activeLangcode))); + throw new \InvalidArgumentException("The entity object refers to a removed translation ({$this->activeLangcode}) and cannot be manipulated."); } $duplicate = clone $this; diff --git a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php index 9240827..6e6a74f 100644 --- a/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Entity; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Field\FieldDefinitionInterface; @@ -83,7 +82,7 @@ protected function doCreate(array $values) { $bundle = FALSE; if ($this->bundleKey) { if (!isset($values[$this->bundleKey])) { - throw new EntityStorageException(SafeMarkup::format('Missing bundle for entity type @type', array('@type' => $this->entityTypeId))); + throw new EntityStorageException('Missing bundle for entity type ' . $this->entityTypeId); } $bundle = $values[$this->bundleKey]; } diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 8d5e9e3..4863121 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -195,10 +195,7 @@ public function urlInfo($rel = 'canonical', array $options = []) { $uri = call_user_func($uri_callback, $this); } else { - throw new UndefinedLinkTemplateException(SafeMarkup::format('No link template "@rel" found for the "@entity_type" entity type', array( - '@rel' => $rel, - '@entity_type' => $this->getEntityTypeId(), - ))); + throw new UndefinedLinkTemplateException("No link template '$rel' found for the '{$this->getEntityTypeId()}' entity type"); } } @@ -384,12 +381,7 @@ public function preSave(EntityStorageInterface $storage) { if ($this->getEntityType()->getBundleOf()) { // Throw an exception if the bundle ID is longer than 32 characters. if (Unicode::strlen($this->id()) > EntityTypeInterface::BUNDLE_MAX_LENGTH) { - throw new ConfigEntityIdLengthException(SafeMarkup::format( - 'Attempt to create a bundle with an ID longer than @max characters: @id.', array( - '@max' => EntityTypeInterface::BUNDLE_MAX_LENGTH, - '@id' => $this->id(), - ) - )); + throw new ConfigEntityIdLengthException("Attempt to create a bundle with an ID longer than " . EntityTypeInterface::BUNDLE_MAX_LENGTH . " characters: $this->id()."); } } } diff --git a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php index d5cda65..3a59e01 100644 --- a/core/lib/Drupal/Core/Entity/EntityDisplayBase.php +++ b/core/lib/Drupal/Core/Entity/EntityDisplayBase.php @@ -11,7 +11,6 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Entity\Display\EntityDisplayInterface; -use Drupal\Component\Utility\SafeMarkup; /** * Provides a common base class for entity view and form displays. @@ -262,7 +261,7 @@ public function calculateDependencies() { // If the target entity type uses entities to manage its bundles then // depend on the bundle entity. if (!$bundle_entity = $this->entityManager()->getStorage($bundle_entity_type_id)->load($this->bundle)) { - throw new \LogicException(SafeMarkup::format('Missing bundle entity, entity type %type, entity id %bundle.', array('%type' => $bundle_entity_type_id, '%bundle' => $this->bundle))); + throw new \LogicException("Missing bundle entity, entity type $bundle_entity_type_id, entity id {$this->bundle}."); } $this->addDependency('config', $bundle_entity->getConfigDependencyName()); } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 2d03dff..ad0002e 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -9,7 +9,6 @@ use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\Entity\ConfigEntityType; @@ -425,7 +424,7 @@ protected function buildBaseFieldDefinitions($entity_type_id) { // Fail with an exception for non-fieldable entity types. if (!$entity_type->isSubclassOf('\Drupal\Core\Entity\FieldableEntityInterface')) { - throw new \LogicException(SafeMarkup::format('Getting the base fields is not supported for entity type @type.', array('@type' => $entity_type->getLabel()))); + throw new \LogicException("Getting the base fields is not supported for entity type {$entity_type->getLabel()}."); } // Retrieve base field definitions. @@ -493,28 +492,19 @@ protected function buildBaseFieldDefinitions($entity_type_id) { // translatable values. foreach (array_intersect_key($keys, array_flip(['id', 'revision', 'uuid', 'bundle'])) as $key => $field_name) { if (!isset($base_field_definitions[$field_name])) { - throw new \LogicException(SafeMarkup::format('The @field field definition does not exist and it is used as @key entity key.', array( - '@field' => $field_name, - '@key' => $key, - ))); + throw new \LogicException("The $field_name field definition does not exist and it is used as $key entity key."); } if ($base_field_definitions[$field_name]->isRevisionable()) { - throw new \LogicException(SafeMarkup::format('The @field field cannot be revisionable as it is used as @key entity key.', array( - '@field' => $base_field_definitions[$field_name]->getLabel(), - '@key' => $key, - ))); + throw new \LogicException("The {$base_field_definitions[$field_name]->getLabel()} field cannot be revisionable as it is used as $key entity key."); } if ($base_field_definitions[$field_name]->isTranslatable()) { - throw new \LogicException(SafeMarkup::format('The @field field cannot be translatable as it is used as @key entity key.', array( - '@field' => $base_field_definitions[$field_name]->getLabel(), - '@key' => $key, - ))); + throw new \LogicException("The {$base_field_definitions[$field_name]->getLabel()} field cannot be translatable as it is used as $key entity key."); } } // Make sure translatable entity types define the "langcode" field properly. if ($entity_type->isTranslatable() && (!isset($keys['langcode']) || !isset($base_field_definitions[$keys['langcode']]) || !$base_field_definitions[$keys['langcode']]->isTranslatable())) { - throw new \LogicException(SafeMarkup::format('The @entity_type entity type cannot be translatable as it does not define a translatable "langcode" field.', array('@entity_type' => $entity_type->getLabel()))); + throw new \LogicException("The {$entity_type->getLabel()} entity type cannot be translatable as it does not define a translatable \"langcode\" field."); } return $base_field_definitions; diff --git a/core/lib/Drupal/Core/Entity/EntityStorageBase.php b/core/lib/Drupal/Core/Entity/EntityStorageBase.php index 9163c11..f132d89 100644 --- a/core/lib/Drupal/Core/Entity/EntityStorageBase.php +++ b/core/lib/Drupal/Core/Entity/EntityStorageBase.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Entity; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Entity\Query\QueryInterface; /** @@ -422,7 +421,7 @@ protected function doPreSave(EntityInterface $entity) { // A new entity should not already exist. if ($id_exists && $entity->isNew()) { - throw new EntityStorageException(SafeMarkup::format('@type entity with ID @id already exists.', array('@type' => $this->entityTypeId, '@id' => $id))); + throw new EntityStorageException("'{$this->entityTypeId}' entity with ID '$id' already exists."); } // Load the original entity, if any. diff --git a/core/lib/Drupal/Core/Entity/EntityType.php b/core/lib/Drupal/Core/Entity/EntityType.php index e121d75..31c7923 100644 --- a/core/lib/Drupal/Core/Entity/EntityType.php +++ b/core/lib/Drupal/Core/Entity/EntityType.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Entity; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; use Drupal\Core\Entity\Exception\EntityTypeIdLengthException; use Drupal\Core\StringTranslation\StringTranslationTrait; @@ -245,12 +244,7 @@ class EntityType implements EntityTypeInterface { public function __construct($definition) { // Throw an exception if the entity type ID is longer than 32 characters. if (Unicode::strlen($definition['id']) > static::ID_MAX_LENGTH) { - throw new EntityTypeIdLengthException(SafeMarkup::format( - 'Attempt to create an entity type with an ID longer than @max characters: @id.', array( - '@max' => static::ID_MAX_LENGTH, - '@id' => $definition['id'], - ) - )); + throw new EntityTypeIdLengthException('Attempt to create an entity type with an ID longer than ' . static::ID_MAX_LENGTH . " characters: {$definition['id']}."); } foreach ($definition as $property => $value) { diff --git a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php index 5d8ac59..5bb1049 100644 --- a/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/KeyValueStore/KeyValueEntityStorage.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Entity\KeyValueStore; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Uuid\UuidInterface; use Drupal\Core\Config\Entity\Exception\ConfigEntityIdLengthException; use Drupal\Core\Entity\FieldableEntityInterface; @@ -167,10 +166,7 @@ public function save(EntityInterface $entity) { // @todo This is not config-specific, but serial IDs will likely never hit // this limit. Consider renaming the exception class. if (strlen($entity->id()) > static::MAX_ID_LENGTH) { - throw new ConfigEntityIdLengthException(SafeMarkup::format('Entity ID @id exceeds maximum allowed length of @length characters.', array( - '@id' => $entity->id(), - '@length' => static::MAX_ID_LENGTH, - ))); + throw new ConfigEntityIdLengthException("Entity ID {$entity->id()} exceeds maximum allowed length of " . static::MAX_ID_LENGTH . ' characters.'); } return parent::save($entity); } diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php index 1a64c40..054d101 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/EntityAdapter.php @@ -81,12 +81,12 @@ public function setValue($entity, $notify = TRUE) { */ public function get($property_name) { if (!isset($this->entity)) { - throw new MissingDataException(SafeMarkup::format('Unable to get property @name as no entity has been provided.', array('@name' => $property_name))); + throw new MissingDataException("Unable to get property $property_name as no entity has been provided."); } if (!$this->entity instanceof FieldableEntityInterface) { // @todo: Add support for config entities in // https://www.drupal.org/node/1818574. - throw new \InvalidArgumentException(SafeMarkup::format('Unable to get unknown property @name.', array('@name' => $property_name))); + throw new \InvalidArgumentException("Unable to get unknown property $property_name."); } // This will throw an exception for unknown fields. return $this->entity->get($property_name); @@ -97,12 +97,12 @@ public function get($property_name) { */ public function set($property_name, $value, $notify = TRUE) { if (!isset($this->entity)) { - throw new MissingDataException(SafeMarkup::format('Unable to set property @name as no entity has been provided.', array('@name' => $property_name))); + throw new MissingDataException("Unable to set property $property_name as no entity has been provided."); } if (!$this->entity instanceof FieldableEntityInterface) { // @todo: Add support for config entities in // https://www.drupal.org/node/1818574. - throw new \InvalidArgumentException(SafeMarkup::format('Unable to set unknown property @name.', array('@name' => $property_name))); + throw new \InvalidArgumentException("Unable to set unknown property $property_name."); } // This will throw an exception for unknown fields. $this->entity->set($property_name, $value, $notify); @@ -129,7 +129,7 @@ public function getProperties($include_computed = FALSE) { */ public function toArray() { if (!isset($this->entity)) { - throw new MissingDataException(SafeMarkup::format('Unable to get property values as no entity has been provided.')); + throw new MissingDataException('Unable to get property values as no entity has been provided.'); } return $this->entity->toArray(); } diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php index 98f4f84..e1a976a 100644 --- a/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Tables.php @@ -215,7 +215,7 @@ public function addField($field, $type, $langcode) { $index_prefix .= "$next_index_prefix."; } else { - throw new QueryException(format_string('Invalid specifier @next.', array('@next' => $relationship_specifier))); + throw new QueryException("Invalid specifier '$relationship_specifier'"); } } } @@ -247,7 +247,7 @@ protected function ensureEntityTable($index_prefix, $property, $type, $langcode, return $this->entityTables[$index_prefix . $table]; } } - throw new QueryException(format_string('@property not found', array('@property' => $property))); + throw new QueryException("'$property' not found"); } /** diff --git a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php index ac12621..b701279 100644 --- a/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php +++ b/core/lib/Drupal/Core/Entity/Sql/DefaultTableMapping.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Entity\Sql; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Entity\ContentEntityTypeInterface; use Drupal\Core\Field\FieldStorageDefinitionInterface; @@ -178,7 +177,7 @@ public function getFieldTableName($field_name) { } if (!isset($result)) { - throw new SqlContentEntityStorageException(SafeMarkup::format('Table information not available for the "@field_name" field.', array('@field_name' => $field_name))); + throw new SqlContentEntityStorageException("Table information not available for the '$field_name' field."); } return $result; @@ -211,7 +210,7 @@ public function getFieldColumnName(FieldStorageDefinitionInterface $storage_defi $column_name = !in_array($property_name, $this->getReservedColumns()) ? $field_name . '_' . $property_name : $property_name; } else { - throw new SqlContentEntityStorageException(SafeMarkup::format('Column information not available for the "@field_name" field.', array('@field_name' => $field_name))); + throw new SqlContentEntityStorageException("Column information not available for the '$field_name' field."); } return $column_name; diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 28a5afa..689655a 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Entity\Sql; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Database\Connection; use Drupal\Core\Database\Database; @@ -266,7 +265,7 @@ public function setEntityType(EntityTypeInterface $entity_type) { $this->initTableLayout(); } else { - throw new EntityStorageException(SafeMarkup::format('Unsupported entity type @id', array('@id' => $entity_type->id()))); + throw new EntityStorageException("Unsupported entity type {$entity_type->id()}"); } } @@ -924,7 +923,7 @@ protected function mapToStorageRecord(ContentEntityInterface $entity, $table_nam foreach ($table_mapping->getFieldNames($table_name) as $field_name) { if (empty($this->getFieldStorageDefinitions()[$field_name])) { - throw new EntityStorageException(SafeMarkup::format('Table mapping contains invalid field %field.', array('%field' => $field_name))); + throw new EntityStorageException("Table mapping contains invalid field $field_name."); } $definition = $this->getFieldStorageDefinitions()[$field_name]; $columns = $table_mapping->getColumnNames($field_name); diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php index 24f4650..8a96e51 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorageSchema.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Entity\Sql; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Database\Connection; use Drupal\Core\Database\DatabaseException; use Drupal\Core\Entity\ContentEntityTypeInterface; @@ -286,7 +285,7 @@ public function onEntityTypeUpdate(EntityTypeInterface $entity_type, EntityTypeI // If a migration is required, we can't proceed. if ($this->requiresEntityDataMigration($entity_type, $original)) { - throw new EntityStorageException(SafeMarkup::format('The SQL storage cannot change the schema for an existing entity type with data.')); + throw new EntityStorageException('The SQL storage cannot change the schema for an existing entity type with data.'); } // If we have no data just recreate the entity schema from scratch. @@ -467,7 +466,7 @@ public function finalizePurge(FieldStorageDefinitionInterface $storage_definitio */ protected function checkEntityType(EntityTypeInterface $entity_type) { if ($entity_type->id() != $this->entityType->id()) { - throw new EntityStorageException(SafeMarkup::format('Unsupported entity type @id', array('@id' => $entity_type->id()))); + throw new EntityStorageException("Unsupported entity type {$entity_type->id()}"); } return TRUE; } @@ -530,7 +529,7 @@ protected function getEntitySchema(ContentEntityTypeInterface $entity_type, $res } foreach ($table_mapping->getFieldNames($table_name) as $field_name) { if (!isset($storage_definitions[$field_name])) { - throw new FieldException(SafeMarkup::format('Field storage definition for "@field_name" could not be found.', array('@field_name' => $field_name))); + throw new FieldException("Field storage definition for '$field_name' could not be found."); } // Add the schema for base field definitions. elseif ($table_mapping->allowsSharedTableStorage($storage_definitions[$field_name])) { @@ -1430,7 +1429,7 @@ protected function getSharedTableFieldSchema(FieldStorageDefinitionInterface $st // Check that the schema does not include forbidden column names. if (array_intersect(array_keys($field_schema['columns']), $this->storage->getTableMapping()->getReservedColumns())) { - throw new FieldException(format_string('Illegal field column names on @field_name', array('@field_name' => $storage_definition->getName()))); + throw new FieldException("Illegal field column names on {$storage_definition->getName()}"); } $field_name = $storage_definition->getName(); @@ -1652,7 +1651,7 @@ protected function getDedicatedTableSchema(FieldStorageDefinitionInterface $stor $properties = $storage_definition->getPropertyDefinitions(); $table_mapping = $this->storage->getTableMapping(); if (array_intersect(array_keys($schema['columns']), $table_mapping->getReservedColumns())) { - throw new FieldException(format_string('Illegal field column names on @field_name', array('@field_name' => $storage_definition->getName()))); + throw new FieldException("Illegal field column names on {$storage_definition->getName()}"); } // Add field columns. diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index ce5af4f..f97897c 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -9,7 +9,6 @@ use Drupal\Component\Graph\Graph; use Drupal\Component\Utility\NestedArray; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; @@ -581,7 +580,7 @@ protected function buildImplementationInfo($hook) { } // If a new implementation was added, verify that the function exists. if (!function_exists($module . '_' . $hook)) { - throw new \RuntimeException(SafeMarkup::format('An invalid implementation @function was added by hook_module_implements_alter()', array('@function' => $module . '_' . $hook))); + throw new \RuntimeException("An invalid implementation {$module}_{$hook} was added by hook_module_implements_alter()"); } } } diff --git a/core/lib/Drupal/Core/Extension/ModuleInstaller.php b/core/lib/Drupal/Core/Extension/ModuleInstaller.php index 56902a7..41e698c 100644 --- a/core/lib/Drupal/Core/Extension/ModuleInstaller.php +++ b/core/lib/Drupal/Core/Extension/ModuleInstaller.php @@ -13,7 +13,6 @@ use Drupal\Core\Config\PreExistingConfigException; use Drupal\Core\Config\StorageInterface; use Drupal\Core\DrupalKernelInterface; -use Drupal\Component\Utility\SafeMarkup; /** * Default implementation of the module installer. @@ -88,10 +87,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { $module_list = $module_list ? array_combine($module_list, $module_list) : array(); if ($missing_modules = array_diff_key($module_list, $module_data)) { // One or more of the given modules doesn't exist. - throw new MissingDependencyException(SafeMarkup::format('Unable to install modules %modules due to missing modules %missing.', array( - '%modules' => implode(', ', $module_list), - '%missing' => implode(', ', $missing_modules), - ))); + throw new MissingDependencyException(sprintf('Unable to install modules %s due to missing modules %s.', implode(', ', $module_list), implode(', ', $missing_modules))); } // Only process currently uninstalled modules. @@ -107,10 +103,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { foreach (array_keys($module_data[$module]->requires) as $dependency) { if (!isset($module_data[$dependency])) { // The dependency does not exist. - throw new MissingDependencyException(SafeMarkup::format('Unable to install modules: module %module is missing its dependency module %dependency.', array( - '%module' => $module, - '%dependency' => $dependency, - ))); + throw new MissingDependencyException("Unable to install modules: module '$module' is missing its dependency module $dependency."); } // Skip already installed modules. @@ -145,10 +138,7 @@ public function install(array $module_list, $enable_dependencies = TRUE) { if (!$enabled) { // Throw an exception if the module name is too long. if (strlen($module) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) { - throw new ExtensionNameLengthException(format_string('Module name %name is over the maximum allowed length of @max characters.', array( - '%name' => $module, - '@max' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, - ))); + throw new ExtensionNameLengthException("Module name '$module' is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters'); } // Check the validity of the default configuration. This will throw @@ -329,9 +319,7 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) { foreach ($reasons as $reason) { $reason_message[] = implode(', ', $reason); } - throw new ModuleUninstallValidatorException(format_string('The following reasons prevents the modules from being uninstalled: @reasons', array( - '@reasons' => implode('; ', $reason_message), - ))); + throw new ModuleUninstallValidatorException('The following reasons prevents the modules from being uninstalled: ' . implode('; ', $reason_message)); } // Set the actual module weights. $module_list = array_map(function ($module) use ($module_data) { diff --git a/core/lib/Drupal/Core/Extension/ThemeHandler.php b/core/lib/Drupal/Core/Extension/ThemeHandler.php index 4059d79..2eb56bc 100644 --- a/core/lib/Drupal/Core/Extension/ThemeHandler.php +++ b/core/lib/Drupal/Core/Extension/ThemeHandler.php @@ -429,7 +429,7 @@ protected function getExtensionDiscovery() { public function getName($theme) { $themes = $this->listInfo(); if (!isset($themes[$theme])) { - throw new \InvalidArgumentException(SafeMarkup::format('Requested the name of a non-existing theme @theme', array('@theme' => $theme))); + throw new \InvalidArgumentException("Requested the name of a non-existing theme $theme"); } return SafeMarkup::checkPlain($themes[$theme]->info['name']); } diff --git a/core/lib/Drupal/Core/Extension/ThemeInstaller.php b/core/lib/Drupal/Core/Extension/ThemeInstaller.php index 1bebca2..b3b391e 100644 --- a/core/lib/Drupal/Core/Extension/ThemeInstaller.php +++ b/core/lib/Drupal/Core/Extension/ThemeInstaller.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Extension; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Asset\AssetCollectionOptimizerInterface; use Drupal\Core\Cache\Cache; use Drupal\Core\Config\ConfigFactoryInterface; @@ -113,9 +112,7 @@ public function install(array $theme_list, $install_dependencies = TRUE) { if ($missing = array_diff_key($theme_list, $theme_data)) { // One or more of the given themes doesn't exist. - throw new \InvalidArgumentException(SafeMarkup::format('Unknown themes: !themes.', array( - '!themes' => implode(', ', $missing), - ))); + throw new \InvalidArgumentException('Unknown themes: ' . implode(', ', $missing) . '.'); } // Only process themes that are not installed currently. @@ -164,10 +161,7 @@ public function install(array $theme_list, $install_dependencies = TRUE) { // Throw an exception if the theme name is too long. if (strlen($key) > DRUPAL_EXTENSION_NAME_MAX_LENGTH) { - throw new ExtensionNameLengthException(SafeMarkup::format('Theme name %name is over the maximum allowed length of @max characters.', array( - '%name' => $key, - '@max' => DRUPAL_EXTENSION_NAME_MAX_LENGTH, - ))); + throw new ExtensionNameLengthException("Theme name $key is over the maximum allowed length of " . DRUPAL_EXTENSION_NAME_MAX_LENGTH . ' characters.'); } // Validate default configuration of the theme. If there is existing diff --git a/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php b/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php index 32862d1..ecf7665 100644 --- a/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php +++ b/core/lib/Drupal/Core/Field/Entity/BaseFieldOverride.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Field\Entity; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Field\BaseFieldDefinition; use Drupal\Core\Field\FieldConfigBase; @@ -103,10 +102,10 @@ public function __construct(array $values, $entity_type = 'base_field_override') throw new FieldException('Attempt to create a base field bundle override of a field without a field_name'); } if (empty($values['entity_type'])) { - throw new FieldException(SafeMarkup::format('Attempt to create a base field bundle override of field @field_name without an entity_type', array('@field_name' => $values['field_name']))); + throw new FieldException("Attempt to create a base field bundle override of field {$values['field_name']} without an entity_type"); } if (empty($values['bundle'])) { - throw new FieldException(SafeMarkup::format('Attempt to create a base field bundle override of field @field_name without a bundle', array('@field_name' => $values['field_name']))); + throw new FieldException("Attempt to create a base field bundle override of field {$values['field_name']} without a bundle"); } parent::__construct($values, $entity_type); @@ -188,10 +187,10 @@ public function preSave(EntityStorageInterface $storage) { else { // Some updates are always disallowed. if ($this->entity_type != $this->original->entity_type) { - throw new FieldException(SafeMarkup::format('Cannot change the entity_type of an existing base field bundle override (entity type:@entity_type, bundle:@bundle, field name: @field_name)', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type, '@bundle' => $this->original->bundle))); + throw new FieldException("Cannot change the entity_type of an existing base field bundle override (entity type:{$this->entity_type}, bundle:{$this->original->bundle}, field name: {$this->field_name})"); } if ($this->bundle != $this->original->bundle && empty($this->bundleRenameAllowed)) { - throw new FieldException(SafeMarkup::format('Cannot change the bundle of an existing base field bundle override (entity type:@entity_type, bundle:@bundle, field name: @field_name)', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type, '@bundle' => $this->original->bundle))); + throw new FieldException("Cannot change the bundle of an existing base field bundle override (entity type:{$this->entity_type}, bundle:{$this->original->bundle}, field name: {$this->field_name})"); } $previous_definition = $this->original; } diff --git a/core/lib/Drupal/Core/Field/FieldConfigBase.php b/core/lib/Drupal/Core/Field/FieldConfigBase.php index a7790a3..00fc567 100644 --- a/core/lib/Drupal/Core/Field/FieldConfigBase.php +++ b/core/lib/Drupal/Core/Field/FieldConfigBase.php @@ -12,7 +12,6 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Field\TypedData\FieldItemDataDefinition; -use Drupal\Component\Utility\SafeMarkup; /** * Base class for configurable field definitions. @@ -254,7 +253,7 @@ public function calculateDependencies() { $bundle_entity_type_id = $this->entityManager()->getDefinition($this->entity_type)->getBundleEntityType(); if ($bundle_entity_type_id != 'bundle') { if (!$bundle_entity = $this->entityManager()->getStorage($bundle_entity_type_id)->load($this->bundle)) { - throw new \LogicException(SafeMarkup::format('Missing bundle entity, entity type %type, entity id %bundle.', array('%type' => $bundle_entity_type_id, '%bundle' => $this->bundle))); + throw new \LogicException("Missing bundle entity, entity type {$bundle_entity_type_id}, entity id {$this->bundle}."); } $this->addDependency('config', $bundle_entity->getConfigDependencyName()); } diff --git a/core/lib/Drupal/Core/Form/FormBuilder.php b/core/lib/Drupal/Core/Form/FormBuilder.php index a24330d..fe6d104 100644 --- a/core/lib/Drupal/Core/Form/FormBuilder.php +++ b/core/lib/Drupal/Core/Form/FormBuilder.php @@ -10,7 +10,6 @@ use Drupal\Component\Utility\Crypt; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\NestedArray; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Access\AccessResultInterface; use Drupal\Core\Access\CsrfTokenGenerator; @@ -153,7 +152,7 @@ public function getFormId($form_arg, FormStateInterface &$form_state) { } if (!is_object($form_arg) || !($form_arg instanceof FormInterface)) { - throw new \InvalidArgumentException(SafeMarkup::format('The form argument @form_arg is not a valid form.', array('@form_arg' => $form_arg))); + throw new \InvalidArgumentException("The form argument $form_arg is not a valid form."); } // Add the $form_arg as the callback object and determine the form ID. diff --git a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php index 4fd6bdc..9e21c03 100644 --- a/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php +++ b/core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php @@ -8,7 +8,6 @@ namespace Drupal\Core\ImageToolkit; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Plugin\PluginBase; use Psr\Log\LoggerInterface; @@ -114,7 +113,7 @@ protected function prepareArguments(array $arguments) { if ($argument['required']) { if (!array_key_exists($id, $arguments)) { // If the argument is required throw an exception. - throw new \InvalidArgumentException(SafeMarkup::format("Argument '@argument' expected by plugin '@plugin' but not passed", array('@argument' => $id, '@plugin' => $this->getPluginId()))); + throw new \InvalidArgumentException("Argument '$id' expected by plugin '{$this->getPluginId()}' but not passed"); } } else { @@ -124,7 +123,7 @@ protected function prepareArguments(array $arguments) { if (!array_key_exists('default', $argument)) { // The plugin did not define a default, so throw a plugin exception, // not an invalid argument exception. - throw new InvalidPluginDefinitionException(SafeMarkup::format("Default for argument '@argument' expected by plugin '@plugin' but not defined", array('@argument' => $id, '@plugin' => $this->getPluginId()))); + throw new InvalidPluginDefinitionException("Default for argument '$id' expected by plugin '{$this->getPluginId()}' but not defined"); } // Use the default value if the argument is not passed in. diff --git a/core/lib/Drupal/Core/Menu/InaccessibleMenuLink.php b/core/lib/Drupal/Core/Menu/InaccessibleMenuLink.php index 075e356..1dad00d 100644 --- a/core/lib/Drupal/Core/Menu/InaccessibleMenuLink.php +++ b/core/lib/Drupal/Core/Menu/InaccessibleMenuLink.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Menu; use Drupal\Component\Plugin\Exception\PluginException; -use Drupal\Component\Utility\SafeMarkup; /** * A menu link plugin for wrapping another menu link, in sensitive situations. @@ -80,7 +79,7 @@ public function getCacheMaxAge() { * {@inheritdoc} */ public function updateLink(array $new_definition_values, $persist) { - throw new PluginException(SafeMarkup::format('Inaccessible menu link plugins do not support updating')); + throw new PluginException('Inaccessible menu link plugins do not support updating'); } } diff --git a/core/lib/Drupal/Core/Menu/MenuLinkBase.php b/core/lib/Drupal/Core/Menu/MenuLinkBase.php index 70774df..6ecfbdf 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkBase.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkBase.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Menu; use Drupal\Component\Plugin\Exception\PluginException; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\Cache; use Drupal\Core\Plugin\PluginBase; use Drupal\Core\Url; @@ -170,7 +169,7 @@ public function getTranslateRoute() { * {@inheritdoc} */ public function deleteLink() { - throw new PluginException(SafeMarkup::format('Menu link plugin with ID @id does not support deletion', array('@id' => $this->getPluginId()))); + throw new PluginException("Menu link plugin with ID '{$this->getPluginId()}' does not support deletion"); } /** diff --git a/core/lib/Drupal/Core/Menu/MenuLinkManager.php b/core/lib/Drupal/Core/Menu/MenuLinkManager.php index b4c7760..5a18a31 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkManager.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkManager.php @@ -10,7 +10,6 @@ use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Component\Utility\NestedArray; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\Plugin\Discovery\ContainerDerivativeDiscoveryDecorator; use Drupal\Core\Plugin\Discovery\YamlDiscovery; @@ -287,7 +286,7 @@ protected function deleteInstance(MenuLinkInterface $instance, $persist) { } } else { - throw new PluginException(SafeMarkup::format('Menu link plugin with ID @id does not support deletion', array('@id' => $id))); + throw new PluginException("Menu link plugin with ID '$id' does not support deletion"); } $this->treeStorage->delete($id); } @@ -355,7 +354,7 @@ public function loadLinksByRoute($route_name, array $route_parameters = array(), */ public function addDefinition($id, array $definition) { if ($this->treeStorage->load($id) || $id === '') { - throw new PluginException(SafeMarkup::format('The ID @id already exists as a plugin definition or is not valid', array('@id' => $id))); + throw new PluginException("The ID $id already exists as a plugin definition or is not valid"); } // Add defaults, so there is no requirement to specify everything. $this->processDefinition($definition, $id); @@ -402,7 +401,7 @@ protected function resetInstance(MenuLinkInterface $instance) { $id = $instance->getPluginId(); if (!$instance->isResettable()) { - throw new PluginException(SafeMarkup::format('Menu link %id is not resettable', array('%id' => $id))); + throw new PluginException("Menu link $id is not resettable"); } // Get the original data from disk, reset the override and re-save the menu // tree for this link. diff --git a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php index 659d6be..3f2d403 100644 --- a/core/lib/Drupal/Core/Menu/MenuTreeStorage.php +++ b/core/lib/Drupal/Core/Menu/MenuTreeStorage.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Menu; use Drupal\Component\Plugin\Exception\PluginException; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\CacheBackendInterface; @@ -476,7 +475,7 @@ protected function setParents(array &$fields, $parent, array $original) { $limit = $this->maxDepth() - 1; } if ($parent['depth'] > $limit) { - throw new PluginException(SafeMarkup::format('The link with ID @id or its children exceeded the maximum depth of @depth', array('@id' => $fields['id'], '@depth' => $this->maxDepth()))); + throw new PluginException("The link with ID {$fields['id']} or its children exceeded the maximum depth of {$this->maxDepth()}"); } $fields['depth'] = $parent['depth'] + 1; $i = 1; @@ -637,7 +636,7 @@ public function loadByProperties(array $properties) { foreach ($properties as $name => $value) { if (!in_array($name, $this->definitionFields(), TRUE)) { $fields = implode(', ', $this->definitionFields()); - throw new \InvalidArgumentException(SafeMarkup::format('An invalid property name, @name was specified. Allowed property names are: @fields.', array('@name' => $name, '@fields' => $fields))); + throw new \InvalidArgumentException("An invalid property name, $name was specified. Allowed property names are: $fields."); } $query->condition($name, $value); } diff --git a/core/lib/Drupal/Core/Plugin/Context/Context.php b/core/lib/Drupal/Core/Plugin/Context/Context.php index 5a5ab6c..837d601 100644 --- a/core/lib/Drupal/Core/Plugin/Context/Context.php +++ b/core/lib/Drupal/Core/Plugin/Context/Context.php @@ -9,7 +9,6 @@ use Drupal\Component\Plugin\Context\Context as ComponentContext; use Drupal\Component\Plugin\Exception\ContextException; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Cache\CacheableMetadata; use Drupal\Core\TypedData\TypedDataInterface; @@ -66,7 +65,7 @@ public function getContextValue() { } elseif ($definition->isRequired()) { $type = $definition->getDataType(); - throw new ContextException(SafeMarkup::format("The @type context is required and not present.", array('@type' => $type))); + throw new ContextException("The '$type' context is required and not present."); } return $default_value; } diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php b/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php index 34ad362..40fd662 100644 --- a/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php +++ b/core/lib/Drupal/Core/Plugin/Context/ContextDefinition.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Plugin\Context; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\TypedData\TypedDataTrait; /** @@ -245,7 +244,7 @@ public function getDataDefinition() { } if (!$definition) { - throw new \Exception(SafeMarkup::format('The data type "@type" is invalid', array('@type' => $this->getDataType()))); + throw new \Exception("The data type '{$this->getDataType()}' is invalid"); } $definition->setLabel($this->getLabel()) ->setDescription($this->getDescription()) diff --git a/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php index 5e5f126..373c73c 100644 --- a/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php +++ b/core/lib/Drupal/Core/Plugin/Context/ContextHandler.php @@ -8,7 +8,6 @@ namespace Drupal\Core\Plugin\Context; use Drupal\Component\Plugin\Exception\ContextException; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\CacheableDependencyInterface; use Drupal\Core\Plugin\ContextAwarePluginInterface; @@ -119,7 +118,7 @@ public function applyContextMapping(ContextAwarePluginInterface $plugin, $contex // If there are any mappings that were not satisfied, throw an exception. if (!empty($mappings)) { - throw new ContextException(SafeMarkup::format('Assigned contexts were not satisfied: @mappings', ['@mappings' => implode(',', array_keys($mappings))])); + throw new ContextException('Assigned contexts were not satisfied: ' . implode(',', array_keys($mappings))); } } diff --git a/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php b/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php index 4d5189a..a0f0238 100644 --- a/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php +++ b/core/lib/Drupal/Core/Routing/RequestFormatRouteFilter.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Routing; -use Drupal\Component\Utility\SafeMarkup; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; use Symfony\Component\Routing\Route; @@ -51,7 +50,7 @@ public function filter(RouteCollection $collection, Request $request) { // We do not throw a // \Symfony\Component\Routing\Exception\ResourceNotFoundException here // because we don't want to return a 404 status code, but rather a 406. - throw new NotAcceptableHttpException(SafeMarkup::format('No route found for the specified format @format.', ['@format' => $format])); + throw new NotAcceptableHttpException("No route found for the specified format $format."); } } diff --git a/core/lib/Drupal/Core/TypedData/ListDataDefinition.php b/core/lib/Drupal/Core/TypedData/ListDataDefinition.php index b710a75..e0fd530 100644 --- a/core/lib/Drupal/Core/TypedData/ListDataDefinition.php +++ b/core/lib/Drupal/Core/TypedData/ListDataDefinition.php @@ -87,7 +87,7 @@ public function getClass() { $item_type_definition = \Drupal::typedDataManager() ->getDefinition($this->getItemDefinition()->getDataType()); if (!$item_type_definition) { - throw new \LogicException(format_string('An invalid data type @plugin_id has been specified for list items.', array('@plugin_id' => $this->getItemDefinition()->getDataType()))); + throw new \LogicException("An invalid data type '{$this->getItemDefinition()->getDataType()}' has been specified for list items"); } return $item_type_definition['list_class']; } diff --git a/core/lib/Drupal/Core/TypedData/TypedDataManager.php b/core/lib/Drupal/Core/TypedData/TypedDataManager.php index 89fa657..858d13d 100644 --- a/core/lib/Drupal/Core/TypedData/TypedDataManager.php +++ b/core/lib/Drupal/Core/TypedData/TypedDataManager.php @@ -8,7 +8,6 @@ namespace Drupal\Core\TypedData; use Drupal\Component\Plugin\Exception\PluginException; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\DependencyInjection\ClassResolverInterface; use Drupal\Core\DependencyInjection\DependencySerializationTrait; @@ -99,7 +98,7 @@ public function createInstance($data_type, array $configuration = array()) { $type_definition = $this->getDefinition($data_type); if (!isset($type_definition)) { - throw new \InvalidArgumentException(format_string('Invalid data type %plugin_id has been given.', array('%plugin_id' => $data_type))); + throw new \InvalidArgumentException("Invalid data type '$data_type' has been given"); } // Allow per-data definition overrides of the used classes, i.e. take over @@ -179,7 +178,7 @@ public function create(DataDefinitionInterface $definition, $value = NULL, $name public function createDataDefinition($data_type) { $type_definition = $this->getDefinition($data_type); if (!isset($type_definition)) { - throw new \InvalidArgumentException(format_string('Invalid data type %plugin_id has been given.', array('%plugin_id' => $data_type))); + throw new \InvalidArgumentException("Invalid data type '$data_type' has been given"); } $class = $type_definition['definition_class']; return $class::createFromDataType($data_type); @@ -199,7 +198,7 @@ public function createDataDefinition($data_type) { public function createListDataDefinition($item_type) { $type_definition = $this->getDefinition($item_type); if (!isset($type_definition)) { - throw new \InvalidArgumentException(format_string('Invalid data type %plugin_id has been given.', array('%plugin_id' => $item_type))); + throw new \InvalidArgumentException("Invalid data type '$item_type' has been given"); } $class = $type_definition['list_definition_class']; return $class::createFromItemType($item_type); @@ -298,7 +297,7 @@ public function getPropertyInstance(TypedDataInterface $object, $property_name, throw new \InvalidArgumentException("The passed object has to either implement the ComplexDataInterface or the ListInterface."); } if (!$definition) { - throw new \InvalidArgumentException('Property ' . SafeMarkup::checkPlain($property_name) . ' is unknown.'); + throw new \InvalidArgumentException("Property $property_name is unknown."); } // Create the prototype without any value, but with initial parenting // so that constructors can set up the objects correclty. diff --git a/core/lib/Drupal/Core/Url.php b/core/lib/Drupal/Core/Url.php index e349627..5da8ffb8 100644 --- a/core/lib/Drupal/Core/Url.php +++ b/core/lib/Drupal/Core/Url.php @@ -7,7 +7,6 @@ namespace Drupal\Core; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Routing\RouteMatchInterface; @@ -232,7 +231,7 @@ public static function fromUserInput($user_input, $options = []) { // because these are URI reserved characters that a scheme name may not // start with. if ((strpos($user_input, '/') !== 0) && (strpos($user_input, '#') !== 0) && (strpos($user_input, '?') !== 0)) { - throw new \InvalidArgumentException(SafeMarkup::format("The user-entered string @user_input must begin with a '/', '?', or '#'.", ['@user_input' => $user_input])); + throw new \InvalidArgumentException("The user-entered string '$user_input' must begin with a '/', '?', or '#'."); } // fromUri() requires an absolute URI, so prepend the appropriate scheme @@ -296,10 +295,10 @@ public static function fromUserInput($user_input, $options = []) { public static function fromUri($uri, $options = []) { $uri_parts = parse_url($uri); if ($uri_parts === FALSE) { - throw new \InvalidArgumentException(SafeMarkup::format('The URI "@uri" is malformed.', ['@uri' => $uri])); + throw new \InvalidArgumentException("The URI '$uri' is malformed."); } if (empty($uri_parts['scheme'])) { - throw new \InvalidArgumentException(SafeMarkup::format('The URI "@uri" is invalid. You must use a valid URI scheme.', ['@uri' => $uri])); + throw new \InvalidArgumentException("The URI '$uri' is invalid. You must use a valid URI scheme."); } $uri_parts += ['path' => '']; // Discard empty fragment in $options for consistency with parse_url(). @@ -362,7 +361,7 @@ public static function fromUri($uri, $options = []) { protected static function fromEntityUri(array $uri_parts, array $options, $uri) { list($entity_type_id, $entity_id) = explode('/', $uri_parts['path'], 2); if ($uri_parts['scheme'] != 'entity' || $entity_id === '') { - throw new \InvalidArgumentException(SafeMarkup::format('The entity URI "@uri" is invalid. You must specify the entity id in the URL. e.g., entity:node/1 for loading the canonical path to node entity with id 1.', ['@uri' => $uri])); + throw new \InvalidArgumentException("The entity URI '$uri' is invalid. You must specify the entity id in the URL. e.g., entity:node/1 for loading the canonical path to node entity with id 1."); } return new static("entity.$entity_type_id.canonical", [$entity_type_id => $entity_id], $options); @@ -422,13 +421,13 @@ protected static function fromInternalUri(array $uri_parts, array $options) { } else { if ($uri_parts['path'][0] !== '/') { - throw new \InvalidArgumentException(SafeMarkup::format('The internal path component "@path" is invalid. Its path component must have a leading slash, e.g. internal:/foo.', ['@path' => $uri_parts['path']])); + throw new \InvalidArgumentException("The internal path component '{$uri_parts['path']}' is invalid. Its path component must have a leading slash, e.g. internal:/foo."); } // Remove the leading slash. $uri_parts['path'] = substr($uri_parts['path'], 1); if (UrlHelper::isExternal($uri_parts['path'])) { - throw new \InvalidArgumentException(SafeMarkup::format('The internal path component "@path" is external. You are not allowed to specify an external URL together with internal:/.', ['@path' => $uri_parts['path']])); + throw new \InvalidArgumentException("The internal path component '{$uri_parts['path']}' is external. You are not allowed to specify an external URL together with internal:/."); } } @@ -462,7 +461,7 @@ protected static function fromRouteUri(array $uri_parts, array $options, $uri) { $route_parts = explode(';', $uri_parts['path'], 2); $route_name = $route_parts[0]; if ($route_name === '') { - throw new \InvalidArgumentException(SafeMarkup::format('The route URI "@uri" is invalid. You must have a route name in the URI. e.g., route:system.admin', ['@uri' => $uri])); + throw new \InvalidArgumentException("The route URI '$uri' is invalid. You must have a route name in the URI. e.g., route:system.admin"); } $route_parameters = []; if (!empty($route_parts[1])) { diff --git a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php index 1e807b3..3c97c44 100644 --- a/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php +++ b/core/lib/Drupal/Core/Utility/UnroutedUrlAssembler.php @@ -7,7 +7,6 @@ namespace Drupal\Core\Utility; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\UrlHelper; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\GeneratedUrl; @@ -68,7 +67,7 @@ public function assemble($uri, array $options = [], $collect_bubbleable_metadata // UrlHelper::isExternal() only returns true for safe protocols. return $this->buildExternalUrl($uri, $options, $collect_bubbleable_metadata); } - throw new \InvalidArgumentException(SafeMarkup::format('The URI "@uri" is invalid. You must use a valid URI scheme. Use base: for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal.', ['@uri' => $uri])); + throw new \InvalidArgumentException("The URI '$uri' is invalid. You must use a valid URI scheme. Use base: for a path, e.g., to a Drupal file that needs the base path. Do not use this for internal paths controlled by Drupal."); } /** diff --git a/core/modules/block/src/BlockPluginCollection.php b/core/modules/block/src/BlockPluginCollection.php index c1905a7..b757d23 100644 --- a/core/modules/block/src/BlockPluginCollection.php +++ b/core/modules/block/src/BlockPluginCollection.php @@ -9,7 +9,6 @@ use Drupal\Component\Plugin\Exception\PluginException; use Drupal\Component\Plugin\PluginManagerInterface; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection; /** @@ -56,7 +55,7 @@ public function &get($instance_id) { */ protected function initializePlugin($instance_id) { if (!$instance_id) { - throw new PluginException(SafeMarkup::format("The block '@block' did not specify a plugin.", array('@block' => $this->blockId))); + throw new PluginException("The block '{$this->blockId}' did not specify a plugin."); } try { diff --git a/core/modules/comment/src/Tests/CommentTestTrait.php b/core/modules/comment/src/Tests/CommentTestTrait.php index 58aa9c7..d8c54c2 100644 --- a/core/modules/comment/src/Tests/CommentTestTrait.php +++ b/core/modules/comment/src/Tests/CommentTestTrait.php @@ -7,7 +7,6 @@ namespace Drupal\comment\Tests; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; @@ -42,10 +41,7 @@ public function addDefaultCommentField($entity_type, $bundle, $field_name = 'com $comment_type_storage = $entity_manager->getStorage('comment_type'); if ($comment_type = $comment_type_storage->load($comment_type_id)) { if ($comment_type->getTargetEntityTypeId() !== $entity_type) { - throw new \InvalidArgumentException(SafeMarkup::format('The given comment type id %id can only be used with the %entity_type entity type', array( - '%id' => $comment_type_id, - '%entity_type' => $entity_type, - ))); + throw new \InvalidArgumentException("The given comment type id $comment_type_id can only be used with the $entity_type entity type"); } } else { diff --git a/core/modules/config/src/Tests/ConfigImporterTest.php b/core/modules/config/src/Tests/ConfigImporterTest.php index ad21c78..e39baf6 100644 --- a/core/modules/config/src/Tests/ConfigImporterTest.php +++ b/core/modules/config/src/Tests/ConfigImporterTest.php @@ -295,8 +295,8 @@ function testSecondaryWriteSecondaryFirst() { $logs = $this->configImporter->getErrors(); $this->assertEqual(count($logs), 1); - $message = SafeMarkup::format('config_test entity with ID @name already exists', array('@name' => 'secondary')); - $this->assertEqual($logs[0], SafeMarkup::format('Unexpected error during import with operation @op for @name: @message.', array('@op' => 'create', '@name' => $name_primary, '@message' => $message))); + $message = SafeMarkup::format("'config_test' entity with ID '@name' already exists", array('@name' => 'secondary')); + $this->assertEqual($logs[0], SafeMarkup::format('Unexpected error during import with operation @op for @name: !message.', array('@op' => 'create', '@name' => $name_primary, '!message' => $message))); } /** diff --git a/core/modules/config_translation/src/ConfigMapperManager.php b/core/modules/config_translation/src/ConfigMapperManager.php index 56b2182..2731aa0 100644 --- a/core/modules/config_translation/src/ConfigMapperManager.php +++ b/core/modules/config_translation/src/ConfigMapperManager.php @@ -7,7 +7,6 @@ namespace Drupal\config_translation; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Config\TypedConfigManagerInterface; @@ -134,7 +133,7 @@ public function processDefinition(&$definition, $plugin_id) { parent::processDefinition($definition, $plugin_id); if (!isset($definition['base_route_name'])) { - throw new InvalidPluginDefinitionException($plugin_id, SafeMarkup::format("The plugin definition of the mapper '%plugin_id' does not contain a base_route_name.", array('%plugin_id' => $plugin_id))); + throw new InvalidPluginDefinitionException($plugin_id, "The plugin definition of the mapper '$plugin_id' does not contain a base_route_name."); } } diff --git a/core/modules/field/src/Entity/FieldConfig.php b/core/modules/field/src/Entity/FieldConfig.php index 500fa42..6054d02 100644 --- a/core/modules/field/src/Entity/FieldConfig.php +++ b/core/modules/field/src/Entity/FieldConfig.php @@ -110,12 +110,12 @@ public function __construct(array $values, $entity_type = 'field_config') { throw new FieldException('Attempt to create a field without a field_name.'); } if (empty($values['entity_type'])) { - throw new FieldException(SafeMarkup::format('Attempt to create a field @field_name without an entity_type.', array('@field_name' => $values['field_name']))); + throw new FieldException("Attempt to create a field '{$values['field_name']}' without an entity_type."); } } // 'bundle' is required in either case. if (empty($values['bundle'])) { - throw new FieldException(SafeMarkup::format('Attempt to create a field @field_name without a bundle.', array('@field_name' => $values['field_name']))); + throw new FieldException("Attempt to create a field '{$values['field_name']}' without a bundle."); } parent::__construct($values, $entity_type); @@ -288,9 +288,10 @@ public function getFieldStorageDefinition() { if (!$this->fieldStorage) { $fields = $this->entityManager()->getFieldStorageDefinitions($this->entity_type); if (!isset($fields[$this->field_name])) { - throw new FieldException(SafeMarkup::format('Attempt to create a field @field_name that does not exist on entity type @entity_type.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); } + throw new FieldException('Attempt to create a field {$this->field_name} that does not exist on entity type {$this->entity_type}.'); + } if (!$fields[$this->field_name] instanceof FieldStorageConfigInterface) { - throw new FieldException(SafeMarkup::format('Attempt to create a configurable field of non-configurable field storage @field_name.', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type))); + throw new FieldException("Attempt to create a configurable field of non-configurable field storage {$this->field_name}."); } $this->fieldStorage = $fields[$this->field_name]; } diff --git a/core/modules/field/src/Entity/FieldStorageConfig.php b/core/modules/field/src/Entity/FieldStorageConfig.php index 66b6fff..5fff1aa 100644 --- a/core/modules/field/src/Entity/FieldStorageConfig.php +++ b/core/modules/field/src/Entity/FieldStorageConfig.php @@ -7,7 +7,6 @@ namespace Drupal\field\Entity; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; @@ -242,13 +241,13 @@ public function __construct(array $values, $entity_type = 'field_storage_config' throw new FieldException('Attempt to create a field storage without a field name.'); } if (!preg_match('/^[_a-z]+[_a-z0-9]*$/', $values['field_name'])) { - throw new FieldException(SafeMarkup::format('Attempt to create a field storage @field_name with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character', array('@field_name' => $values['field_name']))); + throw new FieldException("Attempt to create a field storage {$values['field_name']} with invalid characters. Only lowercase alphanumeric characters and underscores are allowed, and only lowercase letters and underscore are allowed as the first character"); } if (empty($values['type'])) { - throw new FieldException(SafeMarkup::format('Attempt to create a field storage @field_name with no type.', array('@field_name' => $values['field_name']))); + throw new FieldException("Attempt to create a field storage {$values['field_name']} with no type."); } if (empty($values['entity_type'])) { - throw new FieldException(SafeMarkup::format('Attempt to create a field storage @field_name with no entity_type.', array('@field_name' => $values['field_name']))); + throw new FieldException("Attempt to create a field storage {$values['field_name']} with no entity_type."); } parent::__construct($values, $entity_type); @@ -309,24 +308,19 @@ protected function preSaveNew(EntityStorageInterface $storage) { // We use Unicode::strlen() because the DB layer assumes that column widths // are given in characters rather than bytes. if (Unicode::strlen($this->getName()) > static::NAME_MAX_LENGTH) { - throw new FieldException(SafeMarkup::format( - 'Attempt to create a field storage with an name longer than @max characters: %name', array( - '@max' => static::NAME_MAX_LENGTH, - '%name' => $this->getName(), - ) - )); + throw new FieldException('Attempt to create a field storage with an name longer than ' . static::NAME_MAX_LENGTH . ' characters: ' . $this->getName()); } // Disallow reserved field names. $disallowed_field_names = array_keys($entity_manager->getBaseFieldDefinitions($this->getTargetEntityTypeId())); if (in_array($this->getName(), $disallowed_field_names)) { - throw new FieldException(SafeMarkup::format('Attempt to create field storage %name which is reserved by entity type %type.', array('%name' => $this->getName(), '%type' => $this->getTargetEntityTypeId()))); + throw new FieldException("Attempt to create field storage {$this->getName()} which is reserved by entity type {$this->getTargetEntityTypeId()}."); } // Check that the field type is known. $field_type = $field_type_manager->getDefinition($this->getType(), FALSE); if (!$field_type) { - throw new FieldException(SafeMarkup::format('Attempt to create a field storage of unknown type %type.', array('%type' => $this->getType()))); + throw new FieldException("Attempt to create a field storage of unknown type {$this->getType()}."); } $this->module = $field_type['provider']; diff --git a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php index 2bce97d..f249c6c 100644 --- a/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php +++ b/core/modules/field/tests/src/Unit/FieldConfigEntityUnitTest.php @@ -178,7 +178,7 @@ public function testCalculateDependencies() { * Test that invalid bundles are handled. * * @expectedException \LogicException - * @expectedExceptionMessage Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists. + * @expectedExceptionMessage Missing bundle entity, entity type bundle_entity_type, entity id test_bundle_not_exists. */ public function testCalculateDependenciesIncorrectBundle() { $storage = $this->getMock('\Drupal\Core\Config\Entity\ConfigEntityStorageInterface'); diff --git a/core/modules/field_ui/src/Tests/ManageFieldsTest.php b/core/modules/field_ui/src/Tests/ManageFieldsTest.php index 8bd8688..3b2ac3e 100644 --- a/core/modules/field_ui/src/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/src/Tests/ManageFieldsTest.php @@ -627,7 +627,7 @@ public function testExternalDestinations() { // The external redirect should not fire. $this->assertUrl('admin/structure/types/manage/article/fields/node.article.body/storage', $options); $this->assertResponse(200); - $this->assertRaw('Attempt to update field Body failed: The internal path component "http://example.com" is external. You are not allowed to specify an external URL together with internal:/..'); + $this->assertRaw('Attempt to update field Body failed: The internal path component 'http://example.com' is external. You are not allowed to specify an external URL together with internal:/..'); } /** diff --git a/core/modules/image/src/Form/ImageEffectFormBase.php b/core/modules/image/src/Form/ImageEffectFormBase.php index 7b7f25b..66edd95 100644 --- a/core/modules/image/src/Form/ImageEffectFormBase.php +++ b/core/modules/image/src/Form/ImageEffectFormBase.php @@ -13,7 +13,6 @@ use Drupal\image\ConfigurableImageEffectInterface; use Drupal\image\ImageStyleInterface; use Drupal\Component\Plugin\Exception\PluginNotFoundException; -use Drupal\Component\Utility\SafeMarkup; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** @@ -61,7 +60,7 @@ public function buildForm(array $form, FormStateInterface $form_state, ImageStyl $this->imageEffect = $this->prepareImageEffect($image_effect); } catch (PluginNotFoundException $e) { - throw new NotFoundHttpException(SafeMarkup::format("Invalid effect id: '@id'.", array('@id' => $image_effect))); + throw new NotFoundHttpException("Invalid effect id: '$image_effect'."); } $request = $this->getRequest(); diff --git a/core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php b/core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php index 651209a..00cd1b9 100644 --- a/core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php +++ b/core/modules/language/src/Config/LanguageConfigCollectionNameTrait.php @@ -7,8 +7,6 @@ namespace Drupal\language\Config; -use Drupal\Component\Utility\SafeMarkup; - /** * Provides a common trait for working with language override collection names. */ @@ -45,7 +43,7 @@ protected function createConfigCollectionName($langcode) { protected function getLangcodeFromCollectionName($collection) { preg_match('/^language\.(.*)$/', $collection, $matches); if (!isset($matches[1])) { - throw new \InvalidArgumentException(SafeMarkup::format('!collection is not a valid language override collection', array('!collection' => $collection))); + throw new \InvalidArgumentException("'$collection' is not a valid language override collection"); } return $matches[1]; } diff --git a/core/modules/language/src/Entity/ContentLanguageSettings.php b/core/modules/language/src/Entity/ContentLanguageSettings.php index 76a8a25..da69686 100644 --- a/core/modules/language/src/Entity/ContentLanguageSettings.php +++ b/core/modules/language/src/Entity/ContentLanguageSettings.php @@ -7,7 +7,6 @@ namespace Drupal\language\Entity; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Language\LanguageInterface; @@ -200,7 +199,7 @@ public function calculateDependencies() { // If the target entity type uses entities to manage its bundles then // depend on the bundle entity. if (!$bundle_entity = $this->entityManager()->getStorage($bundle_entity_type_id)->load($this->target_bundle)) { - throw new \LogicException(SafeMarkup::format('Missing bundle entity, entity type %type, entity id %bundle.', array('%type' => $bundle_entity_type_id, '%bundle' => $this->target_bundle))); + throw new \LogicException("Missing bundle entity, entity type $bundle_entity_type_id, entity id {$this->target_bundle}."); } $this->addDependency('config', $bundle_entity->getConfigDependencyName()); } diff --git a/core/modules/locale/src/StringBase.php b/core/modules/locale/src/StringBase.php index eecd505..d0340ef 100644 --- a/core/modules/locale/src/StringBase.php +++ b/core/modules/locale/src/StringBase.php @@ -190,9 +190,7 @@ public function save() { $storage->save($this); } else { - throw new StringStorageException(SafeMarkup::format('The string cannot be saved because its not bound to a storage: @string', array( - '@string' => $this->getString(), - ))); + throw new StringStorageException('The string cannot be saved because its not bound to a storage: ' . $this->getString()); } return $this; } @@ -206,9 +204,7 @@ public function delete() { $storage->delete($this); } else { - throw new StringStorageException(SafeMarkup::format('The string cannot be deleted because its not bound to a storage: @string', array( - '@string' => $this->getString(), - ))); + throw new StringStorageException('The string cannot be deleted because its not bound to a storage: ' . $this->getString()); } } return $this; diff --git a/core/modules/locale/src/StringDatabaseStorage.php b/core/modules/locale/src/StringDatabaseStorage.php index 06f9f97..de62484 100644 --- a/core/modules/locale/src/StringDatabaseStorage.php +++ b/core/modules/locale/src/StringDatabaseStorage.php @@ -199,9 +199,7 @@ public function delete($string) { } } else { - throw new StringStorageException(format_string('The string cannot be deleted because it lacks some key fields: @string', array( - '@string' => $string->getString(), - ))); + throw new StringStorageException('The string cannot be deleted because it lacks some key fields: ' . $string->getString()); } return $this; } @@ -483,9 +481,7 @@ protected function dbStringInsert($string) { ->execute(); } else { - throw new StringStorageException(format_string('The string cannot be saved: @string', array( - '@string' => $string->getString(), - ))); + throw new StringStorageException('The string cannot be saved: ' . $string->getString()); } } @@ -516,9 +512,7 @@ protected function dbStringUpdate($string) { ->execute(); } else { - throw new StringStorageException(format_string('The string cannot be updated: @string', array( - '@string' => $string->getString(), - ))); + throw new StringStorageException('The string cannot be updated: ' . $string->getString()); } } diff --git a/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php b/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php index f120b61..a9a7d2c 100644 --- a/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php +++ b/core/modules/menu_link_content/src/Plugin/Menu/MenuLinkContent.php @@ -8,7 +8,6 @@ namespace Drupal\menu_link_content\Plugin\Menu; use Drupal\Component\Plugin\Exception\PluginException; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Language\LanguageManagerInterface; use Drupal\Core\Menu\MenuLinkBase; @@ -138,7 +137,7 @@ protected function getEntity() { $entity = reset($loaded_entities); } if (!$entity) { - throw new PluginException(SafeMarkup::format('Entity not found through the menu link plugin definition and could not fallback on UUID @uuid', array('@uuid' => $uuid))); + throw new PluginException("Entity not found through the menu link plugin definition and could not fallback on UUID '$uuid'"); } // Clone the entity object to avoid tampering with the static cache. $this->entity = clone $entity; diff --git a/core/modules/migrate/src/Entity/Migration.php b/core/modules/migrate/src/Entity/Migration.php index e3f920c..c92f975 100644 --- a/core/modules/migrate/src/Entity/Migration.php +++ b/core/modules/migrate/src/Entity/Migration.php @@ -7,7 +7,6 @@ namespace Drupal\migrate\Entity; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Config\Entity\ConfigEntityBase; use Drupal\migrate\Exception\RequirementsException; use Drupal\migrate\MigrateException; @@ -381,7 +380,7 @@ public function checkRequirements() { } } if ($missing_migrations) { - throw new RequirementsException(SafeMarkup::format('Missing migrations @requirements.', ['@requirements' => implode(', ', $missing_migrations)]), ['requirements' => $missing_migrations]); + throw new RequirementsException('Missing migrations ' . implode(', ', $missing_migrations) . '.', ['requirements' => $missing_migrations]); } } diff --git a/core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php b/core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php index 817b1c9..57d6909 100644 --- a/core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php +++ b/core/modules/migrate/src/Plugin/migrate/destination/EntityFile.php @@ -7,7 +7,6 @@ namespace Drupal\migrate\Plugin\migrate\destination; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\File\FileSystemInterface; @@ -83,7 +82,7 @@ public function import(Row $row, array $old_destination_id_values = array()) { // Ensure the source file exists, if it's a local URI or path. if ($this->isLocalUri($source) && !file_exists($source)) { - throw new MigrateException(SafeMarkup::format('File @source does not exist.', ['@source' => $source])); + throw new MigrateException("File '$source' does not exist."); } // If the start and end file is exactly the same, there is nothing to do. @@ -99,7 +98,7 @@ public function import(Row $row, array $old_destination_id_values = array()) { $success = $this->writeFile($source, $destination, $replace); } else { - throw new MigrateException(SafeMarkup::format('Could not create directory @dir', ['@dir' => $dir])); + throw new MigrateException("Could not create directory '$dir'"); } } @@ -107,7 +106,7 @@ public function import(Row $row, array $old_destination_id_values = array()) { return parent::import($row, $old_destination_id_values); } else { - throw new MigrateException(SafeMarkup::format('File %source could not be copied to %destination.', ['%source' => $source, '%destination' => $destination])); + throw new MigrateException("File $source could not be copied to $destination."); } } diff --git a/core/modules/migrate/src/Plugin/migrate/process/Concat.php b/core/modules/migrate/src/Plugin/migrate/process/Concat.php index 6e45e5d..174818d 100644 --- a/core/modules/migrate/src/Plugin/migrate/process/Concat.php +++ b/core/modules/migrate/src/Plugin/migrate/process/Concat.php @@ -7,7 +7,6 @@ namespace Drupal\migrate\Plugin\migrate\process; -use Drupal\Component\Utility\SafeMarkup; use Drupal\migrate\MigrateException; use Drupal\migrate\MigrateExecutableInterface; use Drupal\migrate\ProcessPluginBase; @@ -34,7 +33,7 @@ public function transform($value, MigrateExecutableInterface $migrate_executable return implode($delimiter, $value); } else { - throw new MigrateException(sprintf('%s is not an array', SafeMarkup::checkPlain(var_export($value, TRUE)))); + throw new MigrateException(sprintf('%s is not an array', var_export($value, TRUE))); } } diff --git a/core/modules/migrate/src/Tests/EntityFileTest.php b/core/modules/migrate/src/Tests/EntityFileTest.php index 509e98b..718e0a7 100644 --- a/core/modules/migrate/src/Tests/EntityFileTest.php +++ b/core/modules/migrate/src/Tests/EntityFileTest.php @@ -94,7 +94,7 @@ public function testNonExistentSourceFile() { $this->fail('Expected Drupal\migrate\MigrateException when importing ' . $destination); } catch (MigrateException $e) { - $this->assertIdentical($e->getMessage(), 'File ' . $destination . ' does not exist.'); + $this->assertIdentical($e->getMessage(), "File '$destination' does not exist."); } } diff --git a/core/modules/migrate/tests/src/Unit/TestSqlIdMap.php b/core/modules/migrate/tests/src/Unit/TestSqlIdMap.php index 203bd62..68d8077 100644 --- a/core/modules/migrate/tests/src/Unit/TestSqlIdMap.php +++ b/core/modules/migrate/tests/src/Unit/TestSqlIdMap.php @@ -7,7 +7,6 @@ namespace Drupal\Tests\migrate\Unit; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Database\Connection; use Drupal\migrate\Entity\MigrationInterface; use Drupal\migrate\MigrateException; @@ -61,7 +60,7 @@ protected function getFieldSchema(array $id_definition) { 'not null' => FALSE, ); default: - throw new MigrateException(SafeMarkup::format('@type not supported', array('@type' => $id_definition['type']))); + throw new MigrateException($id_definition['type'] . ' not supported'); } } } diff --git a/core/modules/migrate_drupal/src/MigrationStorage.php b/core/modules/migrate_drupal/src/MigrationStorage.php index 06b0c29..9a33b36 100644 --- a/core/modules/migrate_drupal/src/MigrationStorage.php +++ b/core/modules/migrate_drupal/src/MigrationStorage.php @@ -7,7 +7,6 @@ namespace Drupal\migrate_drupal; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Uuid\UuidInterface; use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityInterface; @@ -164,7 +163,7 @@ protected function getDynamicIds(array &$dynamic_ids, array $entities) { */ public function save(EntityInterface $entity) { if (strpos($entity->id(), ':') !== FALSE) { - throw new EntityStorageException(SafeMarkup::format("Dynamic migration %id can't be saved", array('$%id' => $entity->id()))); + throw new EntityStorageException("Dynamic migration '{$entity->id()}' can't be saved"); } return parent::save($entity); } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php b/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php index 9edbcd0..375fe7b 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/load/LoadEntity.php @@ -7,7 +7,6 @@ namespace Drupal\migrate_drupal\Plugin\migrate\load; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Plugin\PluginBase; use Drupal\migrate\Entity\MigrationInterface; @@ -44,7 +43,7 @@ public function __construct(array $configuration, $plugin_id, array $plugin_defi throw new MigrateException('Migrations with a load plugin using LoadEntity should have an entity as source.'); } if ($source_plugin->bundleMigrationRequired() && empty($configuration['bundle_migration'])) { - throw new MigrateException(SafeMarkup::format('Source plugin @plugin requires the bundle_migration key to be set.', array('@plugin' => $source_plugin->getPluginId()))); + throw new MigrateException("Source plugin '{$source_plugin->getPluginId()}' requires the bundle_migration key to be set."); } } diff --git a/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php b/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php index 5257d94..deb7adf 100644 --- a/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php +++ b/core/modules/migrate_drupal/src/Plugin/migrate/source/DrupalSqlBase.php @@ -8,7 +8,6 @@ namespace Drupal\migrate_drupal\Plugin\migrate\source; use Drupal\Component\Plugin\DependentPluginInterface; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Entity\DependencyTrait; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; @@ -102,11 +101,11 @@ public function checkRequirements() { if (isset($this->pluginDefinition['source_provider'])) { if ($this->moduleExists($this->pluginDefinition['source_provider'])) { if (isset($this->pluginDefinition['minimum_schema_version']) && !$this->getModuleSchemaVersion($this->pluginDefinition['source_provider']) < $this->pluginDefinition['minimum_schema_version']) { - throw new RequirementsException(SafeMarkup::format('Required minimum schema version @minimum_schema_version', ['@minimum_schema_version' => $this->pluginDefinition['minimum_schema_version']]), ['minimum_schema_version' => $this->pluginDefinition['minimum_schema_version']]); + throw new RequirementsException('Required minimum schema version ' . $this->pluginDefinition['minimum_schema_version'], ['minimum_schema_version' => $this->pluginDefinition['minimum_schema_version']]); } } else { - throw new RequirementsException(SafeMarkup::format('Missing source provider @provider', ['@provider' => $this->pluginDefinition['source_provider']]), ['source_provider' => $this->pluginDefinition['source_provider']]); + throw new RequirementsException('Missing source provider ' . $this->pluginDefinition['source_provider'], ['source_provider' => $this->pluginDefinition['source_provider']]); } } } diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index e7e2465..86b0a12 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -5,7 +5,6 @@ * Responsive image display formatter for image fields. */ -use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; use Drupal\Core\Routing\RouteMatchInterface; use \Drupal\Core\Template\Attribute; @@ -333,7 +332,7 @@ function responsive_image_build_source_attributes(ImageInterface $image, array $ // this breakpoint should be merged into one srcset and the sizes // attribute should be merged as well. if (is_null($dimensions['width'])) { - throw new \LogicException(SafeMarkup::format('Could not determine image width for @file using image style with ID: @image_style_name. This image style can not be used for a responsive image style mapping using the \'sizes\' attribute.', array('@file' => $image->getSource(), '@image_style_name' => $image_style_name))); + throw new \LogicException("Could not determine image width for '{$image->getSource()}' using image style with ID: $image_style_name. This image style can not be used for a responsive image style mapping using the 'sizes' attribute."); } // Use the image width as key so we can sort the array later on. // Images within a srcset should be sorted from small to large, since diff --git a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php index 8aa4dc3..464fe08 100644 --- a/core/modules/rest/src/Plugin/rest/resource/EntityResource.php +++ b/core/modules/rest/src/Plugin/rest/resource/EntityResource.php @@ -11,7 +11,6 @@ use Drupal\Core\Entity\EntityStorageException; use Drupal\rest\Plugin\ResourceBase; use Drupal\rest\ResourceResponse; -use Drupal\Component\Utility\SafeMarkup; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\HttpException; @@ -98,7 +97,7 @@ public function post(EntityInterface $entity = NULL) { // and 'update', so the 'edit' operation is used here. foreach ($entity->_restSubmittedFields as $key => $field_name) { if (!$entity->get($field_name)->access('edit')) { - throw new AccessDeniedHttpException(SafeMarkup::format('Access denied on creating field @field', array('@field' => $field_name))); + throw new AccessDeniedHttpException("Access denied on creating field '$field_name'"); } } @@ -155,7 +154,7 @@ public function patch(EntityInterface $original_entity, EntityInterface $entity } if (!$original_entity->get($field_name)->access('edit')) { - throw new AccessDeniedHttpException(SafeMarkup::format('Access denied on updating field @field.', array('@field' => $field_name))); + throw new AccessDeniedHttpException("Access denied on updating field '$field_name'."); } $original_entity->set($field_name, $field->getValue()); } diff --git a/core/modules/simpletest/src/KernelTestBase.php b/core/modules/simpletest/src/KernelTestBase.php index 481b031..ba8622b 100644 --- a/core/modules/simpletest/src/KernelTestBase.php +++ b/core/modules/simpletest/src/KernelTestBase.php @@ -381,9 +381,7 @@ protected function defaultLanguageData() { protected function installConfig(array $modules) { foreach ($modules as $module) { if (!$this->container->get('module_handler')->moduleExists($module)) { - throw new \RuntimeException(format_string("'@module' module is not enabled.", array( - '@module' => $module, - ))); + throw new \RuntimeException("'$module' module is not enabled"); } \Drupal::service('config.installer')->installDefaultConfig('module', $module); } @@ -411,18 +409,13 @@ protected function installSchema($module, $tables) { // behavior and non-reproducible test failures, we only allow the schema of // explicitly loaded/enabled modules to be installed. if (!$this->container->get('module_handler')->moduleExists($module)) { - throw new \RuntimeException(format_string("'@module' module is not enabled.", array( - '@module' => $module, - ))); + throw new \RuntimeException("'$module' module is not enabled"); } $tables = (array) $tables; foreach ($tables as $table) { $schema = drupal_get_module_schema($module, $table); if (empty($schema)) { - throw new \RuntimeException(format_string("Unknown '@table' table schema in '@module' module.", array( - '@module' => $module, - '@table' => $table, - ))); + throw new \RuntimeException("Unknown '$table' table schema in '$module' module."); } $this->container->get('database')->schema()->createTable($table, $schema); } diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php index 93b9360..a905871 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Convert.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Component\Utility\SafeMarkup; - /** * Defines GD2 convert operation. * @@ -38,7 +36,7 @@ protected function arguments() { */ protected function validateArguments(array $arguments) { if (!in_array($arguments['extension'], $this->getToolkit()->getSupportedExtensions())) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid extension (@value) specified for the image 'convert' operation", array('@value' => $arguments['extension']))); + throw new \InvalidArgumentException("Invalid extension ({$arguments['extension']}) specified for the image 'convert' operation"); } return $arguments; } diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php index 00fecad..2b556f7 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/CreateNew.php @@ -8,7 +8,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; use Drupal\Component\Utility\Color; -use Drupal\Component\Utility\SafeMarkup; /** * Defines GD2 create_new image operation. @@ -53,7 +52,7 @@ protected function arguments() { protected function validateArguments(array $arguments) { // Assure extension is supported. if (!in_array($arguments['extension'], $this->getToolkit()->getSupportedExtensions())) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid extension (@value) specified for the image 'convert' operation", array('@value' => $arguments['extension']))); + throw new \InvalidArgumentException("Invalid extension ('{$arguments['extension']}') specified for the image 'convert' operation"); } // Assure integers for width and height. @@ -62,15 +61,15 @@ protected function validateArguments(array $arguments) { // Fail when width or height are 0 or negative. if ($arguments['width'] <= 0) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid width (@value) specified for the image 'create_new' operation", array('@value' => $arguments['width']))); + throw new \InvalidArgumentException("Invalid width ('{$arguments['width']}') specified for the image 'create_new' operation"); } if ($arguments['height'] <= 0) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid height (@value) specified for the image 'create_new' operation", array('@value' => $arguments['height']))); + throw new \InvalidArgumentException("Invalid height ({$arguments['height']}) specified for the image 'create_new' operation"); } // Assure transparent color is a valid hex string. if ($arguments['transparent_color'] && !Color::validateHex($arguments['transparent_color'])) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid transparent color (@value) specified for the image 'create_new' operation", array('@value' => $arguments['transparent_color']))); + throw new \InvalidArgumentException("Invalid transparent color ({$arguments['transparent_color']}) specified for the image 'create_new' operation"); } return $arguments; diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php index 21d59f4..aed4a26 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Crop.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Component\Utility\SafeMarkup; - /** * Defines GD2 Crop operation. * @@ -67,10 +65,10 @@ protected function validateArguments(array $arguments) { // Fail when width or height are 0 or negative. if ($arguments['width'] <= 0) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid width (@value) specified for the image 'crop' operation", array('@value' => $arguments['width']))); + throw new \InvalidArgumentException("Invalid width ('{$arguments['width']}') specified for the image 'crop' operation"); } if ($arguments['height'] <= 0) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid height (@value) specified for the image 'crop' operation", array('@value' => $arguments['height']))); + throw new \InvalidArgumentException("Invalid height ('{$arguments['height']}') specified for the image 'crop' operation"); } return $arguments; diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php index be72427..2e4494c 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Resize.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Component\Utility\SafeMarkup; - /** * Defines GD2 resize operation. * @@ -46,10 +44,10 @@ protected function validateArguments(array $arguments) { // Fail when width or height are 0 or negative. if ($arguments['width'] <= 0) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid width (@value) specified for the image 'resize' operation", array('@value' => $arguments['width']))); + throw new \InvalidArgumentException("Invalid width ('{$arguments['width']}') specified for the image 'resize' operation"); } if ($arguments['height'] <= 0) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid height (@value) specified for the image 'resize' operation", array('@value' => $arguments['height']))); + throw new \InvalidArgumentException("Invalid height ('{$arguments['height']}') specified for the image 'resize' operation"); } return $arguments; diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php index 875ce23..c478878 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/Scale.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Component\Utility\SafeMarkup; - /** * Defines GD2 Scale operation. * @@ -73,10 +71,10 @@ protected function validateArguments(array $arguments) { // Fail when width or height are 0 or negative. if ($arguments['width'] <= 0) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid width (@value) specified for the image 'scale' operation", array('@value' => $arguments['width']))); + throw new \InvalidArgumentException("Invalid width ('{$arguments['width']}') specified for the image 'scale' operation"); } if ($arguments['height'] <= 0) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid height (@value) specified for the image 'scale' operation", array('@value' => $arguments['height']))); + throw new \InvalidArgumentException("Invalid height ('{$arguments['height']}') specified for the image 'scale' operation"); } return $arguments; diff --git a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php index 7d465b8..0e09bd4 100644 --- a/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php +++ b/core/modules/system/src/Plugin/ImageToolkit/Operation/gd/ScaleAndCrop.php @@ -7,8 +7,6 @@ namespace Drupal\system\Plugin\ImageToolkit\Operation\gd; -use Drupal\Component\Utility\SafeMarkup; - /** * Defines GD2 Scale and crop operation. * @@ -54,10 +52,10 @@ protected function validateArguments(array $arguments) { // Fail when width or height are 0 or negative. if ($arguments['width'] <= 0) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid width (@value) specified for the image 'scale_and_crop' operation", array('@value' => $arguments['width']))); + throw new \InvalidArgumentException("Invalid width ('{$arguments['width']}') specified for the image 'scale_and_crop' operation"); } if ($arguments['height'] <= 0) { - throw new \InvalidArgumentException(SafeMarkup::format("Invalid height (@value) specified for the image 'scale_and_crop' operation", array('@value' => $arguments['height']))); + throw new \InvalidArgumentException("Invalid height ('{$arguments['height']}') specified for the image 'scale_and_crop' operation"); } return $arguments; diff --git a/core/modules/system/src/Tests/Plugin/ContextPluginTest.php b/core/modules/system/src/Tests/Plugin/ContextPluginTest.php index 5b04cd5..3508689 100644 --- a/core/modules/system/src/Tests/Plugin/ContextPluginTest.php +++ b/core/modules/system/src/Tests/Plugin/ContextPluginTest.php @@ -57,7 +57,7 @@ function testContext() { $plugin->getContextValue('user'); } catch(ContextException $e) { - $this->assertIdentical("The entity:user context is required and not present.", $e->getMessage(), 'Requesting a non-set value of a required context should throw a context exception.'); + $this->assertIdentical("The 'entity:user' context is required and not present.", $e->getMessage(), 'Requesting a non-set value of a required context should throw a context exception.'); } // Try to pass the wrong class type as a context value. diff --git a/core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php b/core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php index ee3c763..1b22d5c 100644 --- a/core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php +++ b/core/modules/system/src/Tests/Routing/ExceptionHandlingTest.php @@ -120,4 +120,28 @@ public function testBacktraceEscaping() { $this->assertTrue(strpos($response->getContent(), '') === FALSE); } + /** + * Tests exception message escaping. + */ + public function testExceptionEscaping() { + // Enable verbose error logging. + $this->config('system.logging')->set('error_level', ERROR_REPORTING_DISPLAY_VERBOSE)->save(); + + // Using SafeMarkup::format(). + $request = Request::create('/router_test/test24'); + $request->setFormat('html', ['text/html']); + + /** @var \Symfony\Component\HttpKernel\HttpKernelInterface $kernel */ + $kernel = \Drupal::getContainer()->get('http_kernel'); + $response = $kernel->handle($request)->prepare($request); + $this->assertEqual($response->getStatusCode(), Response::HTTP_INTERNAL_SERVER_ERROR); + $this->assertEqual($response->headers->get('Content-type'), 'text/html; charset=UTF-8'); + + // Test message is properly escaped, and that the unescaped string is not + // output at all. + $this->setRawContent($response->getContent()); + $this->assertRaw(SafeMarkup::checkPlain('Escaped content:


')); + $this->assertNoRaw('


'); + } + } diff --git a/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php b/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php index 0f52fba..649b04f 100644 --- a/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php +++ b/core/modules/system/tests/modules/accept_header_routing_test/src/Routing/AcceptHeaderMatcher.php @@ -7,7 +7,6 @@ namespace Drupal\accept_header_routing_test\Routing; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\Routing\RouteFilterInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException; @@ -62,7 +61,7 @@ public function filter(RouteCollection $collection, Request $request) { // We do not throw a // \Symfony\Component\Routing\Exception\ResourceNotFoundException here // because we don't want to return a 404 status code, but rather a 406. - throw new NotAcceptableHttpException(SafeMarkup::format('No route found for the specified formats @formats.', array('@formats' => implode(' ', $acceptable_mime_types)))); + throw new NotAcceptableHttpException('No route found for the specified formats ' . implode(' ', $acceptable_mime_types)); } /** diff --git a/core/modules/system/tests/modules/router_test_directory/router_test.routing.yml b/core/modules/system/tests/modules/router_test_directory/router_test.routing.yml index 36a7017..8ae26d4 100644 --- a/core/modules/system/tests/modules/router_test_directory/router_test.routing.yml +++ b/core/modules/system/tests/modules/router_test_directory/router_test.routing.yml @@ -148,7 +148,14 @@ router_test.23: requirements: _access: 'TRUE' -router_test.hierarchy_parent: +router_test.24: + path: '/router_test/test24' + defaults: + _controller: '\Drupal\router_test\TestControllers::test24' + requirements: + _access: 'TRUE' + +router_test.dierarchy_parent: path: '/menu-test/parent' defaults: _controller: '\Drupal\router_test\TestControllers::test' diff --git a/core/modules/system/tests/modules/router_test_directory/src/TestControllers.php b/core/modules/system/tests/modules/router_test_directory/src/TestControllers.php index f3ff517..40fad0b 100644 --- a/core/modules/system/tests/modules/router_test_directory/src/TestControllers.php +++ b/core/modules/system/tests/modules/router_test_directory/src/TestControllers.php @@ -76,14 +76,7 @@ public function test9($uid) { * This can be used to test if the generated backtrace is properly escaped. */ public function test10() { - // Remove the exception logger from the event dispatcher. We are going to - // throw an exception to check if it is properly escaped when rendered as a - // backtrace. The exception logger does a call to error_log() which is not - // handled by the Simpletest error handler and would cause a test failure. - $event_dispatcher = \Drupal::service('event_dispatcher'); - $exception_logger = \Drupal::service('exception.logger'); - $event_dispatcher->removeSubscriber($exception_logger); - + $this->removeExceptionLogger(); $this->throwException(''); } @@ -108,6 +101,11 @@ public function test23() { return new HtmlResponse('test23'); } + public function test24() { + $this->removeExceptionLogger(); + throw new \Exception('Escaped content:


'); + } + /** * Throws an exception. * @@ -121,4 +119,14 @@ protected function throwException($message) { throw new \Exception($message); } + protected function removeExceptionLogger() { + // Remove the exception logger from the event dispatcher. We are going to + // throw an exception to check if it is properly escaped when rendered as a + // backtrace. The exception logger does a call to error_log() which is not + // handled by the Simpletest error handler and would cause a test failure. + $event_dispatcher = \Drupal::service('event_dispatcher'); + $exception_logger = \Drupal::service('exception.logger'); + $event_dispatcher->removeSubscriber($exception_logger); + } + } diff --git a/core/modules/user/src/PrivateTempStore.php b/core/modules/user/src/PrivateTempStore.php index 090aad4..3b5fe4a 100644 --- a/core/modules/user/src/PrivateTempStore.php +++ b/core/modules/user/src/PrivateTempStore.php @@ -7,7 +7,6 @@ namespace Drupal\user; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface; use Drupal\Core\Lock\LockBackendInterface; use Drupal\Core\Session\AccountProxyInterface; @@ -122,10 +121,7 @@ public function set($key, $value) { if (!$this->lockBackend->acquire($key)) { $this->lockBackend->wait($key); if (!$this->lockBackend->acquire($key)) { - throw new TempStoreException(SafeMarkup::format("Couldn't acquire lock to update item %key in %collection temporary storage.", array( - '%key' => $key, - '%collection' => $this->storage->getCollectionName(), - ))); + throw new TempStoreException("Couldn't acquire lock to update item '$key' in '{$this->storage->getCollectionName()}' temporary storage."); } } @@ -180,10 +176,7 @@ public function delete($key) { if (!$this->lockBackend->acquire($key)) { $this->lockBackend->wait($key); if (!$this->lockBackend->acquire($key)) { - throw new TempStoreException(SafeMarkup::format("Couldn't acquire lock to delete item %key from %collection temporary storage.", array( - '%key' => $key, - '%collection' => $this->storage->getCollectionName(), - ))); + throw new TempStoreException("Couldn't acquire lock to delete item '$key' from '{$this->storage->getCollectionName()}' temporary storage."); } } $this->storage->delete($key); diff --git a/core/modules/user/src/SharedTempStore.php b/core/modules/user/src/SharedTempStore.php index 0fa9ba4..0a70b7f 100644 --- a/core/modules/user/src/SharedTempStore.php +++ b/core/modules/user/src/SharedTempStore.php @@ -7,7 +7,6 @@ namespace Drupal\user; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\KeyValueStore\KeyValueStoreExpirableInterface; use Drupal\Core\Lock\LockBackendInterface; use Symfony\Component\HttpFoundation\RequestStack; @@ -196,10 +195,7 @@ public function set($key, $value) { if (!$this->lockBackend->acquire($key)) { $this->lockBackend->wait($key); if (!$this->lockBackend->acquire($key)) { - throw new TempStoreException(SafeMarkup::format("Couldn't acquire lock to update item %key in %collection temporary storage.", array( - '%key' => $key, - '%collection' => $this->storage->getCollectionName(), - ))); + throw new TempStoreException("Couldn't acquire lock to update item '$key' in '{$this->storage->getCollectionName()}' temporary storage."); } } @@ -242,10 +238,7 @@ public function delete($key) { if (!$this->lockBackend->acquire($key)) { $this->lockBackend->wait($key); if (!$this->lockBackend->acquire($key)) { - throw new TempStoreException(SafeMarkup::format("Couldn't acquire lock to delete item %key from %collection temporary storage.", array( - '%key' => $key, - '%collection' => $this->storage->getCollectionName(), - ))); + throw new TempStoreException("Couldn't acquire lock to delete item '$key' from {$this->storage->getCollectionName()} temporary storage."); } } $this->storage->delete($key); diff --git a/core/modules/views/src/Plugin/views/HandlerBase.php b/core/modules/views/src/Plugin/views/HandlerBase.php index 82a4a92..f2e5604 100644 --- a/core/modules/views/src/Plugin/views/HandlerBase.php +++ b/core/modules/views/src/Plugin/views/HandlerBase.php @@ -721,7 +721,7 @@ public function getEntityType() { return $views_data['table']['entity type']; } else { - throw new \Exception(SafeMarkup::format('No entity type for field @field on view @view', array('@field' => $this->options['id'], '@view' => $this->view->storage->id()))); + throw new \Exception("No entity type for field {$this->options['id']} on view {$this->view->storage->id()}"); } } diff --git a/core/modules/views/src/Plugin/views/query/Sql.php b/core/modules/views/src/Plugin/views/query/Sql.php index a61b850..7ee7316 100644 --- a/core/modules/views/src/Plugin/views/query/Sql.php +++ b/core/modules/views/src/Plugin/views/query/Sql.php @@ -1454,7 +1454,7 @@ function execute(ViewExecutable $view) { drupal_set_message($e->getMessage(), 'error'); } else { - throw new DatabaseExceptionWrapper(format_string('Exception in @label[@view_name]: @message', array('@label' => $view->storage->label(), '@view_name' => $view->storage->id(), '@message' => $e->getMessage()))); + throw new DatabaseExceptionWrapper("Exception in {$view->storage->label()}[$view->storage->id()]: {$e->getMessage()}"); } } diff --git a/core/modules/views/src/ViewExecutable.php b/core/modules/views/src/ViewExecutable.php index b21f314..2e4189c 100644 --- a/core/modules/views/src/ViewExecutable.php +++ b/core/modules/views/src/ViewExecutable.php @@ -9,7 +9,6 @@ use Drupal\Component\Utility\Html; use Drupal\Core\Cache\Cache; -use Drupal\Component\Utility\SafeMarkup; use Drupal\Core\DependencyInjection\DependencySerializationTrait; use Drupal\Core\Form\FormState; use Drupal\Core\Routing\RouteProviderInterface; @@ -1897,7 +1896,7 @@ public function getUrl($args = NULL, $display_id = NULL) { public function getUrlInfo($display_id = '') { $this->initDisplay(); if (!$this->display_handler instanceof DisplayRouterInterface) { - throw new \InvalidArgumentException(SafeMarkup::format('You cannot generate a URL for the display @display_id', ['@display_id' => $display_id])); + throw new \InvalidArgumentException("You cannot generate a URL for the display '$display_id'"); } return $this->display_handler->getUrlInfo(); } diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php index a048f95..7a34a93 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -413,17 +413,12 @@ public function validateNameProvider() { // Name missing namespace (dot). array( 'MissingNamespace', - SafeMarkup::format('Missing namespace in Config object name MissingNamespace.', array( - '@name' => 'MissingNamespace', - )), + 'Missing namespace in Config object name MissingNamespace.', ), // Exceeds length (max length plus an extra dot). array( str_repeat('a', Config::MAX_NAME_LENGTH) . ".", - SafeMarkup::format('Config object name @name exceeds maximum allowed length of @length characters.', array( - '@name' => str_repeat('a', Config::MAX_NAME_LENGTH) . ".", - '@length' => Config::MAX_NAME_LENGTH, - )), + 'Config object name ' . str_repeat('a', Config::MAX_NAME_LENGTH) . '. exceeds maximum allowed length of ' . Config::MAX_NAME_LENGTH . ' characters.', ), ); // Name must not contain : ? * < > " ' / \ @@ -431,9 +426,7 @@ public function validateNameProvider() { $name = 'name.' . $char; $return[] = array( $name, - SafeMarkup::format('Invalid character in Config object name @name.', array( - '@name' => $name, - )), + "Invalid character in Config object name $name.", ); } return $return; diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php index 524fea0..97bf172 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityTypeTest.php @@ -9,7 +9,6 @@ use Drupal\Tests\UnitTestCase; use Drupal\Core\Config\Entity\ConfigEntityType; -use Drupal\Component\Utility\SafeMarkup; /** * @coversDefaultClass \Drupal\Core\Config\Entity\ConfigEntityType @@ -41,8 +40,6 @@ protected function setUpConfigEntityType($definition) { * @covers ::getConfigPrefix */ public function testConfigPrefixLengthExceeds() { - $message_text = 'The configuration file name prefix @config_prefix exceeds the maximum character limit of @max_char.'; - // A provider length of 24 and config_prefix length of 59 (+1 for the .) // results in a config length of 84, which is too long. $definition = array( @@ -50,10 +47,10 @@ public function testConfigPrefixLengthExceeds() { 'config_prefix' => $this->randomMachineName(59), ); $config_entity = $this->setUpConfigEntityType($definition); - $this->setExpectedException('\Drupal\Core\Config\ConfigPrefixLengthException', SafeMarkup::format($message_text, array( - '@config_prefix' => $definition['provider'] . '.' . $definition['config_prefix'], - '@max_char' => ConfigEntityType::PREFIX_LENGTH, - ))); + $this->setExpectedException( + '\Drupal\Core\Config\ConfigPrefixLengthException', + "The configuration file name prefix {$definition['provider']}.{$definition['config_prefix']} exceeds the maximum character limit of " . ConfigEntityType::PREFIX_LENGTH + ); $this->assertEmpty($config_entity->getConfigPrefix()); } diff --git a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php index 8b9852c..022a232 100644 --- a/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/EntityUrlTest.php @@ -110,7 +110,7 @@ public function providerTestUrlInfo() { * @covers ::urlInfo * * @expectedException \Drupal\Core\Entity\Exception\UndefinedLinkTemplateException - * @expectedExceptionMessage No link template "canonical" found for the "test_entity_type" entity type + * @expectedExceptionMessage No link template 'canonical' found for the 'test_entity_type' entity type * * @dataProvider providerTestUrlInfoForInvalidLinkTemplate */ diff --git a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php index 0266229..2727cd1 100644 --- a/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/KeyValueStore/KeyValueEntityStorageTest.php @@ -466,7 +466,7 @@ public function testSaveInvalid() { * @covers ::doSave * * @expectedException \Drupal\Core\Entity\EntityStorageException - * @expectedExceptionMessage test_entity_type entity with ID foo already exists + * @expectedExceptionMessage 'test_entity_type' entity with ID 'foo' already exists */ public function testSaveDuplicate() { $this->setUpKeyValueEntityStorage(); diff --git a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php index 15b6ba0..330695e 100644 --- a/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/Sql/DefaultTableMappingTest.php @@ -291,7 +291,7 @@ public function testGetFieldColumnName($base_field, $columns, $column, $expected * The name of the column to be processed. * * @expectedException \Drupal\Core\Entity\Sql\SqlContentEntityStorageException - * @expectedExceptionMessage Column information not available for the "test" field. + * @expectedExceptionMessage Column information not available for the 'test' field. * * @covers ::getFieldColumnName * @@ -437,7 +437,7 @@ public function providerTestGetFieldTableName() { * Tests DefaultTableMapping::getFieldTableName() with an invalid parameter. * * @expectedException \Drupal\Core\Entity\Sql\SqlContentEntityStorageException - * @expectedExceptionMessage Table information not available for the "invalid_field_name" field. + * @expectedExceptionMessage Table information not available for the 'invalid_field_name' field. * * @covers ::getFieldTableName */ diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php index f1c538c..635eec3 100644 --- a/core/tests/Drupal/Tests/Core/UrlTest.php +++ b/core/tests/Drupal/Tests/Core/UrlTest.php @@ -779,7 +779,7 @@ public function providerTestToUriStringForRoute() { /** * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The route URI "route:" is invalid. + * @expectedExceptionMessage The route URI 'route:' is invalid. */ public function testFromRouteUriWithMissingRouteName() { Url::fromUri('route:');