diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 1109452..5df583c 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -185,90 +185,6 @@ const DRUPAL_KILOBYTE = 1024; /** - * Special system language code (only applicable to UI language). - * - * Refers to the language used in Drupal and module/theme source code. Drupal - * uses the built-in text for English by default, but if configured to allow - * translation/customization of English, we need to differentiate between the - * built-in language and the English translation. - */ -const LANGUAGE_SYSTEM = 'system'; - -/** - * The language code used when no language is explicitly assigned (yet). - * - * Should be used when language information is not available or cannot be - * determined. This special language code is useful when we know the data - * might have linguistic information, but we don't know the language. - * - * See http://www.w3.org/International/questions/qa-no-language#undetermined. - */ -const LANGUAGE_NOT_SPECIFIED = 'und'; - -/** - * The language code used when the marked object has no linguistic content. - * - * Should be used when we explicitly know that the data referred has no - * linguistic content. - * - * See http://www.w3.org/International/questions/qa-no-language#nonlinguistic. - */ -const LANGUAGE_NOT_APPLICABLE = 'zxx'; - -/** - * Language code referring to the default language of data, e.g. of an entity. - * - * @todo: Change value to differ from LANGUAGE_NOT_SPECIFIED once field API - * leverages the property API. - */ -const LANGUAGE_DEFAULT = 'und'; - -/** - * The language state when referring to configurable languages. - */ -const LANGUAGE_CONFIGURABLE = 1; - -/** - * The language state when referring to locked languages. - */ -const LANGUAGE_LOCKED = 2; - -/** - * The language state used when referring to all languages. - */ -const LANGUAGE_ALL = 3; - -/** - * The language state used when referring to the site's default language. - */ -const LANGUAGE_SITE_DEFAULT = 4; - -/** - * The type of language used to define the content language. - */ -const LANGUAGE_TYPE_CONTENT = 'language_content'; - -/** - * The type of language used to select the user interface. - */ -const LANGUAGE_TYPE_INTERFACE = 'language_interface'; - -/** - * The type of language used for URLs. - */ -const LANGUAGE_TYPE_URL = 'language_url'; - -/** - * Language written left to right. Possible value of $language->direction. - */ -const LANGUAGE_LTR = 0; - -/** - * Language written right to left. Possible value of $language->direction. - */ -const LANGUAGE_RTL = 1; - -/** * Indicates an error during check for PHP unicode support. */ const UNICODE_ERROR = -1; @@ -1526,7 +1442,7 @@ function t($string, array $args = array(), array $options = array()) { // Merge in default. if (empty($options['langcode'])) { - $options['langcode'] = language(LANGUAGE_TYPE_INTERFACE)->langcode; + $options['langcode'] = language(Language::TYPE_INTERFACE)->langcode; } if (empty($options['context'])) { $options['context'] = ''; @@ -1544,7 +1460,7 @@ function t($string, array $args = array(), array $options = array()) { $string = $custom_strings[$options['langcode']][$options['context']][$string]; } // Translate with locale module if enabled. - elseif ($options['langcode'] != LANGUAGE_SYSTEM && ($options['langcode'] != 'en' || variable_get('locale_translate_english', FALSE)) && function_exists('locale')) { + elseif ($options['langcode'] != Language::LANGCODE_SYSTEM && ($options['langcode'] != 'en' || variable_get('locale_translate_english', FALSE)) && function_exists('locale')) { $string = locale($string, $options['context'], $options['langcode']); } if (empty($args)) { @@ -2754,7 +2670,7 @@ function drupal_language_initialize() { * @see Drupal\Core\Language\LanguageManager * * @param string $type - * The type of language object needed, e.g. LANGUAGE_TYPE_INTERFACE. + * The type of language object needed, e.g. Language::TYPE_INTERFACE. */ function language($type) { $container = drupal_container(); @@ -2789,9 +2705,9 @@ function language_types_get_all() { */ function language_types_get_default() { return array( - LANGUAGE_TYPE_INTERFACE => TRUE, - LANGUAGE_TYPE_CONTENT => FALSE, - LANGUAGE_TYPE_URL => FALSE, + Language::TYPE_INTERFACE => TRUE, + Language::TYPE_CONTENT => FALSE, + Language::TYPE_URL => FALSE, ); } @@ -2813,13 +2729,14 @@ function language_multilingual() { * * @param $flags * (optional) Specifies the state of the languages that have to be returned. - * It can be: LANGUAGE_CONFIGURABLE, LANGUAGE_LOCKED, LANGUAGE_ALL. + * It can be: Language::STATE_CONFIGURABLE, Language::STATE_LOCKED, + * Language::STATE_ALL. * * @return array * An associative array of languages, keyed by the language code, ordered by * weight ascending and name ascending. */ -function language_list($flags = LANGUAGE_CONFIGURABLE) { +function language_list($flags = Language::STATE_CONFIGURABLE) { $languages = &drupal_static(__FUNCTION__); @@ -2855,7 +2772,7 @@ function language_list($flags = LANGUAGE_CONFIGURABLE) { $filtered_languages = array(); // Add the site's default language if flagged as allowed value. - if ($flags & LANGUAGE_SITE_DEFAULT) { + if ($flags & Language::STATE_SITE_DEFAULT) { $default = isset($default) ? $default : language_default(); // Rename the default language. $default->name = t("Site's default language (@lang_name)", array('@lang_name' => $default->name)); @@ -2863,7 +2780,7 @@ function language_list($flags = LANGUAGE_CONFIGURABLE) { } foreach ($languages as $langcode => $language) { - if (($language->locked && !($flags & LANGUAGE_LOCKED)) || (!$language->locked && !($flags & LANGUAGE_CONFIGURABLE))) { + if (($language->locked && !($flags & Language::STATE_LOCKED)) || (!$language->locked && !($flags & Language::STATE_CONFIGURABLE))) { continue; } $filtered_languages[$langcode] = $language; @@ -2890,13 +2807,13 @@ function language_default_locked_languages($weight = 0) { ); $languages = array(); - $languages[LANGUAGE_NOT_SPECIFIED] = new Language(array( - 'langcode' => LANGUAGE_NOT_SPECIFIED, + $languages[Language::LANGCODE_NOT_SPECIFIED] = new Language(array( + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'name' => t('Not specified'), 'weight' => ++$weight, ) + $locked_language); - $languages[LANGUAGE_NOT_APPLICABLE] = new Language(array( - 'langcode' => LANGUAGE_NOT_APPLICABLE, + $languages[Language::LANGCODE_NOT_APPLICABLE] = new Language(array( + 'langcode' => Language::LANGCODE_NOT_APPLICABLE, 'name' => t('Not applicable'), 'weight' => ++$weight, ) + $locked_language); @@ -2913,7 +2830,7 @@ function language_default_locked_languages($weight = 0) { * A fully-populated language object or FALSE. */ function language_load($langcode) { - $languages = language_list(LANGUAGE_ALL); + $languages = language_list(Language::STATE_ALL); return isset($languages[$langcode]) ? $languages[$langcode] : FALSE; } @@ -2927,7 +2844,7 @@ function language_load($langcode) { * The printed name of the language. */ function language_name($langcode) { - if ($langcode == LANGUAGE_NOT_SPECIFIED) { + if ($langcode == Language::LANGCODE_NOT_SPECIFIED) { return t('None'); } diff --git a/core/includes/common.inc b/core/includes/common.inc index 35056de..73132c2 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -1,6 +1,7 @@ langcode; + $langcode = $langcode ? $langcode : language(Language::TYPE_CONTENT)->langcode; $output = "\n"; $output .= ' ' . check_plain($title) . "\n"; @@ -1901,7 +1902,7 @@ function format_date($timestamp, $type = 'medium', $format = '', $timezone = NUL } if (empty($langcode)) { - $langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; + $langcode = language(Language::TYPE_INTERFACE)->langcode; } // Create a DrupalDateTime object from the timestamp and timezone. @@ -2049,7 +2050,7 @@ function datetime_default_format_type() { * - 'language': An optional language object. If the path being linked to is * internal to the site, $options['language'] is used to look up the alias * for the URL. If $options['language'] is omitted, the language will be - * obtained from language(LANGUAGE_TYPE_URL). + * obtained from language(Language::TYPE_URL). * - 'https': Whether this URL should point to a secure location. If not * defined, the current scheme is used, so the user stays on HTTP or HTTPS * respectively. TRUE enforces HTTPS and FALSE enforces HTTP, but HTTPS can @@ -2272,7 +2273,7 @@ function l($text, $path, array $options = array()) { // same request with different query parameters may yield a different page // (e.g., pagers). $is_active = ($path == current_path() || ($path == '' && drupal_is_front_page())); - $is_active = $is_active && (empty($options['language']) || $options['language']->langcode == language(LANGUAGE_TYPE_URL)->langcode); + $is_active = $is_active && (empty($options['language']) || $options['language']->langcode == language(Language::TYPE_URL)->langcode); $is_active = $is_active && (drupal_container()->get('request')->query->all() == $options['query']); if ($is_active) { $options['attributes']['class'][] = 'active'; diff --git a/core/includes/entity.inc b/core/includes/entity.inc index 1ffc7ba..3e30ea1 100644 --- a/core/includes/entity.inc +++ b/core/includes/entity.inc @@ -8,6 +8,7 @@ use Drupal\Core\Cache\CacheBackendInterface; use Drupal\Core\Entity\EntityStorageException; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; /** * Gets the entity definition for an entity type. @@ -58,7 +59,7 @@ function entity_info_cache_clear() { function entity_get_bundles($entity_type = NULL) { $bundles = &drupal_static(__FUNCTION__); if (!$bundles) { - $langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; + $langcode = language(Language::TYPE_INTERFACE)->langcode; if ($cache = cache()->get("entity_bundle_info:$langcode")) { $bundles = $cache->data; } @@ -116,7 +117,7 @@ function entity_invoke_bundle_hook($hook, $entity_type, $bundle, $bundle_new = N function entity_get_view_modes($entity_type = NULL) { $view_modes = &drupal_static(__FUNCTION__); if (!$view_modes) { - $langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; + $langcode = language(Language::TYPE_INTERFACE)->langcode; if ($cache = cache()->get("entity_view_mode_info:$langcode")) { $view_modes = $cache->data; } diff --git a/core/includes/language.inc b/core/includes/language.inc index 74d5752..dec14b4 100644 --- a/core/includes/language.inc +++ b/core/includes/language.inc @@ -7,6 +7,8 @@ * @see http://drupal.org/node/1497272 */ +use Drupal\Core\Language\Language; + /** * No language negotiation. The default language is used. */ @@ -46,7 +48,7 @@ * configurable: * @code * function mymodule_language_types_info_alter(&$language_types) { - * unset($language_types[LANGUAGE_TYPE_CONTENT]['fixed']); + * unset($language_types[Language::TYPE_CONTENT]['fixed']); * } * @endcode * @@ -528,18 +530,19 @@ function language_url_split_prefix($path, $languages) { * Returns the possible fallback languages ordered by language weight. * * @param - * (optional) The language type. Defaults to LANGUAGE_TYPE_CONTENT. + * (optional) The language type. Defaults to Language::TYPE_CONTENT. * * @return * An array of language codes. */ -function language_fallback_get_candidates($type = LANGUAGE_TYPE_CONTENT) { +function language_fallback_get_candidates($type = Language::TYPE_CONTENT) { $fallback_candidates = &drupal_static(__FUNCTION__); if (!isset($fallback_candidates)) { - // Get languages ordered by weight, add LANGUAGE_NOT_SPECIFIED at the end. + // Get languages ordered by weight, add Language::LANGCODE_NOT_SPECIFIED + // at the end. $fallback_candidates = array_keys(language_list()); - $fallback_candidates[] = LANGUAGE_NOT_SPECIFIED; + $fallback_candidates[] = Language::LANGCODE_NOT_SPECIFIED; // Let other modules hook in and add/change candidates. drupal_alter('language_fallback_candidates', $fallback_candidates); diff --git a/core/includes/menu.inc b/core/includes/menu.inc index e59615c..bf77b5a 100644 --- a/core/includes/menu.inc +++ b/core/includes/menu.inc @@ -9,6 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Language\Language; use Drupal\Core\Template\Attribute; use Drupal\menu_link\Plugin\Core\Entity\MenuLink; use Drupal\menu_link\MenuLinkStorageController; @@ -1091,7 +1092,7 @@ function menu_tree_output($tree) { */ function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) { $tree = &drupal_static(__FUNCTION__, array()); - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Use $mlid as a flag for whether the data being loaded is for the whole tree. $mlid = isset($link['mlid']) ? $link['mlid'] : 0; @@ -1202,7 +1203,7 @@ function menu_tree_get_path($menu_name) { function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail = FALSE) { $tree = &drupal_static(__FUNCTION__, array()); - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Check if the active trail has been overridden for this menu tree. $active_path = menu_tree_get_path($menu_name); @@ -1353,7 +1354,7 @@ function menu_build_tree($menu_name, array $parameters = array()) { function _menu_build_tree($menu_name, array $parameters = array()) { // Static cache of already built menu trees. $trees = &drupal_static(__FUNCTION__, array()); - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Build the cache id; sort parents to prevent duplicate storage and remove // default parameter values. diff --git a/core/includes/standard.inc b/core/includes/standard.inc index dcf4a39..7d53c84 100644 --- a/core/includes/standard.inc +++ b/core/includes/standard.inc @@ -5,6 +5,8 @@ * Provides a list of countries and languages based on web standards. */ +use Drupal\Core\Language\Language; + /** * Get an array of all country code => country name pairs. * @@ -306,7 +308,7 @@ function standard_language_list() { return array( 'af' => array('Afrikaans', 'Afrikaans'), 'am' => array('Amharic', 'አማርኛ'), - 'ar' => array('Arabic', /* Left-to-right marker "‭" */ 'العربية', LANGUAGE_RTL), + 'ar' => array('Arabic', /* Left-to-right marker "‭" */ 'العربية', Language::DIRECTION_RTL), 'ast' => array('Asturian', 'Asturianu'), 'az' => array('Azerbaijani', 'Azərbaycanca'), 'be' => array('Belarusian', 'Беларуская'), @@ -326,7 +328,7 @@ function standard_language_list() { 'es' => array('Spanish', 'Español'), 'et' => array('Estonian', 'Eesti'), 'eu' => array('Basque', 'Euskera'), - 'fa' => array('Persian, Farsi', /* Left-to-right marker "‭" */ 'فارسی', LANGUAGE_RTL), + 'fa' => array('Persian, Farsi', /* Left-to-right marker "‭" */ 'فارسی', Language::DIRECTION_RTL), 'fi' => array('Finnish', 'Suomi'), 'fil' => array('Filipino', 'Filipino'), 'fo' => array('Faeroese', 'Føroyskt'), @@ -335,7 +337,7 @@ function standard_language_list() { 'gl' => array('Galician', 'Galego'), 'gsw-berne' => array('Swiss German', 'Schwyzerdütsch'), 'gu' => array('Gujarati', 'ગુજરાતી'), - 'he' => array('Hebrew', /* Left-to-right marker "‭" */ 'עברית', LANGUAGE_RTL), + 'he' => array('Hebrew', /* Left-to-right marker "‭" */ 'עברית', Language::DIRECTION_RTL), 'hi' => array('Hindi', 'हिन्दी'), 'hr' => array('Croatian', 'Hrvatski'), 'ht' => array('Haitian Creole', 'Kreyòl ayisyen'), @@ -387,7 +389,7 @@ function standard_language_list() { 'tyv' => array('Tuvan', 'Тыва дыл'), 'ug' => array('Uyghur', 'Уйғур'), 'uk' => array('Ukrainian', 'Українська'), - 'ur' => array('Urdu', /* Left-to-right marker "‭" */ 'اردو', LANGUAGE_RTL), + 'ur' => array('Urdu', /* Left-to-right marker "‭" */ 'اردو', Language::DIRECTION_RTL), 'vi' => array('Vietnamese', 'Tiếng Việt'), 'xx-lolspeak' => array('Lolspeak', 'Lolspeak'), 'zh-hans' => array('Chinese, Simplified', '简体中文'), diff --git a/core/includes/theme.inc b/core/includes/theme.inc index 4c0e580..6b46a34 100644 --- a/core/includes/theme.inc +++ b/core/includes/theme.inc @@ -9,6 +9,7 @@ */ use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Language\Language; use Drupal\Core\Template\Attribute; use Drupal\Core\Utility\ThemeRegistry; @@ -1739,7 +1740,7 @@ function theme_link($variables) { * http://www.w3.org/TR/WCAG-TECHS/H42.html for more information. */ function theme_links($variables) { - $language_url = language(LANGUAGE_TYPE_URL); + $language_url = language(Language::TYPE_URL); $links = $variables['links']; $attributes = $variables['attributes']; @@ -2687,7 +2688,7 @@ function _template_preprocess_default_variables() { * @see html.tpl.php */ function template_preprocess_html(&$variables) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Compile a list of classes that are going to be applied to the body element. // This allows advanced theming based on context (home page, node of certain type, etc.). @@ -2819,7 +2820,7 @@ function template_preprocess_html(&$variables) { * @see page.tpl.php */ function template_preprocess_page(&$variables) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $site_config = config('system.site'); // Move some variables to the top level for themer convenience and template cleanliness. @@ -3003,7 +3004,7 @@ function theme_get_suggestions($args, $base, $delimiter = '__') { */ function template_preprocess_maintenance_page(&$variables) { global $theme; - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Retrieve the theme data to list all available regions. $theme_data = list_themes(); $regions = $theme_data[$theme]->info['regions']; diff --git a/core/lib/Drupal/Core/Condition/ConditionManager.php b/core/lib/Drupal/Core/Condition/ConditionManager.php index 2f4c060..2b32954 100644 --- a/core/lib/Drupal/Core/Condition/ConditionManager.php +++ b/core/lib/Drupal/Core/Condition/ConditionManager.php @@ -12,6 +12,7 @@ use Drupal\Core\Executable\ExecutableInterface; use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; +use Drupal\Core\Language\Language; use Drupal\Core\Plugin\Discovery\AlterDecorator; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\CacheDecorator; @@ -31,7 +32,7 @@ public function __construct(array $namespaces) { $this->discovery = new AnnotatedClassDiscovery('Core', 'Condition', $namespaces); $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->discovery = new AlterDecorator($this->discovery, 'condition_info'); - $this->discovery = new CacheDecorator($this->discovery, 'condition:' . language(LANGUAGE_TYPE_INTERFACE)->langcode); + $this->discovery = new CacheDecorator($this->discovery, 'condition:' . language(Language::TYPE_INTERFACE)->langcode); $this->factory = new DefaultFactory($this); } diff --git a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php index 6d60656..efc8669 100644 --- a/core/lib/Drupal/Core/Datetime/DrupalDateTime.php +++ b/core/lib/Drupal/Core/Datetime/DrupalDateTime.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Datetime; use Drupal\Component\Datetime\DateTimePlus; +use Drupal\Core\Language\Language; /** * Extends DateTimePlus(). @@ -59,7 +60,7 @@ class DrupalDateTime extends DateTimePlus { public function __construct($time = 'now', $timezone = NULL, $format = NULL, $settings = array()) { // We can set the langcode and country using Drupal values. - $settings['langcode'] = !empty($settings['langcode']) ? $settings['langcode'] : language(LANGUAGE_TYPE_INTERFACE)->langcode; + $settings['langcode'] = !empty($settings['langcode']) ? $settings['langcode'] : language(Language::TYPE_INTERFACE)->langcode; $settings['country'] = !empty($settings['country']) ? $settings['country'] : config('system.date')->get('country.default'); // Instantiate the parent class. diff --git a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php index e18edbd..28785de 100644 --- a/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php +++ b/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Language\Language; use PDO; use Drupal\Core\Entity\Query\QueryInterface; @@ -205,7 +206,7 @@ protected function mapFromStorageRecords(array $records, $load_revision = FALSE) // Skip the item delta and item value levels but let the field assign // the value as suiting. This avoids unnecessary array hierarchies and // saves memory here. - $values[$name][LANGUAGE_DEFAULT] = $value; + $values[$name][Language::LANGCODE_DEFAULT] = $value; } $bundle = $this->bundleKey ? $record->{$this->bundleKey} : FALSE; // Turn the record into an entity class. @@ -245,9 +246,9 @@ protected function attachPropertyData(array &$entities, $load_revision = FALSE) foreach ($data as $values) { $id = $values[$this->idKey]; - // Field values in default language are stored with LANGUAGE_DEFAULT as - // key. - $langcode = empty($values['default_langcode']) ? $values['langcode'] : LANGUAGE_DEFAULT; + // Field values in default language are stored with + // Language::LANGCODE_DEFAULT as key. + $langcode = empty($values['default_langcode']) ? $values['langcode'] : Language::LANGCODE_DEFAULT; $translation = $entities[$id]->getTranslation($langcode); foreach ($field_definition as $name => $definition) { diff --git a/core/lib/Drupal/Core/Entity/Entity.php b/core/lib/Drupal/Core/Entity/Entity.php index 785c81c..03238eb 100644 --- a/core/lib/Drupal/Core/Entity/Entity.php +++ b/core/lib/Drupal/Core/Entity/Entity.php @@ -27,7 +27,7 @@ class Entity implements IteratorAggregate, EntityInterface { * * @var string */ - public $langcode = LANGUAGE_NOT_SPECIFIED; + public $langcode = Language::LANGCODE_NOT_SPECIFIED; /** * The entity type. @@ -260,7 +260,7 @@ public function access($operation = 'view', \Drupal\user\Plugin\Core\Entity\User $method = $operation . 'Access'; return drupal_container()->get('plugin.manager.entity') ->getAccessController($this->entityType) - ->$method($this, LANGUAGE_DEFAULT, $account); + ->$method($this, Language::LANGCODE_DEFAULT, $account); } /** @@ -272,7 +272,7 @@ public function language() { $language = language_load($this->langcode); if (!$language) { // Make sure we return a proper language object. - $language = new Language(array('langcode' => LANGUAGE_NOT_SPECIFIED)); + $language = new Language(array('langcode' => Language::LANGCODE_NOT_SPECIFIED)); } return $language; } @@ -317,7 +317,7 @@ public function getTranslationLanguages($include_default = TRUE) { } } } - $languages = array_intersect_key(language_list(LANGUAGE_ALL), $languages); + $languages = array_intersect_key(language_list(Language::STATE_ALL), $languages); } if (empty($include_default)) { diff --git a/core/lib/Drupal/Core/Entity/EntityAccessController.php b/core/lib/Drupal/Core/Entity/EntityAccessController.php index 423281f..5d5f0bc 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessController.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessController.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Language\Language; use Drupal\user\Plugin\Core\Entity\User; /** @@ -24,7 +25,7 @@ class EntityAccessController implements EntityAccessControllerInterface { /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::viewAccess(). */ - public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function viewAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { if (($access = $this->getCache($entity, 'view', $langcode, $account)) !== NULL) { return $access; } @@ -36,7 +37,7 @@ public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::createAccess(). */ - public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function createAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { if (($access = $this->getCache($entity, 'create', $langcode, $account)) !== NULL) { return $access; } @@ -48,7 +49,7 @@ public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::updateAccess(). */ - public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function updateAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { if (($access = $this->getCache($entity, 'update', $langcode, $account)) !== NULL) { return $access; } @@ -60,7 +61,7 @@ public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::deleteAccess(). */ - public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function deleteAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { if (($access = $this->getCache($entity, 'delete', $langcode, $account)) !== NULL) { return $access; } @@ -79,7 +80,7 @@ public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU * 'delete'. * @param string $langcode * (optional) The language code for which to check access. Defaults to - * LANGUAGE_DEFAULT. + * Language::LANGCODE_DEFAULT. * @param \Drupal\user\Plugin\Core\Entity\User $account * (optional) The user for which to check access, or NULL to check access * for the current user. Defaults to NULL. @@ -88,7 +89,7 @@ public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU * TRUE if access was granted, FALSE if access was denied and NULL if access * could not be determined. */ - protected function access(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + protected function access(EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { // @todo Remove this once we can rely on $account. if (!$account) { $account = user_load($GLOBALS['user']->uid); @@ -116,7 +117,7 @@ protected function access(EntityInterface $entity, $operation, $langcode = LANGU * 'delete'. * @param string $langcode * (optional) The language code for which to check access. Defaults to - * LANGUAGE_DEFAULT. + * Language::LANGCODE_DEFAULT. * @param \Drupal\user\Plugin\Core\Entity\User $account * (optional) The user for which to check access, or NULL to check access * for the current user. Defaults to NULL. @@ -126,7 +127,7 @@ protected function access(EntityInterface $entity, $operation, $langcode = LANGU * is no record for the given user, operation, langcode and entity in the * cache. */ - protected function getCache(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + protected function getCache(EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { // @todo Remove this once we can rely on $account. if (!$account) { $account = user_load($GLOBALS['user']->uid); @@ -151,7 +152,7 @@ protected function getCache(EntityInterface $entity, $operation, $langcode = LAN * 'delete'. * @param string $langcode * (optional) The language code for which to check access. Defaults to - * LANGUAGE_DEFAULT. + * Language::LANGCODE_DEFAULT. * @param \Drupal\user\Plugin\Core\Entity\User $account * (optional) The user for which to check access, or NULL to check access * for the current user. Defaults to NULL. @@ -159,7 +160,7 @@ protected function getCache(EntityInterface $entity, $operation, $langcode = LAN * @return bool * TRUE if access was granted, FALSE otherwise. */ - protected function setCache($access, EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + protected function setCache($access, EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { // @todo Remove this once we can rely on $account. if (!$account) { $account = user_load($GLOBALS['user']->uid); diff --git a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php index 66730f6..4b441e9 100644 --- a/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php +++ b/core/lib/Drupal/Core/Entity/EntityAccessControllerInterface.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Language\Language; // @todo Don't depend on module level code. use Drupal\user\Plugin\Core\Entity\User; @@ -22,7 +23,7 @@ * The entity for which to check 'view' access. * @param string $langcode * (optional) The language code for which to check access. Defaults to - * LANGUAGE_DEFAULT. + * Language::LANGCODE_DEFAULT. * @param \Drupal\user\Plugin\Core\Entity\User $account * (optional) The user for which to check access, or NULL to check access * for the current user. Defaults to NULL. @@ -30,7 +31,7 @@ * @return bool * TRUE if access was granted, FALSE otherwise. */ - public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL); + public function viewAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL); /** * Checks 'create' access for a given entity or entity translation. @@ -39,7 +40,7 @@ public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT * The entity for which to check 'create' access. * @param string $langcode * (optional) The language code for which to check access. Defaults to - * LANGUAGE_DEFAULT. + * Language::LANGCODE_DEFAULT. * @param \Drupal\user\Plugin\Core\Entity\User $account * (optional) The user for which to check access, or NULL to check access * for the current user. Defaults to NULL. @@ -47,7 +48,7 @@ public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT * @return bool * TRUE if access was granted, FALSE otherwise. */ - public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL); + public function createAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL); /** * Checks 'update' access for a given entity or entity translation. @@ -56,7 +57,7 @@ public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU * The entity to check 'update' access. * @param string $langcode * (optional) The language code for which to check access. Defaults to - * LANGUAGE_DEFAULT. + * Language::LANGCODE_DEFAULT. * @param \Drupal\user\Plugin\Core\Entity\User $account * (optional) The user for which to check access, or NULL to check access * for the current user. Defaults to NULL. @@ -64,7 +65,7 @@ public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU * @return bool * TRUE if access was granted, FALSE otherwise. */ - public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL); + public function updateAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL); /** * Checks 'delete' access for a given entity or entity translation. @@ -73,7 +74,7 @@ public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU * The entity for which to check 'delete' access. * @param string $langcode * (optional) The language code for which to check access. Defaults to - * LANGUAGE_DEFAULT. + * Language::LANGCODE_DEFAULT. * @param \Drupal\user\Plugin\Core\Entity\User $account * (optional) The user for which to check access, or NULL to check access * for the current user. Defaults to NULL. @@ -81,7 +82,7 @@ public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU * @return bool * TRUE if access was granted, FALSE otherwise. */ - public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL); + public function deleteAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL); /** * Clears all cached access checks. diff --git a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php index 08be87c..dcb0596 100644 --- a/core/lib/Drupal/Core/Entity/EntityBCDecorator.php +++ b/core/lib/Drupal/Core/Entity/EntityBCDecorator.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Language\Language; use IteratorAggregate; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\TypedData\ContextAwareInterface; @@ -118,28 +119,29 @@ public function &__get($name) { // an entity field, provide direct access to the plain value. This makes it // possible to use the BC-decorator with properties; e.g., $node->title. if (isset($this->definitions[$name]) && empty($this->definitions[$name]['configurable'])) { - if (!isset($this->decorated->values[$name][LANGUAGE_DEFAULT])) { - $this->decorated->values[$name][LANGUAGE_DEFAULT][0]['value'] = NULL; + if (!isset($this->decorated->values[$name][Language::LANGCODE_DEFAULT])) { + $this->decorated->values[$name][Language::LANGCODE_DEFAULT][0]['value'] = NULL; } - if (is_array($this->decorated->values[$name][LANGUAGE_DEFAULT])) { + if (is_array($this->decorated->values[$name][Language::LANGCODE_DEFAULT])) { // This will work with all defined properties that have a single value. // We need to ensure the key doesn't matter. Mostly it's 'value' but // e.g. EntityReferenceItem uses target_id. - if (isset($this->decorated->values[$name][LANGUAGE_DEFAULT][0]) && count($this->decorated->values[$name][LANGUAGE_DEFAULT][0]) == 1) { - return $this->decorated->values[$name][LANGUAGE_DEFAULT][0][key($this->decorated->values[$name][LANGUAGE_DEFAULT][0])]; + if (isset($this->decorated->values[$name][Language::LANGCODE_DEFAULT][0]) && count($this->decorated->values[$name][Language::LANGCODE_DEFAULT][0]) == 1) { + return $this->decorated->values[$name][Language::LANGCODE_DEFAULT][0][key($this->decorated->values[$name][Language::LANGCODE_DEFAULT][0])]; } } - return $this->decorated->values[$name][LANGUAGE_DEFAULT]; + return $this->decorated->values[$name][Language::LANGCODE_DEFAULT]; } else { // Allow accessing field values in an entity default language other than - // LANGUAGE_DEFAULT by mapping the values to LANGUAGE_DEFAULT. This is - // necessary as EntityNG always keys default language values with - // LANGUAGE_DEFAULT while field API expects them to be keyed by langcode. + // Language::LANGCODE_DEFAULT by mapping the values to + // Language::LANGCODE_DEFAULT. This is necessary as EntityNG always keys + // default language values with Language::LANGCODE_DEFAULT while field API + // expects them to be keyed by langcode. $langcode = $this->decorated->language()->langcode; - if ($langcode != LANGUAGE_DEFAULT && isset($this->decorated->values[$name]) && is_array($this->decorated->values[$name])) { - if (isset($this->decorated->values[$name][LANGUAGE_DEFAULT]) && !isset($this->decorated->values[$name][$langcode])) { - $this->decorated->values[$name][$langcode] = &$this->decorated->values[$name][LANGUAGE_DEFAULT]; + if ($langcode != Language::LANGCODE_DEFAULT && isset($this->decorated->values[$name]) && is_array($this->decorated->values[$name])) { + if (isset($this->decorated->values[$name][Language::LANGCODE_DEFAULT]) && !isset($this->decorated->values[$name][$langcode])) { + $this->decorated->values[$name][$langcode] = &$this->decorated->values[$name][Language::LANGCODE_DEFAULT]; } } if (!isset($this->decorated->values[$name])) { @@ -160,18 +162,18 @@ public function __set($name, $value) { // an entity field, directly write to the plain value. This makes it // possible to use the BC-decorator with properties; e.g., $node->title. if ($defined && empty($this->definitions[$name]['configurable'])) { - $this->decorated->values[$name][LANGUAGE_DEFAULT] = $value; + $this->decorated->values[$name][Language::LANGCODE_DEFAULT] = $value; } else { if ($defined && is_array($value)) { // If field API sets a value with a langcode in entity language, move it - // to LANGUAGE_DEFAULT. + // to Language::LANGCODE_DEFAULT. // This is necessary as EntityNG always keys default language values - // with LANGUAGE_DEFAULT while field API expects them to be keyed by - // langcode. + // with Language::LANGCODE_DEFAULT while field API expects them to be + // keyed by langcode. foreach ($value as $langcode => $data) { - if ($langcode != LANGUAGE_DEFAULT && $langcode == $this->decorated->language()->langcode) { - $value[LANGUAGE_DEFAULT] = $data; + if ($langcode != Language::LANGCODE_DEFAULT && $langcode == $this->decorated->language()->langcode) { + $value[Language::LANGCODE_DEFAULT] = $data; unset($value[$langcode]); } } diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 4a03975..50c16a1 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -7,6 +7,8 @@ namespace Drupal\Core\Entity; +use Drupal\Core\Language\Language; + /** * Base class for entity form controllers. */ @@ -232,7 +234,7 @@ public function getFormLangcode(array $form_state) { // If no form langcode was provided we default to the current content // language and inspect existing translations to find a valid fallback, // if any. - $langcode = language(LANGUAGE_TYPE_CONTENT)->langcode; + $langcode = language(Language::TYPE_CONTENT)->langcode; $fallback = language_multilingual() ? language_fallback_get_candidates() : array(); while (!empty($langcode) && !isset($translations[$langcode])) { $langcode = array_shift($fallback); diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php index ef9bc89..0087011 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php @@ -56,7 +56,7 @@ public function validate(array $form, array &$form_state) { */ protected function submitEntityLanguage(array $form, array &$form_state) { // Nothing to do here, as original field values are always stored with - // LANGUAGE_DEFAULT language. + // Language::LANGCODE_DEFAULT language. // @todo Delete this method when merging EntityFormControllerNG with // EntityFormController. } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 43d0497..77b34f2 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -10,6 +10,7 @@ use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\Factory\DefaultFactory; use Drupal\Component\Plugin\Discovery\ProcessDecorator; +use Drupal\Core\Language\Language; use Drupal\Core\Plugin\Discovery\AlterDecorator; use Drupal\Core\Plugin\Discovery\CacheDecorator; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; @@ -175,7 +176,7 @@ public function __construct(array $namespaces) { $this->discovery = new InfoHookDecorator($this->discovery, 'entity_info'); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new AlterDecorator($this->discovery, 'entity_info'); - $this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . language(LANGUAGE_TYPE_INTERFACE)->langcode, 'cache', CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE)); + $this->discovery = new CacheDecorator($this->discovery, 'entity_info:' . language(Language::TYPE_INTERFACE)->langcode, 'cache', CacheBackendInterface::CACHE_PERMANENT, array('entity_info' => TRUE)); $this->factory = new DefaultFactory($this->discovery); } diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index 70ac362..7e65ca2 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -38,8 +38,8 @@ class EntityNG extends Entity { * The plain data values of the contained fields. * * This always holds the original, unchanged values of the entity. The values - * are keyed by language code, whereas LANGUAGE_DEFAULT is used for values in - * default language. + * are keyed by language code, whereas Language::LANGCODE_DEFAULT is used for + * values in default language. * * @todo: Add methods for getting original fields and for determining * changes. @@ -48,7 +48,7 @@ class EntityNG extends Entity { * @var array */ protected $values = array( - 'langcode' => array(LANGUAGE_DEFAULT => array(0 => array('value' => LANGUAGE_NOT_SPECIFIED))), + 'langcode' => array(Language::LANGCODE_DEFAULT => array(0 => array('value' => Language::LANGCODE_NOT_SPECIFIED))), ); /** @@ -83,8 +83,8 @@ public function __construct(array $values, $entity_type, $bundle = FALSE) { foreach ($values as $key => $value) { // If the key matches an existing property set the value to the property // to ensure non converted properties have the correct value. - if (property_exists($this, $key) && isset($value[LANGUAGE_DEFAULT])) { - $this->$key = $value[LANGUAGE_DEFAULT]; + if (property_exists($this, $key) && isset($value[Language::LANGCODE_DEFAULT])) { + $this->$key = $value[Language::LANGCODE_DEFAULT]; } $this->values[$key] = $value; } @@ -140,12 +140,12 @@ public function uuid() { * Implements \Drupal\Core\TypedData\ComplexDataInterface::get(). */ public function get($property_name) { - // Values in default language are always stored using the LANGUAGE_DEFAULT - // constant. - if (!isset($this->fields[$property_name][LANGUAGE_DEFAULT])) { - return $this->getTranslatedField($property_name, LANGUAGE_DEFAULT); + // Values in default language are always stored using the + // Language::LANGCODE_DEFAULT constant. + if (!isset($this->fields[$property_name][Language::LANGCODE_DEFAULT])) { + return $this->getTranslatedField($property_name, Language::LANGCODE_DEFAULT); } - return $this->fields[$property_name][LANGUAGE_DEFAULT]; + return $this->fields[$property_name][Language::LANGCODE_DEFAULT]; } /** @@ -161,9 +161,10 @@ protected function getTranslatedField($property_name, $langcode) { if (!$definition) { throw new InvalidArgumentException('Field ' . check_plain($property_name) . ' is unknown.'); } - // Non-translatable fields are always stored with LANGUAGE_DEFAULT as key. - if ($langcode != LANGUAGE_DEFAULT && empty($definition['translatable'])) { - $this->fields[$property_name][$langcode] = $this->getTranslatedField($property_name, LANGUAGE_DEFAULT); + // Non-translatable fields are always stored with + // Language::LANGCODE_DEFAULT as key. + if ($langcode != Language::LANGCODE_DEFAULT && empty($definition['translatable'])) { + $this->fields[$property_name][$langcode] = $this->getTranslatedField($property_name, Language::LANGCODE_DEFAULT); } else { $value = NULL; @@ -276,7 +277,7 @@ public function language() { } if (empty($language)) { // Make sure we return a proper language object. - $language = new Language(array('langcode' => LANGUAGE_NOT_SPECIFIED)); + $language = new Language(array('langcode' => Language::LANGCODE_NOT_SPECIFIED)); } return $language; } @@ -287,15 +288,15 @@ public function language() { * @return \Drupal\Core\Entity\Field\Type\EntityTranslation */ public function getTranslation($langcode, $strict = TRUE) { - // If the default language is LANGUAGE_NOT_SPECIFIED, the entity is not - // translatable, so we use LANGUAGE_DEFAULT. - if ($langcode == LANGUAGE_DEFAULT || in_array($this->language()->langcode, array(LANGUAGE_NOT_SPECIFIED, $langcode))) { + // If the default language is Language::LANGCODE_NOT_SPECIFIED, the entity + // is not translatable, so we use Language::LANGCODE_DEFAULT. + if ($langcode == Language::LANGCODE_DEFAULT || in_array($this->language()->langcode, array(Language::LANGCODE_NOT_SPECIFIED, $langcode))) { // No translation needed, return the entity. return $this; } // Check whether the language code is valid, thus is of an available // language. - $languages = language_list(LANGUAGE_ALL); + $languages = language_list(Language::STATE_ALL); if (!isset($languages[$langcode])) { throw new InvalidArgumentException("Unable to get translation for the invalid language '$langcode'."); } @@ -347,15 +348,15 @@ public function getTranslationLanguages($include_default = TRUE) { } } } - // We include the default language code instead of the LANGUAGE_DEFAULT - // constant. - unset($translations[LANGUAGE_DEFAULT]); + // We include the default language code instead of the + // Language::LANGCODE_DEFAULT constant. + unset($translations[Language::LANGCODE_DEFAULT]); if ($include_default) { $translations[$this->language()->langcode] = TRUE; } // Now load language objects based upon translation langcodes. - return array_intersect_key(language_list(LANGUAGE_ALL), $translations); + return array_intersect_key(language_list(Language::STATE_ALL), $translations); } /** @@ -404,15 +405,15 @@ public function updateOriginalValues() { public function &__get($name) { // If this is an entity field, handle it accordingly. We first check whether // a field object has been already created. If not, we create one. - if (isset($this->fields[$name][LANGUAGE_DEFAULT])) { - return $this->fields[$name][LANGUAGE_DEFAULT]; + if (isset($this->fields[$name][Language::LANGCODE_DEFAULT])) { + return $this->fields[$name][Language::LANGCODE_DEFAULT]; } // Inline getPropertyDefinition() to speed up things. if (!isset($this->fieldDefinitions)) { $this->getPropertyDefinitions(); } if (isset($this->fieldDefinitions[$name])) { - $return = $this->getTranslatedField($name, LANGUAGE_DEFAULT); + $return = $this->getTranslatedField($name, Language::LANGCODE_DEFAULT); return $return; } // Allow the EntityBCDecorator to directly access the values and fields. @@ -440,11 +441,11 @@ public function __set($name, $value) { } // If this is an entity field, handle it accordingly. We first check whether // a field object has been already created. If not, we create one. - if (isset($this->fields[$name][LANGUAGE_DEFAULT])) { - $this->fields[$name][LANGUAGE_DEFAULT]->setValue($value); + if (isset($this->fields[$name][Language::LANGCODE_DEFAULT])) { + $this->fields[$name][Language::LANGCODE_DEFAULT]->setValue($value); } elseif ($this->getPropertyDefinition($name)) { - $this->getTranslatedField($name, LANGUAGE_DEFAULT)->setValue($value); + $this->getTranslatedField($name, Language::LANGCODE_DEFAULT)->setValue($value); } // Else directly read/write plain values. That way, fields not yet converted // to the entity field API can always be directly accessed. diff --git a/core/lib/Drupal/Core/Entity/EntityRenderController.php b/core/lib/Drupal/Core/Entity/EntityRenderController.php index 53457aa..d202636 100644 --- a/core/lib/Drupal/Core/Entity/EntityRenderController.php +++ b/core/lib/Drupal/Core/Entity/EntityRenderController.php @@ -8,6 +8,8 @@ namespace Drupal\Core\Entity; use Drupal\entity\Plugin\Core\Entity\EntityDisplay; +use Drupal\Core\Language\Language; + /** * Base class for entity view controllers. */ @@ -94,7 +96,7 @@ public function view(EntityInterface $entity, $view_mode = 'full', $langcode = N */ public function viewMultiple(array $entities = array(), $view_mode = 'full', $langcode = NULL) { if (!isset($langcode)) { - $langcode = language(LANGUAGE_TYPE_CONTENT)->langcode; + $langcode = language(Language::TYPE_CONTENT)->langcode; } // Build the view modes and display objects. diff --git a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php index c5c491c..163d5c8 100644 --- a/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php +++ b/core/lib/Drupal/Core/EventSubscriber/FinishResponseSubscriber.php @@ -7,6 +7,7 @@ namespace Drupal\Core\EventSubscriber; +use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; use Symfony\Component\HttpKernel\KernelEvents; @@ -50,10 +51,10 @@ public function onRespond(FilterResponseEvent $event) { // Set the X-UA-Compatible HTTP header to force IE to use the most recent // rendering engine or use Chrome's frame rendering engine if available. - $response->headers->set('X-UA-Compatible', 'IE=edge,chrome=1', false); + $response->headers->set('X-UA-Compatible', 'IE=edge,chrome=1', FALSE); // Set the Content-language header. - $response->headers->set('Content-language', $this->languageManager->getLanguage(LANGUAGE_TYPE_INTERFACE)->langcode); + $response->headers->set('Content-language', $this->languageManager->getLanguage(Language::TYPE_INTERFACE)->langcode); // Because pages are highly dynamic, set the last-modified time to now // since the page is in fact being regenerated right now. diff --git a/core/lib/Drupal/Core/Language/Language.php b/core/lib/Drupal/Core/Language/Language.php index 4db85da..f51a225 100644 --- a/core/lib/Drupal/Core/Language/Language.php +++ b/core/lib/Drupal/Core/Language/Language.php @@ -20,13 +20,97 @@ class Language { // Properties within the Language are set up as the default language. public $name = ''; public $langcode = ''; - public $direction = LANGUAGE_LTR; + public $direction = Language::DIRECTION_LTR; public $weight = 0; public $default = FALSE; public $method_id = NULL; public $locked = FALSE; /** + * Special system language code (only applicable to UI language). + * + * Refers to the language used in Drupal and module/theme source code. Drupal + * uses the built-in text for English by default, but if configured to allow + * translation/customization of English, we need to differentiate between the + * built-in language and the English translation. + */ + const LANGCODE_SYSTEM = 'system'; + + /** + * The language code used when no language is explicitly assigned (yet). + * + * Should be used when language information is not available or cannot be + * determined. This special language code is useful when we know the data + * might have linguistic information, but we don't know the language. + * + * See http://www.w3.org/International/questions/qa-no-language#undetermined. + */ + const LANGCODE_NOT_SPECIFIED = 'und'; + + /** + * The language code used when the marked object has no linguistic content. + * + * Should be used when we explicitly know that the data referred has no + * linguistic content. + * + * See http://www.w3.org/International/questions/qa-no-language#nonlinguistic. + */ + const LANGCODE_NOT_APPLICABLE = 'zxx'; + + /** + * Language code referring to the default language of data, e.g. of an entity. + * + * @todo: Change value to differ from Language::LANGCODE_NOT_SPECIFIED once + * field API leverages the property API. + */ + const LANGCODE_DEFAULT = 'und'; + + /** + * The language state when referring to configurable languages. + */ + const STATE_CONFIGURABLE = 1; + + /** + * The language state when referring to locked languages. + */ + const STATE_LOCKED = 2; + + /** + * The language state used when referring to all languages. + */ + const STATE_ALL = 3; + + /** + * The language state used when referring to the site's default language. + */ + const STATE_SITE_DEFAULT = 4; + + /** + * The type of language used to define the content language. + */ + const TYPE_CONTENT = 'language_content'; + + /** + * The type of language used to select the user interface. + */ + const TYPE_INTERFACE = 'language_interface'; + + /** + * The type of language used for URLs. + */ + const TYPE_URL = 'language_url'; + + /** + * Language written left to right. Possible value of $language->direction. + */ + const DIRECTION_LTR = 0; + + /** + * Language written right to left. Possible value of $language->direction. + */ + const DIRECTION_RTL = 1; + + /** * Language constructor builds the default language object. * * @param array $options diff --git a/core/lib/Drupal/Core/Language/LanguageManager.php b/core/lib/Drupal/Core/Language/LanguageManager.php index fa94205..673e8e3 100644 --- a/core/lib/Drupal/Core/Language/LanguageManager.php +++ b/core/lib/Drupal/Core/Language/LanguageManager.php @@ -76,7 +76,7 @@ public function setRequest(Request $request) { * Returns a language object for the given type. * * @param string $type - * The language type, e.g. LANGUAGE_TYPE_INTERFACE. + * The language type, e.g. Language::TYPE_INTERFACE. * * @return \Drupal\Core\Language\Language * A language object for the given type. @@ -115,8 +115,8 @@ public function getLanguage($type) { * * @param string|null $type * (optional) The language type to reset as a string, e.g., - * LANGUAGE_TYPE_INTERFACE, or NULL to reset all language types. Defaults to - * NULL. + * Language::TYPE_INTERFACE, or NULL to reset all language types. Defaults + * to NULL. */ public function reset($type = NULL) { if (!isset($type)) { diff --git a/core/lib/Drupal/Core/Path/AliasManager.php b/core/lib/Drupal/Core/Path/AliasManager.php index fcd7fe5..0a133f1 100644 --- a/core/lib/Drupal/Core/Path/AliasManager.php +++ b/core/lib/Drupal/Core/Path/AliasManager.php @@ -8,6 +8,7 @@ namespace Drupal\Core\Path; use Drupal\Core\Database\Connection; +use Drupal\Core\Language\Language; use Drupal\Core\Language\LanguageManager; class AliasManager implements AliasManagerInterface { @@ -102,7 +103,7 @@ public function getSystemPath($path, $path_language = NULL) { // language. If we used a language different from the one conveyed by the // requested URL, we might end up being unable to check if there is a path // alias matching the URL path. - $path_language = $path_language ?: $this->languageManager->getLanguage(LANGUAGE_TYPE_URL)->langcode; + $path_language = $path_language ?: $this->languageManager->getLanguage(Language::TYPE_URL)->langcode; $original_path = $path; // Lookup the path alias first. if (!empty($path) && $source = $this->lookupPathSource($path, $path_language)) { @@ -120,7 +121,7 @@ public function getPathAlias($path, $path_language = NULL) { // language. If we used a language different from the one conveyed by the // requested URL, we might end up being unable to check if there is a path // alias matching the URL path. - $path_language = $path_language ?: $this->languageManager->getLanguage(LANGUAGE_TYPE_URL)->langcode; + $path_language = $path_language ?: $this->languageManager->getLanguage(Language::TYPE_URL)->langcode; $result = $path; if (!empty($path) && $alias = $this->lookupPathAlias($path, $path_language)) { $result = $alias; @@ -184,7 +185,7 @@ protected function lookupPathAlias($path, $langcode) { $args = array( ':system' => $this->preloadedPathLookups, ':langcode' => $langcode, - ':langcode_undetermined' => LANGUAGE_NOT_SPECIFIED, + ':langcode_undetermined' => Language::LANGCODE_NOT_SPECIFIED, ); // Always get the language-specific alias before the language-neutral // one. For example 'de' is less than 'und' so the order needs to be @@ -193,12 +194,12 @@ protected function lookupPathAlias($path, $langcode) { // the most recently created alias for each source. Subsequent queries // using fetchField() must use pid DESC to have the same effect. // For performance reasons, the query builder is not used here. - if ($langcode == LANGUAGE_NOT_SPECIFIED) { + if ($langcode == Language::LANGCODE_NOT_SPECIFIED) { // Prevent PDO from complaining about a token the query doesn't use. unset($args[':langcode']); $result = $this->connection->query('SELECT source, alias FROM {url_alias} WHERE source IN (:system) AND langcode = :langcode_undetermined ORDER BY pid ASC', $args); } - elseif ($langcode < LANGUAGE_NOT_SPECIFIED) { + elseif ($langcode < Language::LANGCODE_NOT_SPECIFIED) { $result = $this->connection->query('SELECT source, alias FROM {url_alias} WHERE source IN (:system) AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode ASC, pid ASC', $args); } else { @@ -224,14 +225,14 @@ protected function lookupPathAlias($path, $langcode) { $args = array( ':source' => $path, ':langcode' => $langcode, - ':langcode_undetermined' => LANGUAGE_NOT_SPECIFIED, + ':langcode_undetermined' => Language::LANGCODE_NOT_SPECIFIED, ); // See the queries above. - if ($langcode == LANGUAGE_NOT_SPECIFIED) { + if ($langcode == Language::LANGCODE_NOT_SPECIFIED) { unset($args[':langcode']); $alias = $this->connection->query("SELECT alias FROM {url_alias} WHERE source = :source AND langcode = :langcode_undetermined ORDER BY pid DESC", $args)->fetchField(); } - elseif ($langcode > LANGUAGE_NOT_SPECIFIED) { + elseif ($langcode > Language::LANGCODE_NOT_SPECIFIED) { $alias = $this->connection->query("SELECT alias FROM {url_alias} WHERE source = :source AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode DESC, pid DESC", $args)->fetchField(); } else { @@ -265,14 +266,14 @@ protected function lookupPathSource($path, $langcode) { $args = array( ':alias' => $path, ':langcode' => $langcode, - ':langcode_undetermined' => LANGUAGE_NOT_SPECIFIED, + ':langcode_undetermined' => Language::LANGCODE_NOT_SPECIFIED, ); // See the queries above. - if ($langcode == LANGUAGE_NOT_SPECIFIED) { + if ($langcode == Language::LANGCODE_NOT_SPECIFIED) { unset($args[':langcode']); $result = $this->connection->query("SELECT source FROM {url_alias} WHERE alias = :alias AND langcode = :langcode_undetermined ORDER BY pid DESC", $args); } - elseif ($langcode > LANGUAGE_NOT_SPECIFIED) { + elseif ($langcode > Language::LANGCODE_NOT_SPECIFIED) { $result = $this->connection->query("SELECT source FROM {url_alias} WHERE alias = :alias AND langcode IN (:langcode, :langcode_undetermined) ORDER BY langcode DESC, pid DESC", $args); } else { diff --git a/core/lib/Drupal/Core/Path/Path.php b/core/lib/Drupal/Core/Path/Path.php index a7fd55a..4a3410f 100644 --- a/core/lib/Drupal/Core/Path/Path.php +++ b/core/lib/Drupal/Core/Path/Path.php @@ -9,6 +9,7 @@ use Drupal\Core\Database\Database; use Drupal\Core\Database\Connection; +use Drupal\Core\Language\Language; /** * Defines a class for CRUD operations on path aliases. @@ -63,7 +64,7 @@ public function __construct(Connection $connection, AliasManager $alias_manager) * - pid: Unique path alias identifier. * - langcode: The language code of the alias. */ - public function save($source, $alias, $langcode = LANGUAGE_NOT_SPECIFIED, $pid = NULL) { + public function save($source, $alias, $langcode = Language::LANGCODE_NOT_SPECIFIED, $pid = NULL) { $fields = array( 'source' => $source, diff --git a/core/lib/Drupal/Core/TypedData/TranslatableInterface.php b/core/lib/Drupal/Core/TypedData/TranslatableInterface.php index f066b72..f86068a 100644 --- a/core/lib/Drupal/Core/TypedData/TranslatableInterface.php +++ b/core/lib/Drupal/Core/TypedData/TranslatableInterface.php @@ -40,8 +40,8 @@ public function getTranslationLanguages($include_default = TRUE); * AccessibleInterface, the translation object has to implement both as well. * * @param $langcode - * The language code of the translation to get or LANGUAGE_DEFAULT to get - * the data in default language. + * The language code of the translation to get or Language::LANGCODE_DEFAULT + * to get the data in default language. * @param $strict * (optional) If the data is complex, whether the translation should include * only translatable properties. If set to FALSE, untranslatable properties diff --git a/core/lib/Drupal/Core/Validation/ConstraintManager.php b/core/lib/Drupal/Core/Validation/ConstraintManager.php index e0444ae..a733aee 100644 --- a/core/lib/Drupal/Core/Validation/ConstraintManager.php +++ b/core/lib/Drupal/Core/Validation/ConstraintManager.php @@ -12,6 +12,7 @@ use Drupal\Component\Plugin\Discovery\StaticDiscoveryDecorator; use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; use Drupal\Component\Plugin\Discovery\ProcessDecorator; +use Drupal\Core\Language\Language; use Drupal\Core\Plugin\Discovery\AlterDecorator; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\CacheDecorator; @@ -48,7 +49,7 @@ public function __construct(array $namespaces) { $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->discovery = new ProcessDecorator($this->discovery, array($this, 'processDefinition')); $this->discovery = new AlterDecorator($this->discovery, 'validation_constraint'); - $this->discovery = new CacheDecorator($this->discovery, 'validation_constraints:' . language(LANGUAGE_TYPE_INTERFACE)->langcode); + $this->discovery = new CacheDecorator($this->discovery, 'validation_constraints:' . language(Language::TYPE_INTERFACE)->langcode); $this->factory = new DefaultFactory($this); } diff --git a/core/lib/Drupal/Core/Validation/DrupalTranslator.php b/core/lib/Drupal/Core/Validation/DrupalTranslator.php index 8700526..ecc6781 100644 --- a/core/lib/Drupal/Core/Validation/DrupalTranslator.php +++ b/core/lib/Drupal/Core/Validation/DrupalTranslator.php @@ -7,6 +7,7 @@ namespace Drupal\Core\Validation; +use Drupal\Core\Language\Language; use Symfony\Component\Translation\TranslatorInterface; /** @@ -55,7 +56,7 @@ public function setLocale($locale) { * Implements \Symfony\Component\Translation\TranslatorInterface::getLocale(). */ public function getLocale() { - return $this->locale ? $this->locale : language(LANGUAGE_TYPE_INTERFACE)->langcode; + return $this->locale ? $this->locale : language(Language::TYPE_INTERFACE)->langcode; } /** diff --git a/core/modules/aggregator/aggregator.install b/core/modules/aggregator/aggregator.install index 11447ee..7979eba 100644 --- a/core/modules/aggregator/aggregator.install +++ b/core/modules/aggregator/aggregator.install @@ -4,6 +4,7 @@ * @file * Install, update and uninstall functions for the aggregator module. */ +use Drupal\Core\Language\Language; /** * Implements hook_requirements(). @@ -319,7 +320,7 @@ function aggregator_update_8001() { 'length' => 12, 'not null' => TRUE, 'default' => '', - 'initial' => LANGUAGE_DEFAULT, + 'initial' => Language::LANGCODE_DEFAULT, )); db_add_field('aggregator_item', 'langcode', array( 'description' => 'The {language}.langcode of this feed item.', @@ -327,6 +328,6 @@ function aggregator_update_8001() { 'length' => 12, 'not null' => TRUE, 'default' => '', - 'initial' => LANGUAGE_DEFAULT, + 'initial' => Language::LANGCODE_DEFAULT, )); } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php b/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php index 97fb698..39ceb45 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormControllerNG; +use Drupal\Core\Language\Language; /** * Form controller for the aggregator feed edit forms. @@ -35,7 +36,7 @@ public function form(array $form, array &$form_state, EntityInterface $feed) { '#title' => t('Language'), '#type' => 'language_select', '#default_value' => $feed->language()->langcode, - '#languages' => LANGUAGE_ALL, + '#languages' => Language::STATE_ALL, ); $form['url'] = array( diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php index 9f51a71..1031dc4 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/AggregatorPluginManager.php @@ -9,6 +9,7 @@ use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\Factory\DefaultFactory; +use Drupal\Core\Language\Language; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\CacheDecorator; @@ -27,7 +28,7 @@ class AggregatorPluginManager extends PluginManagerBase { */ public function __construct($type, array $namespaces) { $this->discovery = new AnnotatedClassDiscovery('aggregator', $type, $namespaces); - $this->discovery = new CacheDecorator($this->discovery, "aggregator_$type:" . language(LANGUAGE_TYPE_INTERFACE)->langcode); + $this->discovery = new CacheDecorator($this->discovery, "aggregator_$type:" . language(Language::TYPE_INTERFACE)->langcode); $this->factory = new DefaultFactory($this->discovery); } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php index 71e36fc..f6cfbc2 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/AggregatorTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\aggregator\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; use Drupal\aggregator\Plugin\Core\Entity\Feed; @@ -355,7 +356,7 @@ function getHtmlEntitiesSample() { * (optional) The number of nodes to generate. Defaults to five. */ function createSampleNodes($count = 5) { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Post $count article nodes. for ($i = 0; $i < $count; $i++) { $edit = array(); diff --git a/core/modules/block/block.install b/core/modules/block/block.install index b1fc925..ab9eac7 100644 --- a/core/modules/block/block.install +++ b/core/modules/block/block.install @@ -5,6 +5,7 @@ * Install, update and uninstall functions for the block module. */ use Drupal\Component\Uuid\Uuid; +use Drupal\Core\Language\Language; /** * Implements hook_schema(). @@ -226,7 +227,7 @@ function block_update_8007() { 'uuid' => $uuid->generate(), 'info' => $block->info, 'revision_id' => $block->bid, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'type' => 'basic' ); $revision = array( @@ -304,7 +305,7 @@ function block_update_8008() { $found = TRUE; $data = array( - LANGUAGE_NOT_SPECIFIED => array( + Language::LANGCODE_NOT_SPECIFIED => array( array( 'format' => $block->format, 'value' => $block->body diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php index 014d54f..4eb12fe 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockAccessController.php @@ -8,6 +8,7 @@ namespace Drupal\custom_block; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\user\Plugin\Core\Entity\User; use Drupal\Core\Entity\EntityAccessController; @@ -19,28 +20,28 @@ class CustomBlockAccessController extends EntityAccessController { /** * Implements EntityAccessControllerInterface::viewAccess(). */ - public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function viewAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return TRUE; } /** * Implements EntityAccessControllerInterface::createAccess(). */ - public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function createAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer blocks', $account); } /** * Implements EntityAccessControllerInterface::updateAccess(). */ - public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function updateAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer blocks', $account); } /** * Implements EntityAccessControllerInterface::deleteAccess(). */ - public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function deleteAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer blocks', $account); } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php index 2c9845e..3bd8636 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php @@ -10,6 +10,7 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormControllerNG; +use Drupal\Core\Language\Language; /** * Form controller for the custom block edit forms. @@ -76,7 +77,7 @@ public function form(array $form, array &$form_state, EntityInterface $block) { '#title' => t('Language'), '#type' => 'language_select', '#default_value' => $block->langcode->value, - '#languages' => LANGUAGE_ALL, + '#languages' => Language::STATE_ALL, '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], ); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php index ba86c1b..c989682 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockCreationTest.php @@ -8,6 +8,7 @@ namespace Drupal\custom_block\Tests; use Drupal\Core\Database\Database; +use Drupal\Core\Language\Language; /** * Tests creating and saving a block. @@ -48,7 +49,7 @@ protected function setUp() { public function testCustomBlockCreation() { // Create a block. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit['info'] = $this->randomName(8); $edit["block_body[$langcode][0][value]"] = $this->randomName(16); $this->drupalPost('block/add/basic', $edit, t('Save')); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php index 1874ff3..b74de5c 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/CustomBlockSaveTest.php @@ -7,6 +7,8 @@ namespace Drupal\custom_block\Tests; +use Drupal\Core\Language\Language; + /** * Tests block save related functionality. */ @@ -49,7 +51,7 @@ public function testImport() { $info = $this->randomName(8); $block = array( 'info' => $info, - 'block_body' => array(LANGUAGE_NOT_SPECIFIED => array(array('value' => $this->randomName(32)))), + 'block_body' => array(Language::LANGCODE_NOT_SPECIFIED => array(array('value' => $this->randomName(32)))), 'type' => 'basic', 'id' => $test_id ); diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php index 04a5a62..3bb6c22 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/Tests/PageEditTest.php @@ -7,6 +7,8 @@ namespace Drupal\custom_block\Tests; +use Drupal\Core\Language\Language; + /** * Tests the block edit functionality. */ @@ -29,7 +31,7 @@ public static function getInfo() { public function testPageEdit() { $this->drupalLogin($this->adminUser); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $title_key = 'info'; $body_key = "block_body[$langcode][0][value]"; // Create block to edit. diff --git a/core/modules/block/lib/Drupal/block/BlockAccessController.php b/core/modules/block/lib/Drupal/block/BlockAccessController.php index 8e8a563..4f66186 100644 --- a/core/modules/block/lib/Drupal/block/BlockAccessController.php +++ b/core/modules/block/lib/Drupal/block/BlockAccessController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityAccessController; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\user\Plugin\Core\Entity\User; /** @@ -19,7 +20,7 @@ class BlockAccessController extends EntityAccessController { /** * Overrides \Drupal\Core\Entity\EntityAccessController::viewAccess(). */ - public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function viewAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return $entity->getPlugin()->access(); } diff --git a/core/modules/block/lib/Drupal/block/BlockBase.php b/core/modules/block/lib/Drupal/block/BlockBase.php index 4de2a59..8a419fd 100644 --- a/core/modules/block/lib/Drupal/block/BlockBase.php +++ b/core/modules/block/lib/Drupal/block/BlockBase.php @@ -8,6 +8,7 @@ namespace Drupal\block; use Drupal\Component\Plugin\PluginBase; +use Drupal\Core\Language\Language; use Drupal\block\Plugin\Core\Entity\Block; use Drupal\Component\Plugin\Discovery\DiscoveryInterface; @@ -339,7 +340,7 @@ public function form($form, &$form_state) { $configurable_language_types = language_types_get_configurable(); // Fetch languages. - $languages = language_list(LANGUAGE_ALL); + $languages = language_list(Language::STATE_ALL); foreach ($languages as $language) { // @todo $language->name is not wrapped with t(), it should be replaced // by CMI translation implementation. diff --git a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php index b102d4b..51de022 100644 --- a/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php +++ b/core/modules/block/lib/Drupal/block/Plugin/Type/BlockManager.php @@ -9,6 +9,7 @@ use Drupal\Component\Plugin\PluginManagerBase; use Drupal\Component\Plugin\Discovery\DerivativeDiscoveryDecorator; use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Language\Language; use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery; use Drupal\Core\Plugin\Discovery\AlterDecorator; use Drupal\Core\Plugin\Discovery\CacheDecorator; @@ -34,7 +35,7 @@ public function __construct(array $namespaces) { $this->discovery = new AnnotatedClassDiscovery('block', 'block', $namespaces); $this->discovery = new DerivativeDiscoveryDecorator($this->discovery); $this->discovery = new AlterDecorator($this->discovery, 'block'); - $this->discovery = new CacheDecorator($this->discovery, 'block_plugins:' . language(LANGUAGE_TYPE_INTERFACE)->langcode, 'block', CacheBackendInterface::CACHE_PERMANENT, array('block')); + $this->discovery = new CacheDecorator($this->discovery, 'block_plugins:' . language(Language::TYPE_INTERFACE)->langcode, 'block', CacheBackendInterface::CACHE_PERMANENT, array('block')); } /** diff --git a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php index 490e434..641e1ee 100644 --- a/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php +++ b/core/modules/block/lib/Drupal/block/Tests/BlockStorageUnitTest.php @@ -7,6 +7,7 @@ namespace Drupal\block\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\DrupalUnitTestBase; use Drupal\block_test\Plugin\block\block\TestHtmlIdBlock; use Drupal\Component\Plugin\Exception\PluginException; @@ -104,7 +105,7 @@ protected function createTests() { 'cache' => '1', 'admin_label' => t('Test block html id'), ), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, ); $this->assertIdentical($actual_properties, $expected_properties, 'The block properties are exported correctly.'); diff --git a/core/modules/book/book.admin.inc b/core/modules/book/book.admin.inc index ff5dac8..302ff1e 100644 --- a/core/modules/book/book.admin.inc +++ b/core/modules/book/book.admin.inc @@ -5,6 +5,7 @@ * Administration page callbacks for the Book module. */ +use Drupal\Core\Language\Language; use Drupal\Core\Entity\EntityInterface; /** @@ -112,7 +113,7 @@ function book_admin_edit_submit($form, &$form_state) { // Update the title if changed. if ($row['title']['#default_value'] != $values['title']) { $node = node_load($values['nid']); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $node->title = $values['title']; $node->book['link_title'] = $values['title']; $node->setNewRevision(); diff --git a/core/modules/book/book.module b/core/modules/book/book.module index 26f324e..186413f 100644 --- a/core/modules/book/book.module +++ b/core/modules/book/book.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\entity\Plugin\Core\Entity\EntityDisplay; use Drupal\Core\Template\Attribute; use Drupal\menu_link\Plugin\Core\Entity\MenuLink; @@ -1127,12 +1128,12 @@ function book_toc($bid, $depth_limit, $exclude = array()) { */ function template_preprocess_book_export_html(&$variables) { global $base_url; - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $variables['title'] = check_plain($variables['title']); $variables['base_url'] = $base_url; $variables['language'] = $language_interface; - $variables['language_rtl'] = ($language_interface->direction == LANGUAGE_RTL); + $variables['language_rtl'] = ($language_interface->direction == Language::DIRECTION_RTL); $variables['head'] = drupal_get_html_head(); // HTML element attributes. diff --git a/core/modules/book/lib/Drupal/book/Tests/BookTest.php b/core/modules/book/lib/Drupal/book/Tests/BookTest.php index 4601342..aad28a4 100644 --- a/core/modules/book/lib/Drupal/book/Tests/BookTest.php +++ b/core/modules/book/lib/Drupal/book/Tests/BookTest.php @@ -7,6 +7,7 @@ namespace Drupal\book\Tests; +use Drupal\Core\Language\Language; use Drupal\Core\Entity\EntityInterface; use Drupal\simpletest\WebTestBase; @@ -205,7 +206,7 @@ function checkBookNode(EntityInterface $node, $nodes, $previous = FALSE, $up = F // Check printer friendly version. $this->drupalGet('book/export/html/' . $node->nid); $this->assertText($node->label(), 'Printer friendly title found.'); - $this->assertRaw(check_markup($node->body[LANGUAGE_NOT_SPECIFIED][0]['value'], $node->body[LANGUAGE_NOT_SPECIFIED][0]['format']), 'Printer friendly body found.'); + $this->assertRaw(check_markup($node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['format']), 'Printer friendly body found.'); $number++; } @@ -242,7 +243,7 @@ function createBookNode($book_nid, $parent = NULL) { static $number = 0; // Used to ensure that when sorted nodes stay in same order. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $number . ' - SimpleTest test node ' . $this->randomName(10); $edit["body[$langcode][0][value]"] = 'SimpleTest test body ' . $this->randomName(32) . ' ' . $this->randomName(32); $edit['book[bid]'] = $book_nid; @@ -280,7 +281,7 @@ function testBookExport() { // Make sure each part of the book is there. foreach ($nodes as $node) { $this->assertText($node->label(), 'Node title found in printer friendly version.'); - $this->assertRaw(check_markup($node->body[LANGUAGE_NOT_SPECIFIED][0]['value'], $node->body[LANGUAGE_NOT_SPECIFIED][0]['format']), 'Node body found in printer friendly version.'); + $this->assertRaw(check_markup($node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['format']), 'Node body found in printer friendly version.'); } // Make sure we can't export an unsupported format. diff --git a/core/modules/ckeditor/ckeditor.admin.inc b/core/modules/ckeditor/ckeditor.admin.inc index 0dff9f5..8443833 100644 --- a/core/modules/ckeditor/ckeditor.admin.inc +++ b/core/modules/ckeditor/ckeditor.admin.inc @@ -5,6 +5,7 @@ * Callbacks and theming for the CKEditor toolbar configuration UI. */ +use Drupal\Core\Language\Language; use Drupal\Core\Template\Attribute; /** @@ -12,7 +13,7 @@ */ function template_preprocess_ckeditor_settings_toolbar(&$variables) { // Simplify the language direction information for toolbar buttons. - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $variables['language_direction'] = $language_interface->direction ? 'rtl' : 'ltr'; // Create lists of active and disabled buttons. diff --git a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php index 37a843e..08126f5 100644 --- a/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php +++ b/core/modules/ckeditor/lib/Drupal/ckeditor/Plugin/editor/editor/CKEditor.php @@ -7,6 +7,7 @@ namespace Drupal\ckeditor\Plugin\editor\editor; +use Drupal\Core\Language\Language; use Drupal\editor\Plugin\EditorBase; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; @@ -107,7 +108,7 @@ public function settingsFormSubmit(array $form, array &$form_state) { * Implements \Drupal\editor\Plugin\EditorInterface::getJSSettings(). */ public function getJSSettings(Editor $editor) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $settings = array(); $manager = drupal_container()->get('plugin.manager.ckeditor.plugin'); diff --git a/core/modules/comment/lib/Drupal/comment/CommentFormController.php b/core/modules/comment/lib/Drupal/comment/CommentFormController.php index a5e5f15..9d07e9c 100644 --- a/core/modules/comment/lib/Drupal/comment/CommentFormController.php +++ b/core/modules/comment/lib/Drupal/comment/CommentFormController.php @@ -10,6 +10,7 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormControllerNG; +use Drupal\Core\Language\Language; /** * Base for controller for comment forms. @@ -152,7 +153,7 @@ public function form(array $form, array &$form_state, EntityInterface $comment) // Make the comment inherit the current content language unless specifically // set. if ($comment->isNew()) { - $language_content = language(LANGUAGE_TYPE_CONTENT); + $language_content = language(Language::TYPE_CONTENT); $comment->langcode->value = $language_content->langcode; } diff --git a/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php b/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php index f6e9091..8e1ebd9 100644 --- a/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php +++ b/core/modules/comment/lib/Drupal/comment/Plugin/Core/Entity/Comment.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityNG; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Language\Language; /** * Defines the comment entity class. @@ -179,9 +180,9 @@ class Comment extends EntityNG implements ContentEntityInterface { * @var array */ protected $values = array( - 'langcode' => array(LANGUAGE_DEFAULT => array(0 => array('value' => LANGUAGE_NOT_SPECIFIED))), - 'name' => array(LANGUAGE_DEFAULT => array(0 => array('value' => ''))), - 'uid' => array(LANGUAGE_DEFAULT => array(0 => array('target_id' => 0))), + 'langcode' => array(Language::LANGCODE_DEFAULT => array(0 => array('value' => Language::LANGCODE_NOT_SPECIFIED))), + 'name' => array(Language::LANGCODE_DEFAULT => array(0 => array('value' => ''))), + 'uid' => array(Language::LANGCODE_DEFAULT => array(0 => array('target_id' => 0))), ); /** diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentAnonymousTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentAnonymousTest.php index 86f778a..f4ef8cf 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentAnonymousTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentAnonymousTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\Core\Language\Language; + /** * Tests anonymous commenting. */ @@ -66,7 +68,7 @@ function testAnonymous() { $this->assertTrue($this->commentExists($anonymous_comment2), 'Anonymous comment with contact info (optional) found.'); // Ensure anonymous users cannot post in the name of registered users. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array( 'name' => $this->admin_user->name, 'mail' => $this->randomName() . '@example.com', diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php index 1294de4..9213e16 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentCSSTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\Core\Language\Language; + /** * Tests comment CSS classes. */ @@ -54,8 +56,8 @@ function testCommentClasses() { 'uid' => $case['comment_uid'], 'status' => $case['comment_status'], 'subject' => $this->randomName(), - 'language' => LANGUAGE_NOT_SPECIFIED, - 'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array($this->randomName())), + 'language' => Language::LANGCODE_NOT_SPECIFIED, + 'comment_body' => array(Language::LANGCODE_NOT_SPECIFIED => array($this->randomName())), )); comment_save($comment); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php index bda6368..8d7a472 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentInterfaceTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\Core\Language\Language; + /** * Tests the comment module administrative and end-user-facing interfaces. */ @@ -24,7 +26,7 @@ public static function getInfo() { * Tests the comment interface. */ function testCommentInterface() { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Set comments to have subject and preview disabled. $this->drupalLogin($this->admin_user); $this->setCommentPreview(DRUPAL_DISABLED); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php index 35a935e..6dec469 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLanguageTest.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -89,7 +90,7 @@ function testCommentLanguage() { // language and interface language do not influence comment language, as // only content language has to. foreach (language_list() as $node_langcode => $node_language) { - $langcode_not_specified = LANGUAGE_NOT_SPECIFIED; + $langcode_not_specified = Language::LANGCODE_NOT_SPECIFIED; // Create "Article" content. $title = $this->randomName(); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php index 7907464..9dde79f 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentLinksTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\Core\Language\Language; + /** * Tests comment links based on environment configurations. */ @@ -146,8 +148,8 @@ function setEnvironment(array $info) { 'status' => COMMENT_PUBLISHED, 'subject' => $this->randomName(), 'hostname' => ip_address(), - 'langcode' => LANGUAGE_NOT_SPECIFIED, - 'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array($this->randomName())), + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, + 'comment_body' => array(Language::LANGCODE_NOT_SPECIFIED => array($this->randomName())), )); comment_save($comment); $this->comment = $comment; diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php index 8009f88..8e0f1d4 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentNewIndicatorTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\Core\Language\Language; + /** * Tests the 'new' marker on comments. */ @@ -53,8 +55,8 @@ public function testCommentNewCommentsIndicator() { 'status' => COMMENT_PUBLISHED, 'subject' => $this->randomName(), 'hostname' => ip_address(), - 'langcode' => LANGUAGE_NOT_SPECIFIED, - 'comment_body' => array(LANGUAGE_NOT_SPECIFIED => array($this->randomName())), + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, + 'comment_body' => array(Language::LANGCODE_NOT_SPECIFIED => array($this->randomName())), )); comment_save($comment); $this->drupalLogout(); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php index f898ab2..bf1cf6b 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentPreviewTest.php @@ -9,6 +9,8 @@ use Drupal\Core\Datetime\DrupalDateTime; +use Drupal\Core\Language\Language; + /** * Tests previewing comments. */ @@ -33,7 +35,7 @@ public static function getInfo() { * Tests comment preview. */ function testCommentPreview() { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // As admin user, configure comment settings. $this->drupalLogin($this->admin_user); @@ -78,7 +80,7 @@ function testCommentPreview() { * Tests comment edit, preview, and save. */ function testCommentEditPreviewSave() { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $web_user = $this->drupalCreateUser(array('access comments', 'post comments', 'skip comment approval')); $this->drupalLogin($this->admin_user); $this->setCommentPreview(DRUPAL_OPTIONAL); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php index c023c56..ef8ba41 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\comment\Tests; +use Drupal\Core\Language\Language; use Drupal\comment\Plugin\Core\Entity\Comment; use Drupal\simpletest\WebTestBase; @@ -91,7 +92,7 @@ function setUp() { * array of values to set contact info. */ function postComment($node, $comment, $subject = '', $contact = NULL) { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array(); $edit['comment_body[' . $langcode . '][0][value]'] = $comment; diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php index 6f2837a..3636f91 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentThreadingTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\Core\Language\Language; + /** * Tests comment threading. */ @@ -23,7 +25,7 @@ public static function getInfo() { * Tests the comment threading. */ function testCommentThreading() { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Set comments to have a subject with preview disabled. $this->drupalLogin($this->admin_user); $this->setCommentPreview(DRUPAL_DISABLED); diff --git a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php index 6bcc992..3a093ba 100644 --- a/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php +++ b/core/modules/comment/lib/Drupal/comment/Tests/CommentTokenReplaceTest.php @@ -7,6 +7,8 @@ namespace Drupal\comment\Tests; +use Drupal\Core\Language\Language; + /** * Tests comment token replacement in strings. */ @@ -23,7 +25,7 @@ public static function getInfo() { * Creates a comment, then tests the tokens generated from it. */ function testCommentTokenReplacement() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $url_options = array( 'absolute' => TRUE, 'language' => $language_interface, diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php index 90ae934..b455339 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigEntityTest.php @@ -8,6 +8,7 @@ namespace Drupal\config\Tests; use Drupal\Core\Entity\EntityMalformedException; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -41,7 +42,7 @@ function testCRUD() { $this->assertTrue($empty->uuid); $this->assertIdentical($empty->label, NULL); $this->assertIdentical($empty->style, NULL); - $this->assertIdentical($empty->langcode, LANGUAGE_NOT_SPECIFIED); + $this->assertIdentical($empty->langcode, Language::LANGCODE_NOT_SPECIFIED); // Verify ConfigEntity properties/methods on the newly created empty entity. $this->assertIdentical($empty->isNew(), TRUE); @@ -55,7 +56,7 @@ function testCRUD() { $this->assertTrue($empty->get('uuid')); $this->assertIdentical($empty->get('label'), NULL); $this->assertIdentical($empty->get('style'), NULL); - $this->assertIdentical($empty->get('langcode'), LANGUAGE_NOT_SPECIFIED); + $this->assertIdentical($empty->get('langcode'), Language::LANGCODE_NOT_SPECIFIED); // Verify Entity properties/methods on the newly created empty entity. $this->assertIdentical($empty->isNewRevision(), FALSE); @@ -97,7 +98,7 @@ function testCRUD() { $this->assertNotEqual($config_test->uuid, $empty->uuid); $this->assertIdentical($config_test->label, $expected['label']); $this->assertIdentical($config_test->style, $expected['style']); - $this->assertIdentical($config_test->langcode, LANGUAGE_NOT_SPECIFIED); + $this->assertIdentical($config_test->langcode, Language::LANGCODE_NOT_SPECIFIED); // Verify methods on the newly created entity. $this->assertIdentical($config_test->isNew(), TRUE); diff --git a/core/modules/contact/contact.install b/core/modules/contact/contact.install index d35abe9..e4f2302 100644 --- a/core/modules/contact/contact.install +++ b/core/modules/contact/contact.install @@ -6,6 +6,7 @@ */ use Drupal\Component\Uuid\Uuid; +use Drupal\Core\Language\Language; /** * Implements hook_install(). @@ -75,7 +76,7 @@ function contact_update_8001() { ->set('recipients', explode(',', $category->recipients)) ->set('reply', $category->reply) ->set('weight', $category->weight) - ->set('langcode', LANGUAGE_NOT_SPECIFIED) + ->set('langcode', Language::LANGCODE_NOT_SPECIFIED) ->save(); } diff --git a/core/modules/contact/lib/Drupal/contact/MessageFormController.php b/core/modules/contact/lib/Drupal/contact/MessageFormController.php index c4352cf..90b71af 100644 --- a/core/modules/contact/lib/Drupal/contact/MessageFormController.php +++ b/core/modules/contact/lib/Drupal/contact/MessageFormController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Language\Language; use Drupal\user\Plugin\Core\Entity\User; /** @@ -139,7 +140,7 @@ public function preview(array $form, array &$form_state) { public function save(array $form, array &$form_state) { global $user; - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $message = $this->getEntity($form_state); $sender = clone user_load($user->uid); diff --git a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php index 232d019..d3d6cb8 100644 --- a/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php +++ b/core/modules/datetime/lib/Drupal/datetime/Tests/DateTimeFieldTest.php @@ -7,6 +7,7 @@ namespace Drupal\datetime\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; use Drupal\Core\Datetime\DrupalDateTime; @@ -84,7 +85,7 @@ function testDateField() { // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.'); $this->assertNoFieldByName("{$this->field['field_name']}[$langcode][0][value][time]", '', 'Time element not found.'); @@ -153,7 +154,7 @@ function testDatetimeField() { // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.'); $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][time]", '', 'Time element found.'); @@ -235,7 +236,7 @@ function testDatelistWidget() { // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); $field_name = $this->field['field_name']; - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByXPath("//*[@id=\"edit-$field_name-$langcode-0-value-year\"]", NULL, 'Year element found.'); $this->assertOptionSelected("edit-$field_name-$langcode-0-value-year", '', 'No year selected.'); @@ -293,7 +294,7 @@ function testDefaultValue() { $date = new DrupalDateTime(); $date_format = 'Y-m-d'; $this->drupalGet('test-entity/add/test_bundle'); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // See if current date is set. We cannot test for the precise time because // it may be a few seconds between the time the comparison date is created @@ -326,7 +327,7 @@ function testInvalidField() { // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.'); $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][time]", '', 'Time element found.'); diff --git a/core/modules/dblog/lib/Drupal/dblog/Tests/DBLogTest.php b/core/modules/dblog/lib/Drupal/dblog/Tests/DBLogTest.php index 1769605..e2a4747 100644 --- a/core/modules/dblog/lib/Drupal/dblog/Tests/DBLogTest.php +++ b/core/modules/dblog/lib/Drupal/dblog/Tests/DBLogTest.php @@ -7,6 +7,7 @@ namespace Drupal\dblog\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; use SimpleXMLElement; @@ -309,7 +310,7 @@ private function doNode($type) { // Create a node using the form in order to generate an add content event // (which is not triggered by drupalCreateNode). $edit = $this->getContent($type); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $title = $edit["title"]; $this->drupalPost('node/add/' . $type, $edit, t('Save')); $this->assertResponse(200); @@ -367,7 +368,7 @@ private function doNode($type) { * Random content needed by various node types. */ private function getContent($type) { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; switch ($type) { case 'forum': $content = array( @@ -397,7 +398,7 @@ private function getContent($type) { * Random content needed by various node types. */ private function getContentUpdate($type) { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $content = array( "body[$langcode][0][value]" => $this->randomName(32), ); diff --git a/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php b/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php index 5a4faef..afe8af8 100644 --- a/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php +++ b/core/modules/edit/lib/Drupal/edit/Tests/MetadataGeneratorTest.php @@ -7,6 +7,7 @@ namespace Drupal\edit\Tests; +use Drupal\Core\Language\Language; use Drupal\edit\EditorSelector; use Drupal\edit\MetadataGenerator; use Drupal\edit\Plugin\EditorManager; @@ -103,9 +104,9 @@ function testSimpleEntityType() { // Verify metadata for field 1. $instance_1 = field_info_instance($entity->entityType(), $field_1_name, $entity->bundle()); - $metadata_1 = $this->metadataGenerator->generate($entity, $instance_1, LANGUAGE_NOT_SPECIFIED, 'default'); + $metadata_1 = $this->metadataGenerator->generate($entity, $instance_1, Language::LANGCODE_NOT_SPECIFIED, 'default'); $expected_1 = array( - 'access' => TRUE, + 'access' => TRUE, 'label' => 'Simple text field', 'editor' => 'direct', 'aria' => 'Entity entity_test 1, field Simple text field', @@ -114,7 +115,7 @@ function testSimpleEntityType() { // Verify metadata for field 2. $instance_2 = field_info_instance($entity->entityType(), $field_2_name, $entity->bundle()); - $metadata_2 = $this->metadataGenerator->generate($entity, $instance_2, LANGUAGE_NOT_SPECIFIED, 'default'); + $metadata_2 = $this->metadataGenerator->generate($entity, $instance_2, Language::LANGCODE_NOT_SPECIFIED, 'default'); $expected_2 = array( 'access' => TRUE, 'label' => 'Simple number field', @@ -170,7 +171,7 @@ function testEditorWithCustomMetadata() { // Verify metadata. $instance = field_info_instance($entity->entityType(), $field_name, $entity->bundle()); - $metadata = $this->metadataGenerator->generate($entity, $instance, LANGUAGE_NOT_SPECIFIED, 'default'); + $metadata = $this->metadataGenerator->generate($entity, $instance, Language::LANGCODE_NOT_SPECIFIED, 'default'); $expected = array( 'access' => TRUE, 'label' => 'Rich text field', diff --git a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php index 9e443f8..97181fc 100644 --- a/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php +++ b/core/modules/editor/lib/Drupal/editor/Tests/EditIntegrationTest.php @@ -7,6 +7,7 @@ namespace Drupal\editor\Tests; +use Drupal\Core\Language\Language; use Drupal\edit\EditorSelector; use Drupal\edit\MetadataGenerator; use Drupal\edit\Plugin\EditorManager; @@ -160,7 +161,7 @@ function testMetadata() { // Verify metadata. $instance = field_info_instance($entity->entityType(), $this->field_name, $entity->bundle()); - $metadata = $this->metadataGenerator->generate($entity, $instance, LANGUAGE_NOT_SPECIFIED, 'default'); + $metadata = $this->metadataGenerator->generate($entity, $instance, Language::LANGCODE_NOT_SPECIFIED, 'default'); $expected = array( 'access' => TRUE, 'label' => 'Long text field', @@ -188,7 +189,7 @@ function testGetUntransformedTextCommand() { // Verify AJAX response. $controller = new EditorController(); $request = new Request(); - $response = $controller->getUntransformedText($entity, $this->field_name, LANGUAGE_NOT_SPECIFIED, 'default'); + $response = $controller->getUntransformedText($entity, $this->field_name, Language::LANGCODE_NOT_SPECIFIED, 'default'); $expected = array( array( 'command' => 'editorGetUntransformedText', diff --git a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php index c719c97..6aa5f74 100644 --- a/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php +++ b/core/modules/email/lib/Drupal/email/Tests/EmailFieldTest.php @@ -7,6 +7,7 @@ namespace Drupal\email\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -71,7 +72,7 @@ function testEmailField() { // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value]", '', 'Widget found.'); $this->assertRaw('placeholder="example@example.com"'); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php index d7b2d84..a84961c 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceAutoCreateTest.php @@ -7,6 +7,7 @@ namespace Drupal\entity_reference\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -106,6 +107,6 @@ public function testAutoCreate() { $referencing_nid = key($result); $referencing_node = node_load($referencing_nid); - $this->assertEqual($referenced_nid, $referencing_node->test_field[LANGUAGE_NOT_SPECIFIED][0]['target_id'], 'Newly created node is referenced from the referencing node.'); + $this->assertEqual($referenced_nid, $referencing_node->test_field[Language::LANGCODE_NOT_SPECIFIED][0]['target_id'], 'Newly created node is referenced from the referencing node.'); } } diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php index cc089fb..4af4344 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceItemTest.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\Field\FieldInterface; use Drupal\Core\Entity\Field\FieldItemInterface; +use Drupal\Core\Language\Language; use Drupal\field\Tests\FieldUnitTestBase; /** @@ -43,14 +44,14 @@ public function setUp() { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => $this->randomName(), 'vid' => drupal_strtolower($this->randomName()), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $vocabulary->save(); $this->term = entity_create('taxonomy_term', array( 'name' => $this->randomName(), 'vid' => $vocabulary->id(), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $this->term->save(); @@ -90,7 +91,7 @@ public function testEntityReferenceItem() { $term2 = entity_create('taxonomy_term', array( 'name' => $this->randomName(), 'vid' => $this->term->vid, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $term2->save(); diff --git a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php index cf1c619..9ab172b 100644 --- a/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php +++ b/core/modules/entity_reference/lib/Drupal/entity_reference/Tests/EntityReferenceSelectionAccessTest.php @@ -7,6 +7,7 @@ namespace Drupal\entity_reference\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -385,7 +386,7 @@ public function testCommentHandler() { 'pid' => 0, 'status' => COMMENT_PUBLISHED, 'subject' => 'Comment Published <&>', - 'language' => LANGUAGE_NOT_SPECIFIED, + 'language' => Language::LANGCODE_NOT_SPECIFIED, ), 'published_unpublished' => array( 'nid' => $nodes['published']->nid, @@ -394,7 +395,7 @@ public function testCommentHandler() { 'pid' => 0, 'status' => COMMENT_NOT_PUBLISHED, 'subject' => 'Comment Unpublished <&>', - 'language' => LANGUAGE_NOT_SPECIFIED, + 'language' => Language::LANGCODE_NOT_SPECIFIED, ), 'unpublished_published' => array( 'nid' => $nodes['unpublished']->nid, @@ -403,7 +404,7 @@ public function testCommentHandler() { 'pid' => 0, 'status' => COMMENT_NOT_PUBLISHED, 'subject' => 'Comment Published on Unpublished node <&>', - 'language' => LANGUAGE_NOT_SPECIFIED, + 'language' => Language::LANGCODE_NOT_SPECIFIED, ), ); diff --git a/core/modules/field/field.default.inc b/core/modules/field/field.default.inc index 27ba32c..ab6b10e 100644 --- a/core/modules/field/field.default.inc +++ b/core/modules/field/field.default.inc @@ -12,6 +12,8 @@ * the corresponding field_attach_[operation]() function. */ +use Drupal\Core\Language\Language; + /** * Generic field validation handler. * @@ -73,9 +75,9 @@ function field_default_validate(EntityInterface $entity, $field, $instance, $lan */ function field_default_prepare_translation(EntityInterface $entity, $field, $instance, $langcode, &$items, EntityInterface $source_entity, $source_langcode) { $field_name = $field['field_name']; - // If the field is untranslatable keep using LANGUAGE_NOT_SPECIFIED. - if ($langcode == LANGUAGE_NOT_SPECIFIED) { - $source_langcode = LANGUAGE_NOT_SPECIFIED; + // If the field is untranslatable keep using Language::LANGCODE_NOT_SPECIFIED. + if ($langcode == Language::LANGCODE_NOT_SPECIFIED) { + $source_langcode = Language::LANGCODE_NOT_SPECIFIED; } if (isset($source_entity->{$field_name}[$source_langcode])) { $items = $source_entity->{$field_name}[$source_langcode]; diff --git a/core/modules/field/field.info.inc b/core/modules/field/field.info.inc index b422b47..e47b4cb 100644 --- a/core/modules/field/field.info.inc +++ b/core/modules/field/field.info.inc @@ -5,6 +5,7 @@ * Field Info API, providing information about available fields and field types. */ +use Drupal\Core\Language\Language; use Drupal\field\FieldInstance; use Drupal\field\FieldInfo; @@ -81,7 +82,7 @@ function field_info_cache_clear() { * @see _field_info_collate_types_reset() */ function _field_info_collate_types() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; diff --git a/core/modules/field/field.module b/core/modules/field/field.module index ea95f60..7271f8f 100644 --- a/core/modules/field/field.module +++ b/core/modules/field/field.module @@ -5,6 +5,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\Core\Template\Attribute; /* @@ -409,7 +410,7 @@ function field_populate_default_values(EntityInterface $entity, $langcode = NULL $langcode = $langcode ?: $entity->language()->langcode; foreach (field_info_instances($entity_type, $entity->bundle()) as $field_name => $instance) { $field = field_info_field($field_name); - $field_langcode = field_is_translatable($entity_type, $field) ? $langcode : LANGUAGE_NOT_SPECIFIED; + $field_langcode = field_is_translatable($entity_type, $field) ? $langcode : Language::LANGCODE_NOT_SPECIFIED; // We need to preserve existing values. if (empty($entity->{$field_name}) || !array_key_exists($field_langcode, $entity->{$field_name})) { $items = field_get_default_value($entity, $field, $instance, $field_langcode); diff --git a/core/modules/field/field.multilingual.inc b/core/modules/field/field.multilingual.inc index 8e5ee39..c0fd6bd 100644 --- a/core/modules/field/field.multilingual.inc +++ b/core/modules/field/field.multilingual.inc @@ -7,6 +7,8 @@ * Functions implementing Field API multilingual support. */ +use Drupal\Core\Language\Language; + /** * @defgroup field_language Field Language API * @{ @@ -19,11 +21,12 @@ * @endcode * Every field can hold a single or multiple value for each language code * belonging to the available language codes set: - * - For untranslatable fields this set only contains LANGUAGE_NOT_SPECIFIED. + * - For untranslatable fields this set only contains + * Language::LANGCODE_NOT_SPECIFIED. * - For translatable fields this set can contain any language code. By default * it is the list returned by field_content_languages(), which contains all - * installed languages with the addition of LANGUAGE_NOT_SPECIFIED. This - * default can be altered by modules implementing + * installed languages with the addition of Language::LANGCODE_NOT_SPECIFIED. + * This default can be altered by modules implementing * hook_field_available_languages_alter(). * * The available language codes for a particular field are returned by @@ -102,10 +105,10 @@ function field_language_delete() { * Collects the available language codes for the given entity type and field. * * If the given field has language support enabled, an array of available - * language codes will be returned, otherwise only LANGUAGE_NOT_SPECIFIED will - * be returned. Since the default value for a 'translatable' entity property is - * FALSE, we ensure that only entities that are able to handle translations - * actually get translatable fields. + * language codes will be returned, otherwise only + * Language::LANGCODE_NOT_SPECIFIED will be returned. Since the default value + * for a 'translatable' entity property is FALSE, we ensure that only entities + * that are able to handle translations actually get translatable fields. * * @param $entity_type * The type of the entity the field is attached to, e.g. 'node' or 'user'. @@ -125,7 +128,8 @@ function field_available_languages($entity_type, $field) { if (!isset($field_langcodes[$entity_type][$field_name])) { // If the field has language support enabled we retrieve an (alterable) list - // of enabled languages, otherwise we return just LANGUAGE_NOT_SPECIFIED. + // of enabled languages, otherwise we return just + // Language::LANGCODE_NOT_SPECIFIED. if (field_is_translatable($entity_type, $field)) { $langcodes = field_content_languages(); // Let other modules alter the available languages. @@ -134,7 +138,7 @@ function field_available_languages($entity_type, $field) { $field_langcodes[$entity_type][$field_name] = $langcodes; } else { - $field_langcodes[$entity_type][$field_name] = array(LANGUAGE_NOT_SPECIFIED); + $field_langcodes[$entity_type][$field_name] = array(Language::LANGCODE_NOT_SPECIFIED); } } @@ -182,7 +186,7 @@ function _field_language_suggestion($available_langcodes, $langcode_suggestion, * An array of language codes. */ function field_content_languages() { - return array_keys(language_list(LANGUAGE_ALL)); + return array_keys(language_list(Language::STATE_ALL)); } /** @@ -247,7 +251,7 @@ function field_valid_language($langcode, $default = TRUE) { if (in_array($langcode, $languages)) { return $langcode; } - return $default ? language_default()->langcode : language(LANGUAGE_TYPE_CONTENT)->langcode; + return $default ? language_default()->langcode : language(Language::TYPE_CONTENT)->langcode; } /** @@ -258,8 +262,8 @@ function field_valid_language($langcode, $default = TRUE) { * requested language code and the actual data available in the fields * themselves. * If there is no registered translation handler for the given entity type, the - * display language code to be used is just LANGUAGE_NOT_SPECIFIED, as no other - * language code is allowed by field_available_languages(). + * display language code to be used is just Language::LANGCODE_NOT_SPECIFIED, as + * no other language code is allowed by field_available_languages(). * * If translation handlers are found, we let modules provide alternative display * language codes for fields not having the requested language code available. @@ -299,9 +303,9 @@ function field_language(EntityInterface $entity, $field_name = NULL, $langcode = else { // If the field has a value for one of the locked languages, then use // that language for display. If not, the default one will be - // LANGUAGE_NOT_SPECIFIED. - $display_langcode[$instance['field_name']] = LANGUAGE_NOT_SPECIFIED; - foreach (language_list(LANGUAGE_LOCKED) as $language_locked) { + // Language::LANGCODE_NOT_SPECIFIED. + $display_langcode[$instance['field_name']] = Language::LANGCODE_NOT_SPECIFIED; + foreach (language_list(Language::STATE_LOCKED) as $language_locked) { if (isset($entity->{$instance['field_name']}[$language_locked->langcode])) { $display_langcode[$instance['field_name']] = $language_locked->langcode; break; diff --git a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php index c73260f..b0bd5ef 100644 --- a/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php +++ b/core/modules/field/lib/Drupal/field/Plugin/views/field/Field.php @@ -7,6 +7,7 @@ namespace Drupal\field\Plugin\views\field; +use Drupal\Core\Language\Language; use Drupal\Core\Entity\EntityInterface; use Drupal\views\ViewExecutable; use Drupal\views\Plugin\views\display\DisplayPluginBase; @@ -188,11 +189,12 @@ public function query($use_groupby = FALSE) { $field = $this->field_info; if (field_is_translatable($entity_type, $field) && !empty($this->view->display_handler->options['field_langcode_add_to_query'])) { $column = $this->tableAlias . '.langcode'; - // By the same reason as field_language the field might be LANGUAGE_NOT_SPECIFIED in reality so allow it as well. + // By the same reason as field_language the field might be + // Language::LANGCODE_NOT_SPECIFIED in reality so allow it as well. // @see this::field_langcode() $default_langcode = language_default()->langcode; $langcode = str_replace(array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'), - array(drupal_container()->get(LANGUAGE_TYPE_CONTENT)->langcode, $default_langcode), + array(drupal_container()->get(Language::TYPE_CONTENT)->langcode, $default_langcode), $this->view->display_handler->options['field_langcode']); $placeholder = $this->placeholder(); $langcode_fallback_candidates = array($langcode); @@ -201,7 +203,7 @@ public function query($use_groupby = FALSE) { $langcode_fallback_candidates = array_merge($langcode_fallback_candidates, language_fallback_get_candidates()); } else { - $langcode_fallback_candidates[] = LANGUAGE_NOT_SPECIFIED; + $langcode_fallback_candidates[] = Language::LANGCODE_NOT_SPECIFIED; } $this->query->add_where_expression(0, "$column IN($placeholder) OR $column IS NULL", array($placeholder => $langcode_fallback_candidates)); } @@ -846,19 +848,20 @@ function field_langcode(EntityInterface $entity) { if (field_is_translatable($entity->entityType(), $this->field_info)) { $default_langcode = language_default()->langcode; $langcode = str_replace(array('***CURRENT_LANGUAGE***', '***DEFAULT_LANGUAGE***'), - array(drupal_container()->get(LANGUAGE_TYPE_CONTENT)->langcode, $default_langcode), + array(drupal_container()->get(Language::TYPE_CONTENT)->langcode, $default_langcode), $this->view->display_handler->options['field_language']); // Give the Field Language API a chance to fallback to a different language - // (or LANGUAGE_NOT_SPECIFIED), in case the field has no data for the selected language. - // field_view_field() does this as well, but since the returned language code - // is used before calling it, the fallback needs to happen explicitly. + // (or Language::LANGCODE_NOT_SPECIFIED), in case the field has no data + // for the selected language. field_view_field() does this as well, but + // since the returned language code is used before calling it, the + // fallback needs to happen explicitly. $langcode = field_language($entity, $this->field_info['field_name'], $langcode); return $langcode; } else { - return LANGUAGE_NOT_SPECIFIED; + return Language::LANGCODE_NOT_SPECIFIED; } } diff --git a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php index 0635f38..daa2084 100644 --- a/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/BulkDeleteTest.php @@ -7,6 +7,8 @@ namespace Drupal\field\Tests; +use Drupal\Core\Language\Language; + /** * Unit test class for field bulk delete and batch purge functionality. */ @@ -125,7 +127,7 @@ function setUp() { for ($i = 0; $i < 10; $i++) { $entity = field_test_create_entity($id, $id, $bundle); foreach ($this->fields as $field) { - $entity->{$field['field_name']}[LANGUAGE_NOT_SPECIFIED] = $this->_generateTestFieldValues($field['cardinality']); + $entity->{$field['field_name']}[Language::LANGCODE_NOT_SPECIFIED] = $this->_generateTestFieldValues($field['cardinality']); } $entity->save(); $id++; diff --git a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php index f7c3a9c..94b28ad 100644 --- a/core/modules/field/lib/Drupal/field/Tests/CrudTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/CrudTest.php @@ -7,6 +7,7 @@ namespace Drupal\field\Tests; +use Drupal\Core\Language\Language; use Drupal\field\FieldException; use Exception; @@ -336,7 +337,7 @@ function testDeleteField() { // Save an entity with data for the field $entity = field_test_create_entity(0, 0, $instance['bundle']); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $values[0]['value'] = mt_rand(1, 127); $entity->{$field['field_name']}[$langcode] = $values; $entity_type = 'test_entity'; @@ -403,17 +404,17 @@ function testUpdateField() { $entity = field_test_create_entity($id, $id, $instance['bundle']); // Fill in the entity with more values than $cardinality. for ($i = 0; $i < 20; $i++) { - $entity->field_update[LANGUAGE_NOT_SPECIFIED][$i]['value'] = $i; + $entity->field_update[Language::LANGCODE_NOT_SPECIFIED][$i]['value'] = $i; } // Save the entity. field_attach_insert($entity); // Load back and assert there are $cardinality number of values. $entity = field_test_create_entity($id, $id, $instance['bundle']); field_attach_load('test_entity', array($id => $entity)); - $this->assertEqual(count($entity->field_update[LANGUAGE_NOT_SPECIFIED]), $field_definition['cardinality'], 'Cardinality is kept'); + $this->assertEqual(count($entity->field_update[Language::LANGCODE_NOT_SPECIFIED]), $field_definition['cardinality'], 'Cardinality is kept'); // Now check the values themselves. for ($delta = 0; $delta < $cardinality; $delta++) { - $this->assertEqual($entity->field_update[LANGUAGE_NOT_SPECIFIED][$delta]['value'], $delta, 'Value is kept'); + $this->assertEqual($entity->field_update[Language::LANGCODE_NOT_SPECIFIED][$delta]['value'], $delta, 'Value is kept'); } // Increase $cardinality and set the field cardinality to the new value. $field_definition['cardinality'] = ++$cardinality; diff --git a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php index 6f7d159..6c76344 100644 --- a/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/DisplayApiTest.php @@ -7,6 +7,8 @@ namespace Drupal\field\Tests; +use Drupal\Core\Language\Language; + class DisplayApiTest extends FieldUnitTestBase { public static function getInfo() { @@ -67,7 +69,7 @@ function setUp() { $this->values = $this->_generateTestFieldValues($this->cardinality); $this->entity = field_test_create_entity(); $this->is_new = TRUE; - $this->entity->{$this->field_name}[LANGUAGE_NOT_SPECIFIED] = $this->values; + $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED] = $this->values; field_test_entity_save($this->entity); } @@ -152,7 +154,7 @@ function testFieldViewValue() { $settings = field_info_formatter_settings('field_test_default'); $setting = $settings['test_formatter_setting']; foreach ($this->values as $delta => $value) { - $item = $this->entity->{$this->field_name}[LANGUAGE_NOT_SPECIFIED][$delta]; + $item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta]; $output = field_view_value($this->entity, $this->field_name, $item); $this->content = drupal_render($output); $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); @@ -168,7 +170,7 @@ function testFieldViewValue() { $setting = $display['settings']['test_formatter_setting_multiple']; $array = array(); foreach ($this->values as $delta => $value) { - $item = $this->entity->{$this->field_name}[LANGUAGE_NOT_SPECIFIED][$delta]; + $item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta]; $output = field_view_value($this->entity, $this->field_name, $item, $display); $this->content = drupal_render($output); $this->assertText($setting . '|0:' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); @@ -184,7 +186,7 @@ function testFieldViewValue() { $setting = $display['settings']['test_formatter_setting_additional']; $array = array(); foreach ($this->values as $delta => $value) { - $item = $this->entity->{$this->field_name}[LANGUAGE_NOT_SPECIFIED][$delta]; + $item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta]; $output = field_view_value($this->entity, $this->field_name, $item, $display); $this->content = drupal_render($output); $this->assertText($setting . '|' . $value['value'] . '|' . ($value['value'] + 1), format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); @@ -194,7 +196,7 @@ function testFieldViewValue() { // used. $setting = $this->display_options['teaser']['settings']['test_formatter_setting']; foreach ($this->values as $delta => $value) { - $item = $this->entity->{$this->field_name}[LANGUAGE_NOT_SPECIFIED][$delta]; + $item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta]; $output = field_view_value($this->entity, $this->field_name, $item, 'teaser'); $this->content = drupal_render($output); $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); @@ -204,7 +206,7 @@ function testFieldViewValue() { // are used. $setting = $this->display_options['default']['settings']['test_formatter_setting']; foreach ($this->values as $delta => $value) { - $item = $this->entity->{$this->field_name}[LANGUAGE_NOT_SPECIFIED][$delta]; + $item = $this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED][$delta]; $output = field_view_value($this->entity, $this->field_name, $item, 'unknown_view_mode'); $this->content = drupal_render($output); $this->assertText($setting . '|' . $value['value'], format_string('Value @delta was displayed with expected setting.', array('@delta' => $delta))); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php index 1ec87cf..208864c 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachOtherTest.php @@ -7,6 +7,7 @@ namespace Drupal\field\Tests; +use Drupal\Core\Language\Language; use Drupal\field\FieldValidationException; /** @@ -34,7 +35,7 @@ function testFieldAttachView() { $entity_type = 'test_entity'; $entity_init = field_test_create_entity(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $options = array('field_name' => $this->field_name_2); // Populate values to be displayed. @@ -181,7 +182,7 @@ function testFieldAttachView() { */ function testFieldAttachPrepareViewMultiple() { $entity_type = 'test_entity'; - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Set the instance to be hidden. $display = entity_get_display('test_entity', 'test_bundle', 'full') @@ -237,7 +238,7 @@ function testFieldAttachPrepareViewMultiple() { function testFieldAttachCache() { // Initialize random values and a test entity. $entity_init = field_test_create_entity(1, 1, $this->instance['bundle']); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $values = $this->_generateTestFieldValues($this->field['cardinality']); // Non-cacheable entity type. @@ -340,7 +341,7 @@ function testFieldAttachValidate() { $entity_type = 'test_entity'; $entity = field_test_create_entity(0, 0, $this->instance['bundle']); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Set up all but one values of the first field to generate errors. $values = array(); @@ -432,7 +433,7 @@ function testFieldAttachForm() { $entity_type = 'test_entity'; $entity = field_test_create_entity(0, 0, $this->instance['bundle']); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // When generating form for all fields. $form = array(); @@ -472,7 +473,7 @@ function testFieldAttachExtractFormValues() { $entity_type = 'test_entity'; $entity_init = field_test_create_entity(0, 0, $this->instance['bundle']); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Build the form for all fields. $form = array(); diff --git a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php index 9ec10f3..e53f5e6 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FieldAttachStorageTest.php @@ -7,6 +7,8 @@ namespace Drupal\field\Tests; +use Drupal\Core\Language\Language; + /** * Unit test class for storage-related field_attach_* functions. * @@ -38,7 +40,7 @@ function testFieldAttachSaveLoad() { // field_test_field_load() in field_test.module). $this->instance['settings']['test_hook_field_load'] = TRUE; field_update_instance($this->instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $entity_type = 'test_entity'; $values = array(); @@ -95,7 +97,7 @@ function testFieldAttachSaveLoad() { */ function testFieldAttachLoadMultiple() { $entity_type = 'test_entity'; - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Define 2 bundles. $bundles = array( @@ -171,7 +173,7 @@ function testFieldAttachLoadMultiple() { */ function testFieldAttachSaveLoadDifferentStorage() { $entity_type = 'test_entity'; - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create two fields using different storage backends, and their instances. $fields = array( @@ -265,7 +267,7 @@ function testFieldStorageDetailsAlter() { function testFieldAttachSaveMissingData() { $entity_type = 'test_entity'; $entity_init = field_test_create_entity(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Insert: Field is missing. $entity = clone($entity_init); @@ -348,7 +350,7 @@ function testFieldAttachSaveMissingDataDefaultValue() { // Verify that fields are populated with default values. $entity_type = 'test_entity'; $entity_init = field_test_create_entity(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $default = field_test_default_value($entity_init, $this->field, $this->instance); $this->assertEqual($entity_init->{$this->field_name}[$langcode], $default, 'Default field value correctly populated.'); @@ -383,7 +385,7 @@ function testFieldAttachSaveMissingDataDefaultValue() { */ function testFieldAttachDelete() { $entity_type = 'test_entity'; - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $rev[0] = field_test_create_entity(0, 0, $this->instance['bundle']); // Create revision 0 @@ -447,7 +449,7 @@ function testEntityCreateRenameBundle() { // Save an entity with data in the field. $entity = field_test_create_entity(0, 0, $this->instance['bundle']); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $values = $this->_generateTestFieldValues($this->field['cardinality']); $entity->{$this->field_name}[$langcode] = $values; $entity_type = 'test_entity'; @@ -504,7 +506,7 @@ function testEntityDeleteBundle() { // Save an entity with data for both fields $entity = field_test_create_entity(0, 0, $this->instance['bundle']); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $values = $this->_generateTestFieldValues($this->field['cardinality']); $entity->{$this->field_name}[$langcode] = $values; $entity->{$field_name}[$langcode] = $this->_generateTestFieldValues(1); diff --git a/core/modules/field/lib/Drupal/field/Tests/FormTest.php b/core/modules/field/lib/Drupal/field/Tests/FormTest.php index fcda223..23e52da 100644 --- a/core/modules/field/lib/Drupal/field/Tests/FormTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/FormTest.php @@ -7,6 +7,8 @@ namespace Drupal\field\Tests; +use Drupal\Core\Language\Language; + class FormTest extends FieldTestBase { /** @@ -59,7 +61,7 @@ function testFieldFormSingle() { $this->instance['field_name'] = $this->field_name; field_create_field($this->field); field_create_instance($this->instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); @@ -125,7 +127,7 @@ function testFieldFormDefaultValue() { $this->instance['default_value'] = array(array('value' => $default)); field_create_field($this->field); field_create_instance($this->instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); @@ -149,7 +151,7 @@ function testFieldFormSingleRequired() { $this->instance['required'] = TRUE; field_create_field($this->field); field_create_instance($this->instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Submit with missing required value. $edit = array(); @@ -187,7 +189,7 @@ function testFieldFormUnlimited() { $this->instance['field_name'] = $this->field_name; field_create_field($this->field); field_create_instance($this->instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Display creation form -> 1 widget. $this->drupalGet('test-entity/add/test_bundle'); @@ -267,7 +269,7 @@ function testFieldFormMultivalueWithRequiredRadio() { $this->instance['field_name'] = $this->field_name; field_create_field($this->field); field_create_instance($this->instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Add a required radio field. field_create_field(array( @@ -309,7 +311,7 @@ function testFieldFormJSAddMore() { $this->instance['field_name'] = $this->field_name; field_create_field($this->field); field_create_instance($this->instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Display creation form -> 1 widget. $this->drupalGet('test-entity/add/test_bundle'); @@ -369,7 +371,7 @@ function testFieldFormMultipleWidget() { $this->instance['widget']['type'] = 'test_field_widget_multiple'; field_create_field($this->field); field_create_instance($this->instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); @@ -424,7 +426,7 @@ function testFieldFormAccess() { field_create_field($field_no_access); field_create_instance($instance_no_access); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Test that the form structure includes full information for each delta // apart from #access. @@ -486,14 +488,14 @@ function testNestedFieldForm() { // Create two entities. $entity_1 = field_test_create_entity(1, 1); $entity_1->is_new = TRUE; - $entity_1->field_single[LANGUAGE_NOT_SPECIFIED][] = array('value' => 0); - $entity_1->field_unlimited[LANGUAGE_NOT_SPECIFIED][] = array('value' => 1); + $entity_1->field_single[Language::LANGCODE_NOT_SPECIFIED][] = array('value' => 0); + $entity_1->field_unlimited[Language::LANGCODE_NOT_SPECIFIED][] = array('value' => 1); field_test_entity_save($entity_1); $entity_2 = field_test_create_entity(2, 2); $entity_2->is_new = TRUE; - $entity_2->field_single[LANGUAGE_NOT_SPECIFIED][] = array('value' => 10); - $entity_2->field_unlimited[LANGUAGE_NOT_SPECIFIED][] = array('value' => 11); + $entity_2->field_single[Language::LANGCODE_NOT_SPECIFIED][] = array('value' => 10); + $entity_2->field_unlimited[Language::LANGCODE_NOT_SPECIFIED][] = array('value' => 11); field_test_entity_save($entity_2); // Display the 'combined form'. @@ -516,10 +518,10 @@ function testNestedFieldForm() { field_cache_clear(); $entity_1 = field_test_create_entity(1); $entity_2 = field_test_create_entity(2); - $this->assertFieldValues($entity_1, 'field_single', LANGUAGE_NOT_SPECIFIED, array(1)); - $this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NOT_SPECIFIED, array(2, 3)); - $this->assertFieldValues($entity_2, 'field_single', LANGUAGE_NOT_SPECIFIED, array(11)); - $this->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NOT_SPECIFIED, array(12, 13)); + $this->assertFieldValues($entity_1, 'field_single', Language::LANGCODE_NOT_SPECIFIED, array(1)); + $this->assertFieldValues($entity_1, 'field_unlimited', Language::LANGCODE_NOT_SPECIFIED, array(2, 3)); + $this->assertFieldValues($entity_2, 'field_single', Language::LANGCODE_NOT_SPECIFIED, array(11)); + $this->assertFieldValues($entity_2, 'field_unlimited', Language::LANGCODE_NOT_SPECIFIED, array(12, 13)); // Submit invalid values and check that errors are reported on the // correct widgets. @@ -547,8 +549,8 @@ function testNestedFieldForm() { ); $this->drupalPost('test-entity/nested/1/2', $edit, t('Save')); field_cache_clear(); - $this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NOT_SPECIFIED, array(3, 2)); - $this->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NOT_SPECIFIED, array(13, 12)); + $this->assertFieldValues($entity_1, 'field_unlimited', Language::LANGCODE_NOT_SPECIFIED, array(3, 2)); + $this->assertFieldValues($entity_2, 'field_unlimited', Language::LANGCODE_NOT_SPECIFIED, array(13, 12)); // Test the 'add more' buttons. Only Ajax submission is tested, because // the two 'add more' buttons present in the form have the same #value, @@ -574,7 +576,7 @@ function testNestedFieldForm() { // Save the form and check values are saved correclty. $this->drupalPost(NULL, array(), t('Save')); field_cache_clear(); - $this->assertFieldValues($entity_1, 'field_unlimited', LANGUAGE_NOT_SPECIFIED, array(3, 2)); - $this->assertFieldValues($entity_2, 'field_unlimited', LANGUAGE_NOT_SPECIFIED, array(13, 14, 15)); + $this->assertFieldValues($entity_1, 'field_unlimited', Language::LANGCODE_NOT_SPECIFIED, array(3, 2)); + $this->assertFieldValues($entity_2, 'field_unlimited', Language::LANGCODE_NOT_SPECIFIED, array(13, 14, 15)); } } diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php index 609d70f..7e5fcb3 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationTest.php @@ -97,7 +97,7 @@ function testFieldAvailableLanguages() { $this->field['translatable'] = FALSE; field_update_field($this->field); $available_langcodes = field_available_languages($this->entity_type, $this->field); - $this->assertTrue(count($available_langcodes) == 1 && $available_langcodes[0] === LANGUAGE_NOT_SPECIFIED, 'For untranslatable fields only LANGUAGE_NOT_SPECIFIED is available.'); + $this->assertTrue(count($available_langcodes) == 1 && $available_langcodes[0] === Language::LANGCODE_NOT_SPECIFIED, 'For untranslatable fields only Language::LANGCODE_NOT_SPECIFIED is available.'); } /** @@ -342,12 +342,12 @@ function testFieldDisplayLanguage() { $entity->{$field_name}[$langcode] = $this->_generateTestFieldValues($field['cardinality']); // If the langcode is one of the locked languages, then that one // will also be used for display. Otherwise, the default one should be - // used, which is LANGUAGE_NOT_SPECIFIED. + // used, which is Language::LANGCODE_NOT_SPECIFIED. if (language_is_locked($langcode)) { $locked_languages[$field_name] = $langcode; } else { - $locked_languages[$field_name] = LANGUAGE_NOT_SPECIFIED; + $locked_languages[$field_name] = Language::LANGCODE_NOT_SPECIFIED; } } diff --git a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php index 40447f1..b05b1b6 100644 --- a/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/TranslationWebTest.php @@ -74,7 +74,7 @@ function testFieldFormTranslationRevisions() { $eid = 1; $entity = field_test_create_entity($eid, $eid, $this->instance['bundle']); $available_langcodes = array_flip(field_available_languages($this->entity_type, $this->field)); - unset($available_langcodes[LANGUAGE_NOT_SPECIFIED]); + unset($available_langcodes[Language::LANGCODE_NOT_SPECIFIED]); $field_name = $this->field['field_name']; // Store the field translations. diff --git a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php index 6d1975e..b494a5a 100644 --- a/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php +++ b/core/modules/field/lib/Drupal/field/Tests/Views/HandlerFieldFieldTest.php @@ -7,6 +7,7 @@ namespace Drupal\field\Tests\Views; +use Drupal\Core\Language\Language; use Drupal\views\ViewExecutable; /** @@ -104,7 +105,7 @@ public function _testSimpleFieldRender() { for ($key = 0; $key < 2; $key++) { $field = $this->fields[$key]; $rendered_field = $view->style_plugin->get_field($i, $field['field_name']); - $expected_field = $this->nodes[$i]->{$field['field_name']}[LANGUAGE_NOT_SPECIFIED][0]['value']; + $expected_field = $this->nodes[$i]->{$field['field_name']}[Language::LANGCODE_NOT_SPECIFIED][0]['value']; $this->assertEqual($rendered_field, $expected_field); } } @@ -143,7 +144,7 @@ public function _testMultipleFieldRender() { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->get_field($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$field_name}[LANGUAGE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; $pure_items = array_splice($pure_items, 0, 3); foreach ($pure_items as $j => $item) { $items[] = $pure_items[$j]['value']; @@ -166,7 +167,7 @@ public function _testMultipleFieldRender() { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->get_field($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$field_name}[LANGUAGE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; $pure_items = array_splice($pure_items, 1, 3); foreach ($pure_items as $j => $item) { $items[] = $pure_items[$j]['value']; @@ -186,7 +187,7 @@ public function _testMultipleFieldRender() { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->get_field($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$field_name}[LANGUAGE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; array_splice($pure_items, 0, -3); $pure_items = array_reverse($pure_items); foreach ($pure_items as $j => $item) { @@ -207,7 +208,7 @@ public function _testMultipleFieldRender() { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->get_field($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$field_name}[LANGUAGE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; $items[] = $pure_items[0]['value']; $items[] = $pure_items[4]['value']; $this->assertEqual($rendered_field, implode(', ', $items), 'Take sure that the amount of items are limited.'); @@ -225,7 +226,7 @@ public function _testMultipleFieldRender() { for ($i = 0; $i < 3; $i++) { $rendered_field = $view->style_plugin->get_field($i, $field_name); $items = array(); - $pure_items = $this->nodes[$i]->{$field_name}[LANGUAGE_NOT_SPECIFIED]; + $pure_items = $this->nodes[$i]->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; $pure_items = array_splice($pure_items, 0, 3); foreach ($pure_items as $j => $item) { $items[] = $pure_items[$j]['value']; diff --git a/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php b/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php index 5ea9c88..2d43155 100644 --- a/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php +++ b/core/modules/field_sql_storage/lib/Drupal/field_sql_storage/Tests/FieldSqlStorageTest.php @@ -8,6 +8,7 @@ namespace Drupal\field_sql_storage\Tests; use Drupal\Core\Database\Database; +use Drupal\Core\Language\Language; use Drupal\field\FieldException; use Drupal\system\Tests\Entity\EntityUnitTestBase; use Exception; @@ -61,7 +62,7 @@ function setUp() { function testFieldAttachLoad() { $entity_type = 'test_entity'; $eid = 0; - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $columns = array('entity_type', 'entity_id', 'revision_id', 'delta', 'langcode', $this->field_name . '_value'); @@ -130,7 +131,7 @@ function testFieldAttachLoad() { function testFieldAttachInsertAndUpdate() { $entity_type = 'test_entity'; $entity = field_test_create_entity(0, 0, $this->instance['bundle']); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Test insert. $values = array(); @@ -211,7 +212,7 @@ function testFieldAttachInsertAndUpdate() { function testFieldAttachSaveMissingData() { $entity_type = 'test_entity'; $entity = field_test_create_entity(0, 0, $this->instance['bundle']); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Insert: Field is missing field_attach_insert($entity); @@ -310,7 +311,7 @@ function testUpdateFieldSchemaWithData() { $instance = array('field_name' => 'decimal52', 'entity_type' => 'test_entity', 'bundle' => 'test_bundle'); $instance = field_create_instance($instance); $entity = field_test_create_entity(0, 0, $instance['bundle']); - $entity->decimal52[LANGUAGE_NOT_SPECIFIED][0]['value'] = '1.235'; + $entity->decimal52[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = '1.235'; $entity->save(); // Attempt to update the field in a way that would work without data. @@ -370,7 +371,7 @@ function testFieldUpdateIndexesWithData() { // Add data so the table cannot be dropped. $entity = field_test_create_entity(1, 1, $instance['bundle']); - $entity->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['value'] = 'field data'; + $entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = 'field data'; $entity->save(); // Add an index @@ -391,7 +392,7 @@ function testFieldUpdateIndexesWithData() { // Verify that the tables were not dropped. $entity = field_test_create_entity(1, 1, $instance['bundle']); field_attach_load('test_entity', array(1 => $entity)); - $this->assertEqual($entity->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['value'], 'field data', t("Index changes performed without dropping the tables")); + $this->assertEqual($entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['value'], 'field data', t("Index changes performed without dropping the tables")); } /** diff --git a/core/modules/field_ui/field_ui.admin.inc b/core/modules/field_ui/field_ui.admin.inc index 566959b..c582a13 100644 --- a/core/modules/field_ui/field_ui.admin.inc +++ b/core/modules/field_ui/field_ui.admin.inc @@ -5,6 +5,7 @@ * Administrative interface for custom field type creation. */ +use Drupal\Core\Language\Language; use Drupal\field\FieldInstance; use Drupal\field_ui\FieldOverview; use Drupal\field_ui\DisplayOverview; @@ -937,7 +938,7 @@ function field_ui_default_value_widget($field, $instance, &$form, &$form_state) // Insert the widget. Since we do not use the "official" instance definition, // the whole flow cannot use field_invoke_method(). $items = (array) $instance['default_value']; - $element += $instance->getWidget()->form($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state); + $element += $instance->getWidget()->form($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); return $element; } @@ -959,27 +960,27 @@ function field_ui_field_edit_form_validate($form, &$form_state) { // Extract the 'default value'. $items = array(); - $instance->getWidget()->extractFormValues($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state); + $instance->getWidget()->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); // Grab the field definition from $form_state. - $field_state = field_form_get_state($element['#parents'], $field_name, LANGUAGE_NOT_SPECIFIED, $form_state); + $field_state = field_form_get_state($element['#parents'], $field_name, Language::LANGCODE_NOT_SPECIFIED, $form_state); $field = $field_state['field']; // Validate the value. $errors = array(); $function = $field['module'] . '_field_validate'; if (function_exists($function)) { - $function(NULL, $field, $instance, LANGUAGE_NOT_SPECIFIED, $items, $errors); + $function(NULL, $field, $instance, Language::LANGCODE_NOT_SPECIFIED, $items, $errors); } // Report errors. - if (isset($errors[$field_name][LANGUAGE_NOT_SPECIFIED])) { + if (isset($errors[$field_name][Language::LANGCODE_NOT_SPECIFIED])) { // Store reported errors in $form_state. - $field_state['errors'] = $errors[$field_name][LANGUAGE_NOT_SPECIFIED]; - field_form_set_state($element['#parents'], $field_name, LANGUAGE_NOT_SPECIFIED, $form_state, $field_state); + $field_state['errors'] = $errors[$field_name][Language::LANGCODE_NOT_SPECIFIED]; + field_form_set_state($element['#parents'], $field_name, Language::LANGCODE_NOT_SPECIFIED, $form_state, $field_state); // Assign reported errors to the correct form element. - $instance->getWidget()->flagErrors($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state); + $instance->getWidget()->flagErrors($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); } } } @@ -1000,7 +1001,7 @@ function field_ui_field_edit_form_submit($form, &$form_state) { // Extract field values. $items = array(); - $instance->getWidget()->extractFormValues($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state); + $instance->getWidget()->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state); $instance['default_value'] = $items ? $items : NULL; } diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php index 2d3fb98..c4614ac 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/FieldUiTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\field_ui\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -38,7 +39,7 @@ function setUp() { 'name' => $this->randomName(), 'description' => $this->randomName(), 'vid' => drupal_strtolower($this->randomName()), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'help' => '', 'nodes' => array('article' => 'article'), 'weight' => mt_rand(0, 10), diff --git a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php index cbc132f..3834ed9 100644 --- a/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php +++ b/core/modules/field_ui/lib/Drupal/field_ui/Tests/ManageFieldsTest.php @@ -7,6 +7,8 @@ namespace Drupal\field_ui\Tests; +use Drupal\Core\Language\Language; + /** * Tests the functionality of the 'Manage fields' screen. */ @@ -35,7 +37,7 @@ function setUp() { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Tags', 'vid' => 'tags', - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $vocabulary->save(); @@ -255,7 +257,7 @@ function testDefaultValue() { ); field_create_instance($instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $admin_path = 'admin/structure/types/manage/' . $this->type . '/fields/' . $field_name; $element_id = "edit-$field_name-$langcode-0-value"; $element_name = "{$field_name}[$langcode][0][value]"; diff --git a/core/modules/file/lib/Drupal/file/FileStorageController.php b/core/modules/file/lib/Drupal/file/FileStorageController.php index fb72a5d..d3ca601 100644 --- a/core/modules/file/lib/Drupal/file/FileStorageController.php +++ b/core/modules/file/lib/Drupal/file/FileStorageController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\DatabaseStorageController; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; /** * File storage controller for files. @@ -42,7 +43,7 @@ protected function preSave(EntityInterface $entity) { // neutral more often than language dependent. Until we have better // flexible settings. // @todo See http://drupal.org/node/258785 and followups. - $entity->langcode = LANGUAGE_NOT_SPECIFIED; + $entity->langcode = Language::LANGCODE_NOT_SPECIFIED; } } diff --git a/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php b/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php index 080c47a..0631223 100644 --- a/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php +++ b/core/modules/file/lib/Drupal/file/Plugin/Core/Entity/File.php @@ -11,6 +11,7 @@ use Drupal\Core\Entity\Entity; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Language\Language; /** * Defines the file entity class. @@ -50,7 +51,7 @@ class File extends Entity implements ContentEntityInterface { * * @var string */ - public $langcode = LANGUAGE_NOT_SPECIFIED; + public $langcode = Language::LANGCODE_NOT_SPECIFIED; /** * The uid of the user who is associated with the file. diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php index 81e87d0..9d1b20a 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldDisplayTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\Core\Language\Language; + /** * Tests that formatters are working properly. */ @@ -60,12 +62,12 @@ function testNodeDisplay() { // Check that the default formatter is displaying with the file name. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $default_output = theme('file_link', array('file' => $node_file)); $this->assertRaw($default_output, t('Default formatter displaying correctly on full node view.')); // Turn the "display" option off and check that the file is no longer displayed. - $edit = array($field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][display]' => FALSE); + $edit = array($field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][display]' => FALSE); $this->drupalPost('node/' . $nid . '/edit', $edit, t('Save and keep published')); $this->assertNoRaw($default_output, t('Field is hidden when "display" option is unchecked.')); @@ -73,8 +75,8 @@ function testNodeDisplay() { // Add a description and make sure that it is displayed. $description = $this->randomName(); $edit = array( - $field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][description]' => $description, - $field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][display]' => TRUE, + $field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][description]' => $description, + $field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][display]' => TRUE, ); $this->drupalPost('node/' . $nid . '/edit', $edit, t('Save and keep published')); $this->assertText($description); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php index d963b89..df551d0 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldPathTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\Core\Language\Language; + /** * Tests that files are uploaded to proper locations. */ @@ -33,7 +35,7 @@ function testUploadPath() { // Check that the file was uploaded to the file root. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertPathMatch('public://' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri))); // Change the path to contain multiple subdirectories. @@ -44,7 +46,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertPathMatch('public://foo/bar/baz/' . $test_file->filename, $node_file->uri, t('The file %file was uploaded to the correct path.', array('%file' => $node_file->uri))); // Check the path when used with tokens. @@ -56,7 +58,7 @@ function testUploadPath() { // Check that the file was uploaded into the subdirectory. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); // Do token replacement using the same user which uploaded the file, not // the user running the test case. $data = array('user' => $this->admin_user); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php index 1124e18..6cedd1a 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRSSContentTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\Core\Language\Language; + /** * Tests that formatters are working properly. */ @@ -67,7 +69,7 @@ function testFileFieldRSSContent() { // Get the uploaded file from the node. $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); // Check that the RSS enclosure appears in the RSS feed. $this->drupalGet('rss.xml'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php index 47d19d1..34c3de1 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldRevisionTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\Core\Language\Language; + /** * Tests file handling with node revisions. */ @@ -47,7 +49,7 @@ function testRevisions() { // Check that the file exists on disk and in the database. $node = node_load($nid, TRUE); - $node_file_r1 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file_r1 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $node_vid_r1 = $node->vid; $this->assertFileExists($node_file_r1, t('New file saved to disk on node creation.')); $this->assertFileEntryExists($node_file_r1, t('File entry exists in database on node creation.')); @@ -56,7 +58,7 @@ function testRevisions() { // Upload another file to the same node in a new revision. $this->replaceNodeFile($test_file, $field_name, $nid); $node = node_load($nid, TRUE); - $node_file_r2 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file_r2 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $node_vid_r2 = $node->vid; $this->assertFileExists($node_file_r2, t('Replacement file exists on disk after creating new revision.')); $this->assertFileEntryExists($node_file_r2, t('Replacement file entry exists in database after creating new revision.')); @@ -64,7 +66,7 @@ function testRevisions() { // Check that the original file is still in place on the first revision. $node = node_revision_load($node_vid_r1); - $this->assertEqual($node_file_r1, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('Original file still in place after replacing file in new revision.')); + $this->assertEqual($node_file_r1, file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']), t('Original file still in place after replacing file in new revision.')); $this->assertFileExists($node_file_r1, t('Original file still in place after replacing file in new revision.')); $this->assertFileEntryExists($node_file_r1, t('Original file entry still in place after replacing file in new revision')); $this->assertFileIsPermanent($node_file_r1, t('Original file is still permanent.')); @@ -73,7 +75,7 @@ function testRevisions() { // Check that the file is still the same as the previous revision. $this->drupalPost('node/' . $nid . '/edit', array('revision' => '1'), t('Save and keep published')); $node = node_load($nid, TRUE); - $node_file_r3 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file_r3 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $node_vid_r3 = $node->vid; $this->assertEqual($node_file_r2, $node_file_r3, t('Previous revision file still in place after creating a new revision without a new file.')); $this->assertFileIsPermanent($node_file_r3, t('New revision file is permanent.')); @@ -81,7 +83,7 @@ function testRevisions() { // Revert to the first revision and check that the original file is active. $this->drupalPost('node/' . $nid . '/revisions/' . $node_vid_r1 . '/revert', array(), t('Revert')); $node = node_load($nid, TRUE); - $node_file_r4 = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file_r4 = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $node_vid_r4 = $node->vid; $this->assertEqual($node_file_r1, $node_file_r4, t('Original revision file still in place after reverting to the original revision.')); $this->assertFileIsPermanent($node_file_r4, t('Original revision file still permanent after reverting to the original revision.')); @@ -95,8 +97,8 @@ function testRevisions() { // Attach the second file to a user. $user = $this->drupalCreateUser(); - $user->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'] = $node_file_r3->fid; - $user->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['display'] = 1; + $user->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'] = $node_file_r3->fid; + $user->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['display'] = 1; $user->save(); $this->drupalGet('user/' . $user->uid . '/edit'); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php index c2d922d..6b54f4d 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\file\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -126,7 +127,7 @@ function updateFileField($name, $type_name, $instance_settings = array(), $widge * Uploads a file to a node. */ function uploadNodeFile($file, $field_name, $nid_or_type, $new_revision = TRUE, $extras = array()) { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array( "title" => $this->randomName(), 'revision' => (string) (int) $new_revision, @@ -173,7 +174,7 @@ function removeNodeFile($nid, $new_revision = TRUE) { */ function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) { $edit = array( - 'files[' . $field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_0]' => drupal_realpath($file->uri), + 'files[' . $field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_0]' => drupal_realpath($file->uri), 'revision' => (string) (int) $new_revision, ); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php index 7a40a1c..697b1e5 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldValidateTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\Core\Language\Language; + /** * Tests various validations. */ @@ -35,7 +37,7 @@ function testRequired() { $test_file = $this->getTestFile('text'); // Try to post a new node without uploading a file. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array("title" => $this->randomName()); $this->drupalPost('node/add/' . $type_name, $edit, t('Save and publish')); $this->assertRaw(t('!title field is required.', array('!title' => $instance['label'])), t('Node save failed when required file field was empty.')); @@ -46,7 +48,7 @@ function testRequired() { $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading to the required field.')); $this->assertFileEntryExists($node_file, t('File entry exists after uploading to the required field.')); @@ -62,7 +64,7 @@ function testRequired() { // Create a new node with the uploaded file into the multivalue field. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading to the required multiple value field.')); $this->assertFileEntryExists($node_file, t('File entry exists after uploading to the required multipel value field.')); @@ -98,7 +100,7 @@ function testFileMaxSize() { // Create a new node with the small file, which should pass. $nid = $this->uploadNodeFile($small_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize))); $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) under the max limit (%maxsize).', array('%filesize' => format_size($small_file->filesize), '%maxsize' => $max_filesize))); @@ -114,7 +116,7 @@ function testFileMaxSize() { // Upload the big file successfully. $nid = $this->uploadNodeFile($large_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize)))); $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file (%filesize) with no max limit.', array('%filesize' => format_size($large_file->filesize)))); @@ -141,7 +143,7 @@ function testFileExtension() { // Check that the file can be uploaded with no extension checking. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading a file with no extension checking.')); $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file with no extension checking.')); @@ -159,7 +161,7 @@ function testFileExtension() { // Check that the file can be uploaded with extension checking. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('File exists after uploading a file with extension checking.')); $this->assertFileEntryExists($node_file, t('File entry exists after uploading a file with extension checking.')); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php index 05b0cad..1842182 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileFieldWidgetTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\Core\Language\Language; + /** * Tests file field widget. */ @@ -46,7 +48,7 @@ function testSingleValuedWidget() { // does not yet support file uploads. $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('New file saved to disk on node creation.')); // Ensure the file can be downloaded. @@ -73,13 +75,13 @@ function testSingleValuedWidget() { $this->assertNoFieldByXPath('//input[@type="submit"]', t('Remove'), t('After clicking the "Remove" button, it is no longer displayed.')); $this->assertFieldByXpath('//input[@type="submit"]', t('Upload'), t('After clicking the "Remove" button, the "Upload" button is displayed.')); // Test label has correct 'for' attribute. - $label = $this->xpath("//label[@for='edit-" . drupal_clean_css_identifier($field_name) . "-" . LANGUAGE_NOT_SPECIFIED . "-0-upload']"); + $label = $this->xpath("//label[@for='edit-" . drupal_clean_css_identifier($field_name) . "-" . Language::LANGCODE_NOT_SPECIFIED . "-0-upload']"); $this->assertTrue(isset($label[0]), 'Label for upload found.'); // Save the node and ensure it does not have the file. $this->drupalPost(NULL, array(), t('Save and keep published')); $node = node_load($nid, TRUE); - $this->assertTrue(empty($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('File was successfully removed from the node.')); + $this->assertTrue(empty($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']), t('File was successfully removed from the node.')); } } @@ -113,7 +115,7 @@ function testMultiValuedWidget() { $this->drupalGet("node/add/$type_name"); foreach (array($field_name2, $field_name) as $each_field_name) { for ($delta = 0; $delta < 3; $delta++) { - $edit = array('files[' . $each_field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . $delta . ']' => drupal_realpath($test_file->uri)); + $edit = array('files[' . $each_field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_' . $delta . ']' => drupal_realpath($test_file->uri)); // If the Upload button doesn't exist, drupalPost() will automatically // fail with an assertion message. $this->drupalPost(NULL, $edit, t('Upload')); @@ -144,11 +146,11 @@ function testMultiValuedWidget() { $check_field_name = $field_name; } - $this->assertIdentical((string) $button['name'], $check_field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . $key. '_remove_button'); + $this->assertIdentical((string) $button['name'], $check_field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_' . $key. '_remove_button'); } // "Click" the remove button (emulating either a nojs or js submission). - $button_name = $current_field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . $delta . '_remove_button'; + $button_name = $current_field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_' . $delta . '_remove_button'; switch ($type) { case 'nojs': // drupalPost() takes a $submit parameter that is the value of the @@ -176,7 +178,7 @@ function testMultiValuedWidget() { // Ensure an "Upload" button for the current field is displayed with the // correct name. - $upload_button_name = $current_field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . $remaining . '_upload_button'; + $upload_button_name = $current_field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_' . $remaining . '_upload_button'; $buttons = $this->xpath('//input[@type="submit" and @value="Upload" and @name=:name]', array(':name' => $upload_button_name)); $this->assertTrue(is_array($buttons) && count($buttons) == 1, t('The upload button is displayed with the correct name (JSMode=%type).', array('%type' => $type))); @@ -196,7 +198,7 @@ function testMultiValuedWidget() { preg_match('/node\/([0-9]+)/', $this->getUrl(), $matches); $nid = $matches[1]; $node = node_load($nid, TRUE); - $this->assertTrue(empty($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']), t('Node was successfully saved without any files.')); + $this->assertTrue(empty($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']), t('Node was successfully saved without any files.')); } } @@ -217,7 +219,7 @@ function testPrivateFileSetting() { $this->drupalPost("admin/structure/types/manage/$type_name/fields/$field_name/field-settings", $edit, t('Save field settings')); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertFileExists($node_file, t('New file saved to disk on node creation.')); // Ensure the private file is available to the user who uploaded it. @@ -272,8 +274,8 @@ function testPrivateFileComment() { // Add a comment with a file. $text_file = $this->getTestFile('text'); $edit = array( - 'files[field_' . $name . '_' . LANGUAGE_NOT_SPECIFIED . '_' . 0 . ']' => drupal_realpath($text_file->uri), - 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $comment_body = $this->randomName(), + 'files[field_' . $name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_' . 0 . ']' => drupal_realpath($text_file->uri), + 'comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]' => $comment_body = $this->randomName(), ); $this->drupalPost(NULL, $edit, t('Save')); diff --git a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php index 42c0b09..925ac7b 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FilePrivateTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\Core\Language\Language; + /** * Tests file access on private nodes. */ @@ -48,7 +50,7 @@ function testPrivateFile() { $test_file = $this->getTestFile('text'); $nid = $this->uploadNodeFile($test_file, $field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); // Ensure the file can be downloaded. $this->drupalGet(file_create_url($node_file->uri)); $this->assertResponse(200, t('Confirmed that the generated URL is correct by downloading the shipped file.')); @@ -60,7 +62,7 @@ function testPrivateFile() { $this->drupalLogin($this->admin_user); $nid = $this->uploadNodeFile($test_file, $no_access_field_name, $type_name, TRUE, array('private' => TRUE)); $node = node_load($nid, TRUE); - $node_file = file_load($node->{$no_access_field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $node_file = file_load($node->{$no_access_field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); // Ensure the file cannot be downloaded. $this->drupalGet(file_create_url($node_file->uri)); $this->assertResponse(403, t('Confirmed that access is denied for the file without view field access permission.')); diff --git a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php index 4d56b7b..d96f9a4 100644 --- a/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/FileTokenReplaceTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\Core\Language\Language; + /** * Tests the file token replacement in strings. */ @@ -23,7 +25,7 @@ public static function getInfo() { * Creates a file, then tests the tokens generated from it. */ function testFileTokenReplacement() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $url_options = array( 'absolute' => TRUE, 'language' => $language_interface, @@ -46,7 +48,7 @@ function testFileTokenReplacement() { // Load the node and the file. $node = node_load($nid, TRUE); - $file = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $file = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); // Generate and test sanitized tokens. $tests = array(); diff --git a/core/modules/file/lib/Drupal/file/Tests/SaveTest.php b/core/modules/file/lib/Drupal/file/Tests/SaveTest.php index e2611e5..eeb9f77 100644 --- a/core/modules/file/lib/Drupal/file/Tests/SaveTest.php +++ b/core/modules/file/lib/Drupal/file/Tests/SaveTest.php @@ -7,6 +7,8 @@ namespace Drupal\file\Tests; +use Drupal\Core\Language\Language; + /** * Tests saving files. */ @@ -43,7 +45,7 @@ function testFileSave() { $this->assertEqual($loaded_file->status, $file->status, t("Status was saved correctly.")); $this->assertEqual($file->filesize, filesize($file->uri), t("File size was set correctly."), 'File'); $this->assertTrue($file->timestamp > 1, t("File size was set correctly."), 'File'); - $this->assertEqual($loaded_file->langcode, LANGUAGE_NOT_SPECIFIED, t("Langcode was defaulted correctly.")); + $this->assertEqual($loaded_file->langcode, Language::LANGCODE_NOT_SPECIFIED, t("Langcode was defaulted correctly.")); // Resave the file, updating the existing record. file_test_reset(); diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 5de251c..f887986 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -6,6 +6,7 @@ */ use Drupal\Core\Cache\CacheBackendInterface; +use Drupal\Core\Language\Language; use Drupal\Core\Template\Attribute; use Drupal\filter\Plugin\Core\Entity\FilterFormat; @@ -330,7 +331,7 @@ function filter_modules_disabled($modules) { * @see filter_formats_reset() */ function filter_formats($account = NULL) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $formats = &drupal_static(__FUNCTION__, array()); // All available formats are cached for performance. diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php index 4d28fa6..c15eecb 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAdminTest.php @@ -7,6 +7,7 @@ namespace Drupal\filter\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -222,7 +223,7 @@ function testFilterAdmin() { $text = $body . '' . $extra_text . ''; $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(); $edit["body[$langcode][0][value]"] = $text; $edit["body[$langcode][0][format]"] = $basic; diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php index 969fac0..c5a88dd 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterFormatAccessTest.php @@ -7,6 +7,7 @@ namespace Drupal\filter\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -136,7 +137,7 @@ function testFormatPermissions() { // the disallowed format does not. $this->drupalLogin($this->web_user); $this->drupalGet('node/add/page'); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $elements = $this->xpath('//select[@name=:name]/option', array( ':name' => "body[$langcode][0][format]", ':option' => $this->allowed_format->format, @@ -206,7 +207,7 @@ function testFormatRoles() { * choose a new format before saving the page. */ function testFormatWidgetPermissions() { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $title_key = "title"; $body_value_key = "body[$langcode][0][value]"; $body_format_key = "body[$langcode][0][format]"; diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterHooksTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterHooksTest.php index 442eff4..fb5b11b 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterHooksTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterHooksTest.php @@ -7,6 +7,7 @@ namespace Drupal\filter\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -64,7 +65,7 @@ function testFilterHooks() { $this->assertText('hook_filter_format_update invoked.'); // Use the format created. - $language_not_specified = LANGUAGE_NOT_SPECIFIED; + $language_not_specified = Language::LANGCODE_NOT_SPECIFIED; $title = $this->randomName(8); $edit = array( "title" => $title, diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php index aa3f390..9b3eea0 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterSecurityTest.php @@ -7,6 +7,7 @@ namespace Drupal\filter\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -71,8 +72,8 @@ function setUp() { function testDisableFilterModule() { // Create a new node. $node = $this->drupalCreateNode(array('promote' => 1)); - $body_raw = $node->body[LANGUAGE_NOT_SPECIFIED][0]['value']; - $format_id = $node->body[LANGUAGE_NOT_SPECIFIED][0]['format']; + $body_raw = $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value']; + $format_id = $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['format']; $this->drupalGet('node/' . $node->nid); $this->assertText($body_raw, 'Node body found.'); diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php index 02314e8..ea33943 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumBlockTest.php @@ -7,6 +7,7 @@ namespace Drupal\forum\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; use Drupal\Core\Datetime\DrupalDateTime; @@ -98,7 +99,7 @@ public function testActiveForumTopicsBlock() { // Comment on the first 5 topics. $date = new DrupalDateTime(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; for ($index = 0; $index < 5; $index++) { // Get the node from the topic title. $node = $this->drupalGetNodeByTitle($topics[$index]); @@ -168,7 +169,7 @@ protected function createForumTopics($count = 5) { // changing the date. $date->modify('+1 minute'); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array( 'title' => $title, "body[$langcode][0][value]" => $body, diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumIndexTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumIndexTest.php index 27e4384..e497f9b 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumIndexTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumIndexTest.php @@ -7,6 +7,7 @@ namespace Drupal\forum\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -42,7 +43,7 @@ function setUp() { */ function testForumIndexStatus() { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // The forum ID to use. $tid = 1; diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php index bc145b0..dffeb2f 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumNodeAccessTest.php @@ -7,6 +7,7 @@ namespace Drupal\forum\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -54,7 +55,7 @@ function testForumNodeAccess() { $this->drupalLogin($admin_user); // Create a private node. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $private_node_title = $this->randomName(20); $edit = array( 'title' => $private_node_title, diff --git a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php index c08ce70..16517ab 100644 --- a/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php +++ b/core/modules/forum/lib/Drupal/forum/Tests/ForumTest.php @@ -7,6 +7,7 @@ namespace Drupal\forum\Tests; +use Drupal\Core\Language\Language; use Drupal\Core\Entity\EntityInterface; use Drupal\simpletest\WebTestBase; @@ -211,7 +212,7 @@ function testForum() { // Test adding a comment to a forum topic. $node = $this->createForumTopic($this->forum, FALSE); $edit = array(); - $edit['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]'] = $this->randomName(); + $edit['comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]'] = $this->randomName(); $this->drupalPost("node/$node->nid", $edit, t('Save')); $this->assertResponse(200); @@ -247,7 +248,7 @@ function testAddOrphanTopic() { // Create an orphan forum item. $this->drupalLogin($this->admin_user); - $this->drupalPost('node/add/forum', array('title' => $this->randomName(10), 'body[' . LANGUAGE_NOT_SPECIFIED .'][0][value]' => $this->randomName(120)), t('Save')); + $this->drupalPost('node/add/forum', array('title' => $this->randomName(10), 'body[' . Language::LANGCODE_NOT_SPECIFIED .'][0][value]' => $this->randomName(120)), t('Save')); $nid_count = db_query('SELECT COUNT(nid) FROM {node}')->fetchField(); $this->assertEqual(0, $nid_count, 'A forum node was not created when missing a forum vocabulary.'); @@ -474,7 +475,7 @@ function testForumWithNewPost() { // Post a reply to the topic. $edit = array(); $edit['subject'] = $this->randomName(); - $edit['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]'] = $this->randomName(); + $edit['comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]'] = $this->randomName(); $this->drupalPost("node/$node->nid", $edit, t('Save')); $this->assertResponse(200); @@ -501,7 +502,7 @@ function createForumTopic($forum, $container = FALSE) { $title = $this->randomName(20); $body = $this->randomName(200); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array( "title" => $title, "body[$langcode][0][value]" => $body, @@ -525,7 +526,7 @@ function createForumTopic($forum, $container = FALSE) { // Retrieve node object, ensure that the topic was created and in the proper forum. $node = $this->drupalGetNodeByTitle($title); $this->assertTrue($node != NULL, format_string('Node @title was loaded', array('@title' => $title))); - $this->assertEqual($node->taxonomy_forums[LANGUAGE_NOT_SPECIFIED][0]['tid'], $tid, 'Saved forum topic was in the expected forum'); + $this->assertEqual($node->taxonomy_forums[Language::LANGCODE_NOT_SPECIFIED][0]['tid'], $tid, 'Saved forum topic was in the expected forum'); // View forum topic. $this->drupalGet('node/' . $node->nid); @@ -587,7 +588,7 @@ private function verifyForums($node_user, EntityInterface $node, $admin, $respon if ($response == 200) { // Edit forum node (including moving it to another forum). $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = 'node/' . $node->nid; $edit["body[$langcode][0][value]"] = $this->randomName(256); // Assume the topic is initially associated with $forum. diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php index 2618d9a..abe1a52 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/EntityNormalizer.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Entity\EntityNG; +use Drupal\Core\Language\Language; use Symfony\Component\Serializer\Exception\UnexpectedValueException; /** @@ -74,7 +75,7 @@ public function denormalize($data, $class, $format = NULL, array $context = arra } // Get language. - $langcode = isset($data['langcode']) ? $data['langcode'][0]['value'] : LANGUAGE_NOT_SPECIFIED; + $langcode = isset($data['langcode']) ? $data['langcode'][0]['value'] : Language::LANGCODE_NOT_SPECIFIED; // Create the entity. $typed_data_ids = $this->getTypedDataIds($data['_links']['type']); diff --git a/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php b/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php index d625234..f435de3 100644 --- a/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php +++ b/core/modules/hal/lib/Drupal/hal/Normalizer/FieldNormalizer.php @@ -8,6 +8,8 @@ namespace Drupal\hal\Normalizer; use Drupal\Component\Utility\NestedArray; +use Drupal\Core\Language\Language; + use Symfony\Component\Serializer\Exception\LogicException; /** @@ -43,7 +45,7 @@ public function normalize($field, $format = NULL, array $context = array()) { // to the field item values. else { foreach ($entity->getTranslationLanguages() as $lang) { - $context['langcode'] = $lang->langcode == 'und' ? LANGUAGE_DEFAULT : $lang->langcode; + $context['langcode'] = $lang->langcode == 'und' ? Language::LANGCODE_DEFAULT : $lang->langcode; $translation = $entity->getTranslation($lang->langcode); $translated_field = $translation->get($field_name); $normalized_field_items = array_merge($normalized_field_items, $this->normalizeFieldItems($translated_field, $format, $context)); diff --git a/core/modules/image/image.module b/core/modules/image/image.module index 7be1abd..b34369c 100644 --- a/core/modules/image/image.module +++ b/core/modules/image/image.module @@ -5,6 +5,7 @@ * Exposes global functionality for creating image styles. */ +use Drupal\Core\Language\Language; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\BinaryFileResponse; use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException; @@ -876,7 +877,7 @@ function image_style_path($style_name, $uri) { * @see image_effect_definition_load() */ function image_effect_definitions() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // hook_image_effect_info() includes translated strings, so each language is // cached separately. diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php index 84a5ed458..5000941 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageAdminStylesTest.php @@ -7,6 +7,8 @@ namespace Drupal\image\Tests; +use Drupal\Core\Language\Language; + /** * Tests creation, deletion, and editing of image styles and effects. */ @@ -271,7 +273,7 @@ function testStyleReplacement() { // Test that image is displayed using newly created style. $this->drupalGet('node/' . $nid); - $this->assertRaw(image_style_url($style_name, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), format_string('Image displayed using style @style.', array('@style' => $style_name))); + $this->assertRaw(image_style_url($style_name, file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->uri), format_string('Image displayed using style @style.', array('@style' => $style_name))); // Rename the style and make sure the image field is updated. $new_style_name = strtolower($this->randomName(10)); @@ -283,7 +285,7 @@ function testStyleReplacement() { $this->drupalPost($style_path . $style_name, $edit, t('Update style')); $this->assertText(t('Changes to the style have been saved.'), format_string('Style %name was renamed to %new_name.', array('%name' => $style_name, '%new_name' => $new_style_name))); $this->drupalGet('node/' . $nid); - $this->assertRaw(image_style_url($new_style_name, file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), 'Image displayed using style replacement style.'); + $this->assertRaw(image_style_url($new_style_name, file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->uri), 'Image displayed using style replacement style.'); // Delete the style and choose a replacement style. $edit = array( @@ -294,7 +296,7 @@ function testStyleReplacement() { $this->assertRaw($message); $this->drupalGet('node/' . $nid); - $this->assertRaw(image_style_url('thumbnail', file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri), 'Image displayed using style replacement style.'); + $this->assertRaw(image_style_url('thumbnail', file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->uri), 'Image displayed using style replacement style.'); } /** diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php index 7c42a5b..b656691 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldDisplayTest.php @@ -7,6 +7,8 @@ namespace Drupal\image\Tests; +use Drupal\Core\Language\Language; + /** * Test class to check that formatters and display settings are working. */ @@ -56,7 +58,7 @@ function _testImageFieldFormatters($scheme) { $node = node_load($nid, TRUE); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri; + $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->uri; $image_info = array( 'uri' => $image_uri, 'width' => 40, @@ -161,13 +163,13 @@ function testImageFieldSettings() { // and title fields do not display until the image has been attached. $nid = $this->uploadNodeImage($test_image, $field_name, 'article'); $this->drupalGet('node/' . $nid . '/edit'); - $this->assertFieldByName($field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][alt]', '', 'Alt field displayed on article form.'); - $this->assertFieldByName($field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][title]', '', 'Title field displayed on article form.'); + $this->assertFieldByName($field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][alt]', '', 'Alt field displayed on article form.'); + $this->assertFieldByName($field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][title]', '', 'Title field displayed on article form.'); // Verify that the attached image is being previewed using the 'medium' // style. $node = node_load($nid, TRUE); $image_info = array( - 'uri' => file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri, + 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->uri, 'width' => 220, 'height' => 110, 'style_name' => 'medium', @@ -177,15 +179,15 @@ function testImageFieldSettings() { // Add alt/title fields to the image and verify that they are displayed. $image_info = array( - 'uri' => file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri, + 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->uri, 'alt' => $this->randomName(), 'title' => $this->randomName(), 'width' => 40, 'height' => 20, ); $edit = array( - $field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][alt]' => $image_info['alt'], - $field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][title]' => $image_info['title'], + $field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][alt]' => $image_info['alt'], + $field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][title]' => $image_info['title'], ); $this->drupalPost('node/' . $nid . '/edit', $edit, t('Save and keep published')); $default_output = theme('image', $image_info); @@ -194,8 +196,8 @@ function testImageFieldSettings() { // Verify that alt/title longer than allowed results in a validation error. $test_size = 2000; $edit = array( - $field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][alt]' => $this->randomName($test_size), - $field_name . '[' . LANGUAGE_NOT_SPECIFIED . '][0][title]' => $this->randomName($test_size), + $field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][alt]' => $this->randomName($test_size), + $field_name . '[' . Language::LANGCODE_NOT_SPECIFIED . '][0][title]' => $this->randomName($test_size), ); $this->drupalPost('node/' . $nid . '/edit', $edit, t('Save and keep published')); $this->assertRaw(t('Alternate text cannot be longer than %max characters but is currently %length characters long.', array( @@ -244,7 +246,7 @@ function testImageFieldDefaultImage() { $nid = $this->uploadNodeImage($images[1], $field_name, 'article'); $node = node_load($nid, TRUE); $image_info = array( - 'uri' => file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri, + 'uri' => file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->uri, 'width' => 40, 'height' => 20, ); diff --git a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php index 5a4e20e..a6e5f76 100644 --- a/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php +++ b/core/modules/image/lib/Drupal/image/Tests/ImageFieldTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\image\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -117,7 +118,7 @@ function uploadNodeImage($image, $field_name, $type) { $edit = array( 'title' => $this->randomName(), ); - $edit['files[' . $field_name . '_' . LANGUAGE_NOT_SPECIFIED . '_0]'] = drupal_realpath($image->uri); + $edit['files[' . $field_name . '_' . Language::LANGCODE_NOT_SPECIFIED . '_0]'] = drupal_realpath($image->uri); $this->drupalPost('node/add/' . $type, $edit, t('Save and publish')); // Retrieve ID of the newly created node from the current URL. diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityNormalizer.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityNormalizer.php index 14e7e00..f72b74b 100644 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityNormalizer.php +++ b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityNormalizer.php @@ -7,6 +7,7 @@ namespace Drupal\jsonld; +use Drupal\Core\Language\Language; use Drupal\jsonld\JsonldNormalizerBase; use Drupal\rdf\RdfMappingException; use Symfony\Component\Serializer\Exception\UnexpectedValueException; @@ -69,14 +70,14 @@ public function denormalize($data, $class, $format = null, array $context = arra ); // If the data specifies a default language, use it to create the entity. if (isset($data['langcode'])) { - $values['langcode'] = $data['langcode'][LANGUAGE_NOT_SPECIFIED][0]['value']; + $values['langcode'] = $data['langcode'][Language::LANGCODE_NOT_SPECIFIED][0]['value']; } // Otherwise, if the default language is not specified but there are // translations of field values, explicitly set the entity's default // language to the site's default language. This is required to enable // field translation on this entity. else if ($this->containsTranslation($data)) { - $values['langcode'] = language(LANGUAGE_TYPE_CONTENT)->langcode; + $values['langcode'] = language(Language::TYPE_CONTENT)->langcode; } $entity = entity_create($typed_data_ids['entity_type'], $values); // Make sure all empty entity fields default to NULL, so that afterwards it @@ -132,10 +133,10 @@ public function denormalize($data, $class, $format = null, array $context = arra protected function containsTranslation($data) { // Langcodes which do not represent a translation of the entity. $defaultLangcodes = array( - LANGUAGE_DEFAULT, - LANGUAGE_NOT_SPECIFIED, - LANGUAGE_NOT_APPLICABLE, - language(LANGUAGE_TYPE_CONTENT)->langcode, + Language::LANGCODE_DEFAULT, + Language::LANGCODE_NOT_SPECIFIED, + Language::LANGCODE_NOT_APPLICABLE, + language(Language::TYPE_CONTENT)->langcode, ); // Combine the langcodes from the field value keys in a single array. diff --git a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php index f96f114..f0782e4 100644 --- a/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php +++ b/core/modules/jsonld/lib/Drupal/jsonld/JsonldEntityWrapper.php @@ -8,6 +8,7 @@ namespace Drupal\jsonld; use Drupal\Core\Entity\Entity; +use Drupal\Core\Language\Language; use Drupal\rdf\SiteSchema\SiteSchema; use Drupal\rdf\SiteSchema\SiteSchemaManager; use Symfony\Component\Serializer\Serializer; @@ -117,7 +118,7 @@ public function getProperties() { foreach ($this->entity->getTranslationLanguages() as $langcode => $language) { foreach ($this->entity->getTranslation($langcode) as $name => $field) { $definition = $this->entity->getPropertyDefinition($name); - $langKey = empty($definition['translatable']) ? LANGUAGE_NOT_SPECIFIED : $langcode; + $langKey = empty($definition['translatable']) ? Language::LANGCODE_NOT_SPECIFIED : $langcode; if (!$field->isEmpty()) { $properties[$name][$langKey] = $this->serializer->normalize($field, $this->format); } diff --git a/core/modules/language/language.admin.inc b/core/modules/language/language.admin.inc index f59fb38..52d08a1 100644 --- a/core/modules/language/language.admin.inc +++ b/core/modules/language/language.admin.inc @@ -196,7 +196,7 @@ function _language_admin_common_controls(&$form, $language = NULL) { '#required' => TRUE, '#description' => t('Direction that text in this language is presented.'), '#default_value' => @$language->direction, - '#options' => array(LANGUAGE_LTR => t('Left to right'), LANGUAGE_RTL => t('Right to left')), + '#options' => array(Language::DIRECTION_LTR => t('Left to right'), Language::DIRECTION_RTL => t('Right to left')), ); return $form; } diff --git a/core/modules/language/language.module b/core/modules/language/language.module index 6bbb5a7..5dd020d 100644 --- a/core/modules/language/language.module +++ b/core/modules/language/language.module @@ -5,6 +5,8 @@ * Add language handling functionality to Drupal. */ +use Drupal\Core\Language\Language; + /** * Implements hook_help(). */ @@ -224,7 +226,7 @@ function language_element_info_alter(&$type) { $type['language_select']['#process'] = array_merge($type['language_select']['#process'], array('language_process_language_select', 'form_process_select', 'ajax_process_form')); $type['language_select']['#theme'] = 'select'; $type['language_select']['#theme_wrappers'] = array_merge($type['language_select']['#theme_wrappers'], array('form_element')); - $type['language_select']['#languages'] = LANGUAGE_CONFIGURABLE; + $type['language_select']['#languages'] = Language::STATE_CONFIGURABLE; $type['language_select']['#multiple'] = FALSE; } } @@ -271,7 +273,7 @@ function language_element_info() { function language_configuration_element_default_options() { $language_options = array(); - $languages = language_list(LANGUAGE_ALL); + $languages = language_list(Language::STATE_ALL); foreach ($languages as $langcode => $language) { $language_options[$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; } @@ -436,7 +438,7 @@ function language_get_default_langcode($entity_type, $bundle) { } $default_value = NULL; - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); switch ($configuration['langcode']) { case 'site_default': $default_value = language_default()->langcode; @@ -534,7 +536,7 @@ function language_update_count() { * TRUE if language is successfully deleted. Otherwise FALSE. */ function language_delete($langcode) { - $languages = language_list(LANGUAGE_ALL); + $languages = language_list(Language::STATE_ALL); if (isset($languages[$langcode]) && !$languages[$langcode]->locked) { $language = $languages[$langcode]; @@ -566,10 +568,10 @@ function language_delete($langcode) { * and checks to see if a related right to left CSS file should be included. */ function language_css_alter(&$css) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // If the current language is RTL, add the CSS file with the RTL overrides. - if ($language_interface->direction == LANGUAGE_RTL) { + if ($language_interface->direction == Language::DIRECTION_RTL) { foreach ($css as $data => $item) { // Only provide RTL overrides for files. if ($item['type'] == 'file') { @@ -604,16 +606,16 @@ function language_language_types_info() { language_negotiation_include(); return array( - LANGUAGE_TYPE_INTERFACE => array( + Language::TYPE_INTERFACE => array( 'name' => t('User interface text'), 'description' => t('Order of language detection methods for user interface text. If a translation of user interface text is available in the detected language, it will be displayed.'), ), - LANGUAGE_TYPE_CONTENT => array( + Language::TYPE_CONTENT => array( 'name' => t('Content'), 'description' => t('Order of language detection methods for content. If a version of content is available in the detected language, it will be displayed.'), 'fixed' => array(LANGUAGE_NEGOTIATION_INTERFACE), ), - LANGUAGE_TYPE_URL => array( + Language::TYPE_URL => array( 'fixed' => array(LANGUAGE_NEGOTIATION_URL, LANGUAGE_NEGOTIATION_URL_FALLBACK), ), ); @@ -628,7 +630,7 @@ function language_language_negotiation_info() { $negotiation_info = array(); $negotiation_info[LANGUAGE_NEGOTIATION_URL] = array( - 'types' => array(LANGUAGE_TYPE_CONTENT, LANGUAGE_TYPE_INTERFACE, LANGUAGE_TYPE_URL), + 'types' => array(Language::TYPE_CONTENT, Language::TYPE_INTERFACE, Language::TYPE_URL), 'callbacks' => array( 'negotiation' => 'language_from_url', 'language_switch' => 'language_switcher_url', @@ -673,7 +675,7 @@ function language_language_negotiation_info() { ); $negotiation_info[LANGUAGE_NEGOTIATION_INTERFACE] = array( - 'types' => array(LANGUAGE_TYPE_CONTENT), + 'types' => array(Language::TYPE_CONTENT), 'callbacks' => array('negotiation' => 'language_from_interface'), 'file' => $file, 'weight' => 8, @@ -682,7 +684,7 @@ function language_language_negotiation_info() { ); $negotiation_info[LANGUAGE_NEGOTIATION_URL_FALLBACK] = array( - 'types' => array(LANGUAGE_TYPE_URL), + 'types' => array(Language::TYPE_URL), 'callbacks' => array('negotiation' => 'language_url_fallback'), 'file' => $file, 'weight' => 8, @@ -691,7 +693,7 @@ function language_language_negotiation_info() { ); $negotiation_info[LANGUAGE_NEGOTIATION_USER_ADMIN] = array( - 'types' => array(LANGUAGE_TYPE_INTERFACE), + 'types' => array(Language::TYPE_INTERFACE), 'callbacks' => array('negotiation' => 'language_from_user_admin'), 'file' => $file, 'weight' => 10, @@ -853,7 +855,7 @@ function language_update_locked_weights() { // Get maximum weight to update the system languages to keep them on bottom. $max_weight = db_query('SELECT MAX(weight) FROM {language} WHERE locked = 0')->fetchField(); // Loop locked languages to maintain the existing order. - foreach (language_list(LANGUAGE_LOCKED) as $language) { + foreach (language_list(Language::STATE_LOCKED) as $language) { $max_weight++; // Update system languages weight. db_update('language') diff --git a/core/modules/language/language.negotiation.inc b/core/modules/language/language.negotiation.inc index 6565c6d..eadf6a8 100644 --- a/core/modules/language/language.negotiation.inc +++ b/core/modules/language/language.negotiation.inc @@ -7,6 +7,8 @@ * Language negotiation functions. */ +use Drupal\Core\Language\Language; + /** * The language is determined using path prefix or domain. */ @@ -59,7 +61,7 @@ * The current interface language code. */ function language_from_interface() { - return language(LANGUAGE_TYPE_INTERFACE)->langcode; + return language(Language::TYPE_INTERFACE)->langcode; } /** @@ -352,7 +354,7 @@ function language_from_url($languages, Request $request = NULL) { * @return * A valid language code. */ -function language_url_fallback($language = NULL, $request = NULL, $language_type = LANGUAGE_TYPE_INTERFACE) { +function language_url_fallback($language = NULL, $request = NULL, $language_type = Language::TYPE_INTERFACE) { $default = language_default(); $prefix = (config('language.negotiation')->get('url.source') == LANGUAGE_NEGOTIATION_URL_PREFIX); @@ -439,7 +441,7 @@ function language_url_rewrite_url(&$path, &$options) { // Language can be passed as an option, or we go for current URL language. if (!isset($options['language'])) { - $language_url = language(LANGUAGE_TYPE_URL); + $language_url = language(Language::TYPE_URL); $options['language'] = $language_url; } // We allow only enabled languages here. diff --git a/core/modules/language/lib/Drupal/language/Form/NegotiationSelectedForm.php b/core/modules/language/lib/Drupal/language/Form/NegotiationSelectedForm.php index 9ef236d..306bcef 100644 --- a/core/modules/language/lib/Drupal/language/Form/NegotiationSelectedForm.php +++ b/core/modules/language/lib/Drupal/language/Form/NegotiationSelectedForm.php @@ -7,6 +7,7 @@ namespace Drupal\language\Form; +use Drupal\Core\Language\Language; use Drupal\system\SystemConfigFormBase; /** @@ -29,7 +30,7 @@ public function buildForm(array $form, array &$form_state) { $form['selected_langcode'] = array( '#type' => 'language_select', '#title' => t('Language'), - '#languages' => LANGUAGE_CONFIGURABLE | LANGUAGE_SITE_DEFAULT, + '#languages' => Language::STATE_CONFIGURABLE | Language::STATE_SITE_DEFAULT, '#default_value' => $config->get('selected_langcode'), ); diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php index 55d6e8a..1bc67da 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationElementTest.php @@ -83,7 +83,7 @@ public function testDefaultLangcode() { // Current interface. language_save_default_configuration('custom_type', 'custom_bundle', array('langcode' => 'current_interface', 'language_show' => TRUE)); $langcode = language_get_default_langcode('custom_type', 'custom_bundle'); - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $this->assertEqual($langcode, $language_interface->langcode); // Site's default. diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php index b2d0bda..770337c 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageConfigurationTest.php @@ -7,6 +7,7 @@ namespace Drupal\language\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -145,7 +146,7 @@ protected function checkConfigurableLanguageWeight($state = 'by default') { drupal_static_reset('language_list'); $max_configurable_language_weight = $this->getHighestConfigurableLanguageWeight(); $replacements = array('@event' => $state); - foreach (language_list(LANGUAGE_LOCKED) as $locked_language) { + foreach (language_list(Language::STATE_LOCKED) as $locked_language) { $replacements['%language'] = $locked_language->name; $this->assertTrue($locked_language->weight > $max_configurable_language_weight, format_string('System language %language has higher weight than configurable languages @event', $replacements)); } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php index a4a0e2d..f5875af 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageCustomLanguageConfigurationTest.php @@ -57,7 +57,7 @@ public function testLanguageConfiguration() { 'predefined_langcode' => 'custom', 'langcode' => 'white space', 'name' => 'evil markup', - 'direction' => LANGUAGE_LTR, + 'direction' => Language::DIRECTION_LTR, ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); $this->assertRaw(t('%field may only contain characters a-z, underscores, or hyphens.', array('%field' => t('Language code')))); @@ -69,7 +69,7 @@ public function testLanguageConfiguration() { 'predefined_langcode' => 'custom', 'langcode' => 'de', 'name' => 'German', - 'direction' => LANGUAGE_LTR, + 'direction' => Language::DIRECTION_LTR, ); // Add the language the first time. diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php index 92a419b..088d655 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageDependencyInjectionTest.php @@ -49,7 +49,7 @@ function testDependencyInjectedNewLanguage() { drupal_language_initialize(); $expected = language_default(); - $result = language(LANGUAGE_TYPE_INTERFACE); + $result = language(Language::TYPE_INTERFACE); foreach ($expected as $property => $value) { $this->assertEqual($expected->$property, $result->$property, format_string('The dependency injected language object %prop property equals the new Language object %prop property.', array('%prop' => $property))); } @@ -79,7 +79,7 @@ function testDependencyInjectedNewDefaultLanguage() { // The language system creates a Language object which contains the // same properties as the new default language object. $expected = new Language($new_language_default); - $result = language(LANGUAGE_TYPE_INTERFACE); + $result = language(Language::TYPE_INTERFACE); foreach ($expected as $property => $value) { $this->assertEqual($expected->$property, $result->$property, format_string('The dependency injected language object %prop property equals the default language object %prop property.', array('%prop' => $property))); } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php index 00bfd94..570ae2a 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageListTest.php @@ -181,10 +181,10 @@ function testLanguageStates() { $expected_all_languages = array('l4' => 'l4', 'l3' => 'l3', 'l2' => 'l2', 'l1' => 'l1', 'en' => 'en', 'und' => 'und', 'zxx' => 'zxx'); $expected_conf_languages = array('l3' => 'l3', 'l1' => 'l1', 'en' => 'en'); - $locked_languages = language_list(LANGUAGE_LOCKED); + $locked_languages = language_list(Language::STATE_LOCKED); $this->assertEqual(array_diff_key($expected_locked_languages, $locked_languages), array(), 'Locked languages loaded correctly.'); - $all_languages = language_list(LANGUAGE_ALL); + $all_languages = language_list(Language::STATE_ALL); $this->assertEqual(array_diff_key($expected_all_languages, $all_languages), array(), 'All languages loaded correctly.'); $conf_languages = language_list(); diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php index 8aea763..baef5ca 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageNegotiationInfoTest.php @@ -7,6 +7,7 @@ namespace Drupal\language\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -54,7 +55,7 @@ function testInfoAlterations() { // negotiation settings with the proper flag enabled. state()->set('language_test.content_language_type', TRUE); $this->languageNegotiationUpdate(); - $type = LANGUAGE_TYPE_CONTENT; + $type = Language::TYPE_CONTENT; $language_types = variable_get('language_types', language_types_get_default()); $this->assertTrue($language_types[$type], 'Content language type is configurable.'); @@ -96,7 +97,7 @@ function testInfoAlterations() { $last = state()->get('language_test.language_negotiation_last'); foreach (language_types_get_all() as $type) { $langcode = $last[$type]; - $value = $type == LANGUAGE_TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en'; + $value = $type == Language::TYPE_CONTENT || strpos($type, 'test') !== FALSE ? 'it' : 'en'; $this->assertEqual($langcode, $value, format_string('The negotiated language for %type is %language', array('%type' => $type, '%language' => $langcode))); } diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php index ac834d1..d9624e4 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageSwitchingTest.php @@ -7,6 +7,7 @@ namespace Drupal\language\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -42,7 +43,7 @@ function setUp() { */ function testLanguageBlock() { // Enable the language switching block. - $block = $this->drupalPlaceBlock('language_block:' . LANGUAGE_TYPE_INTERFACE, array('machine_name' => 'test_language_block')); + $block = $this->drupalPlaceBlock('language_block:' . Language::TYPE_INTERFACE, array('machine_name' => 'test_language_block')); // Add language. $edit = array( diff --git a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php index e614da2..b7ce84e 100644 --- a/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php +++ b/core/modules/language/lib/Drupal/language/Tests/LanguageUILanguageNegotiationTest.php @@ -139,7 +139,7 @@ function testUILanguageNegotiation() { $this->drupalPost('admin/config/regional/translate/translate', $edit, t('Save translations')); // Configure URL language rewrite. - variable_set('language_negotiation_url_type', LANGUAGE_TYPE_INTERFACE); + variable_set('language_negotiation_url_type', Language::TYPE_INTERFACE); // Configure selected language negotiation to use zh-hans. $edit = array('selected_langcode' => $langcode); @@ -231,7 +231,7 @@ function testUILanguageNegotiation() { } // Unknown language prefix should return 404. - variable_set('language_negotiation_' . LANGUAGE_TYPE_INTERFACE, language_language_negotiation_info()); + variable_set('language_negotiation_' . Language::TYPE_INTERFACE, language_language_negotiation_info()); $this->drupalGet("$langcode_unknown/admin/config", array(), $http_header_browser_fallback); $this->assertResponse(404, "Unknown language path prefix should return 404"); @@ -360,7 +360,7 @@ function testUILanguageNegotiation() { protected function runTest($test) { if (!empty($test['language_negotiation'])) { $method_weights = array_flip($test['language_negotiation']); - language_negotiation_set(LANGUAGE_TYPE_INTERFACE, $method_weights); + language_negotiation_set(Language::TYPE_INTERFACE, $method_weights); } if (!empty($test['language_negotiation_url_part'])) { config('language.negotiation') @@ -404,7 +404,7 @@ function testUrlLanguageFallback() { $this->drupalGet('admin/config/regional/language/detection'); // Enable the language switcher block. - $this->drupalPlaceBlock('language_block:' . LANGUAGE_TYPE_INTERFACE, array('machine_name' => 'test_language_block')); + $this->drupalPlaceBlock('language_block:' . Language::TYPE_INTERFACE, array('machine_name' => 'test_language_block')); // Access the front page without specifying any valid URL language prefix // and having as browser language preference a non-default language. diff --git a/core/modules/language/tests/language_test/language_test.module b/core/modules/language/tests/language_test/language_test.module index cb97937..b83373a 100644 --- a/core/modules/language/tests/language_test/language_test.module +++ b/core/modules/language/tests/language_test/language_test.module @@ -8,13 +8,15 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\HttpKernelInterface; +use Drupal\Core\Language\Language; + /** * Implements hook_init(). */ function language_test_init() { language_test_store_language_negotiation(); - if (isset(language(LANGUAGE_TYPE_INTERFACE)->langcode) && isset(language(LANGUAGE_TYPE_INTERFACE)->method_id)) { - drupal_set_message(t('Language negotiation method: @name', array('@name' => language(LANGUAGE_TYPE_INTERFACE)->method_id))); + if (isset(language(Language::TYPE_INTERFACE)->langcode) && isset(language(Language::TYPE_INTERFACE)->method_id)) { + drupal_set_message(t('Language negotiation method: @name', array('@name' => language(Language::TYPE_INTERFACE)->method_id))); } } @@ -40,7 +42,7 @@ function language_test_language_types_info() { */ function language_test_language_types_info_alter(array &$language_types) { if (state()->get('language_test.content_language_type')) { - unset($language_types[LANGUAGE_TYPE_CONTENT]['fixed']); + unset($language_types[Language::TYPE_CONTENT]['fixed']); } } @@ -61,7 +63,7 @@ function language_test_language_negotiation_info() { return array( 'test_language_negotiation_method' => array( 'name' => t('Test'), - 'types' => array(LANGUAGE_TYPE_CONTENT, 'test_language_type', 'fixed_test_language_type'), + 'types' => array(Language::TYPE_CONTENT, 'test_language_type', 'fixed_test_language_type'), ) + $info, 'test_language_negotiation_method_ts' => array( 'name' => t('Type-specific test'), diff --git a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php index a608873..fc434c6 100644 --- a/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php +++ b/core/modules/link/lib/Drupal/link/Tests/LinkFieldTest.php @@ -7,6 +7,7 @@ namespace Drupal\link\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -70,7 +71,7 @@ function testURLValidation() { )) ->save(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); @@ -140,7 +141,7 @@ function testLinkTitle() { )) ->save(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Verify that the title field works according to the field setting. foreach (array(DRUPAL_DISABLED, DRUPAL_REQUIRED, DRUPAL_OPTIONAL) as $title_setting) { @@ -247,7 +248,7 @@ function testLinkFormatter() { ->setComponent($this->field['field_name'], $display_options) ->save(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity with two link field values: // - The first field item uses a URL only. @@ -383,7 +384,7 @@ function testLinkSeparateFormatter() { ->setComponent($this->field['field_name'], $display_options) ->save(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity with two link field values: // - The first field item uses a URL only. diff --git a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php index 3f0d99b..093c787 100644 --- a/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php +++ b/core/modules/locale/lib/Drupal/locale/LocaleConfigSubscriber.php @@ -68,7 +68,7 @@ public function configContext(ConfigEvent $event) { if ($account = $context->get('user.account')) { $context->set('locale.language', language_load(user_preferred_langcode($account))); } - elseif ($language = $this->languageManager->getLanguage(LANGUAGE_TYPE_INTERFACE)) { + elseif ($language = $this->languageManager->getLanguage(Language::TYPE_INTERFACE)) { $context->set('locale.language', $language); } } diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php index 4f49d02..8188ef5 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocalePathTest.php @@ -7,6 +7,7 @@ namespace Drupal\locale\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -107,7 +108,7 @@ function testPathLanguageConfiguration() { $edit = array( 'source' => 'node/' . $node->nid, 'alias' => $custom_path, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, ); drupal_container()->get('path.crud')->save($edit['source'], $edit['alias'], $edit['langcode']); $lookup_path = drupal_container()->get('path.alias_manager')->getPathAlias('node/' . $node->nid, 'en'); @@ -129,11 +130,12 @@ function testPathLanguageConfiguration() { ); drupal_container()->get('path.crud')->save($edit['source'], $edit['alias'], $edit['langcode']); - // Assign a custom path alias to second node with LANGUAGE_NOT_SPECIFIED. + // Assign a custom path alias to second node with + // Language::LANGCODE_NOT_SPECIFIED. $edit = array( 'source' => 'node/' . $second_node->nid, 'alias' => $custom_path, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, ); drupal_container()->get('path.crud')->save($edit['source'], $edit['alias'], $edit['langcode']); diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php index f1c44dc..1547a72 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleTranslationTest.php @@ -156,7 +156,7 @@ function testStringTranslation() { locale_reset(); // Now we should get the proper fresh translation from t(). $this->assertTrue($name != $translation_to_en && t($name, array(), array('langcode' => 'en')) == $translation_to_en, t('t() works for English.')); - $this->assertTrue(t($name, array(), array('langcode' => LANGUAGE_SYSTEM)) == $name, t('t() works for LANGUAGE_SYSTEM.')); + $this->assertTrue(t($name, array(), array('langcode' => Language::LANGCODE_SYSTEM)) == $name, 't() works for Language::LANGCODE_SYSTEM.'); $search = array( 'string' => $name, diff --git a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php index ee2b0c3..85e4b1c 100644 --- a/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php +++ b/core/modules/locale/lib/Drupal/locale/Tests/LocaleUninstallTest.php @@ -62,7 +62,7 @@ function testUninstallProcess() { $language_manager->init(); // Check the UI language. - $this->assertEqual(language(LANGUAGE_TYPE_INTERFACE)->langcode, $this->langcode, t('Current language: %lang', array('%lang' => language(LANGUAGE_TYPE_INTERFACE)->langcode))); + $this->assertEqual(language(Language::TYPE_INTERFACE)->langcode, $this->langcode, t('Current language: %lang', array('%lang' => language(Language::TYPE_INTERFACE)->langcode))); // Enable multilingual workflow option for articles. language_save_default_configuration('node', 'article', array('langcode' => 'site_default', 'language_show' => TRUE)); @@ -91,9 +91,9 @@ function testUninstallProcess() { // Change language negotiation options. drupal_load('module', 'locale'); variable_set('language_types', language_types_get_default() + array('language_custom' => TRUE)); - variable_set('language_negotiation_' . LANGUAGE_TYPE_INTERFACE, language_language_negotiation_info()); - variable_set('language_negotiation_' . LANGUAGE_TYPE_CONTENT, language_language_negotiation_info()); - variable_set('language_negotiation_' . LANGUAGE_TYPE_URL, language_language_negotiation_info()); + variable_set('language_negotiation_' . Language::TYPE_INTERFACE, language_language_negotiation_info()); + variable_set('language_negotiation_' . Language::TYPE_CONTENT, language_language_negotiation_info()); + variable_set('language_negotiation_' . Language::TYPE_URL, language_language_negotiation_info()); // Change language negotiation settings. config('language.negotiation') @@ -109,7 +109,7 @@ function testUninstallProcess() { // Visit the front page. $this->drupalGet(''); // Check the init language logic. - $this->assertEqual(language(LANGUAGE_TYPE_INTERFACE)->langcode, 'en', t('Language after uninstall: %lang', array('%lang' => language(LANGUAGE_TYPE_INTERFACE)->langcode))); + $this->assertEqual(language(Language::TYPE_INTERFACE)->langcode, 'en', t('Language after uninstall: %lang', array('%lang' => language(Language::TYPE_INTERFACE)->langcode))); // Check JavaScript files deletion. $this->assertTrue($result = !file_exists($js_file), t('JavaScript file deleted: %file', array('%file' => $result ? $js_file : t('found')))); @@ -121,11 +121,11 @@ function testUninstallProcess() { // Check language negotiation. require_once DRUPAL_ROOT . '/core/includes/language.inc'; $this->assertTrue(count(language_types_get_all()) == count(language_types_get_default()), t('Language types reset')); - $language_negotiation = language_negotiation_method_get_first(LANGUAGE_TYPE_INTERFACE) == LANGUAGE_NEGOTIATION_SELECTED; + $language_negotiation = language_negotiation_method_get_first(Language::TYPE_INTERFACE) == LANGUAGE_NEGOTIATION_SELECTED; $this->assertTrue($language_negotiation, t('Interface language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set')))); - $language_negotiation = language_negotiation_method_get_first(LANGUAGE_TYPE_CONTENT) == LANGUAGE_NEGOTIATION_SELECTED; + $language_negotiation = language_negotiation_method_get_first(Language::TYPE_CONTENT) == LANGUAGE_NEGOTIATION_SELECTED; $this->assertTrue($language_negotiation, t('Content language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set')))); - $language_negotiation = language_negotiation_method_get_first(LANGUAGE_TYPE_URL) == LANGUAGE_NEGOTIATION_SELECTED; + $language_negotiation = language_negotiation_method_get_first(Language::TYPE_URL) == LANGUAGE_NEGOTIATION_SELECTED; $this->assertTrue($language_negotiation, t('URL language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set')))); // Check language negotiation method settings. diff --git a/core/modules/locale/locale.bulk.inc b/core/modules/locale/locale.bulk.inc index 6a452d8..d221c19 100644 --- a/core/modules/locale/locale.bulk.inc +++ b/core/modules/locale/locale.bulk.inc @@ -157,7 +157,7 @@ function locale_translate_export_form($form, &$form_state) { if (empty($language_options)) { $form['langcode'] = array( '#type' => 'value', - '#value' => LANGUAGE_SYSTEM, + '#value' => Language::LANGCODE_SYSTEM, ); $form['langcode_text'] = array( '#type' => 'item', @@ -172,7 +172,7 @@ function locale_translate_export_form($form, &$form_state) { '#options' => $language_options, '#default_value' => $language_default->langcode, '#empty_option' => t('Source text only, no translations'), - '#empty_value' => LANGUAGE_SYSTEM, + '#empty_value' => Language::LANGCODE_SYSTEM, ); $form['content_options'] = array( '#type' => 'details', @@ -181,7 +181,7 @@ function locale_translate_export_form($form, &$form_state) { '#tree' => TRUE, '#states' => array( 'invisible' => array( - ':input[name="langcode"]' => array('value' => LANGUAGE_SYSTEM), + ':input[name="langcode"]' => array('value' => Language::LANGCODE_SYSTEM), ), ), ); @@ -217,7 +217,7 @@ function locale_translate_export_form($form, &$form_state) { */ function locale_translate_export_form_submit($form, &$form_state) { // If template is required, language code is not given. - if ($form_state['values']['langcode'] != LANGUAGE_SYSTEM) { + if ($form_state['values']['langcode'] != Language::LANGCODE_SYSTEM) { $language = language_load($form_state['values']['langcode']); } else { @@ -420,8 +420,8 @@ function locale_translate_batch_build($files, $options) { * * @param object $file * A file object of the gettext file to be imported. The file object must - * contain a language parameter (other than LANGUAGE_NOT_SPECIFIED). This - * is used as the language of the import. + * contain a language parameter (other than Language::LANGCODE_NOT_SPECIFIED). + * This is used as the language of the import. * * @param array $options * An array with options that can have the following elements: @@ -445,7 +445,7 @@ function locale_translate_batch_import($file, $options, &$context) { 'customized' => LOCALE_NOT_CUSTOMIZED, ); - if (isset($file->langcode) && $file->langcode != LANGUAGE_NOT_SPECIFIED) { + if (isset($file->langcode) && $file->langcode != Language::LANGCODE_NOT_SPECIFIED) { try { if (empty($context['sandbox'])) { @@ -651,7 +651,7 @@ function locale_translate_file_attach_properties($file, $options = array()) { $file->langcode = isset($options['langcode']) ? $options['langcode'] : $matches[5]; } else { - $file->langcode = LANGUAGE_NOT_SPECIFIED; + $file->langcode = Language::LANGCODE_NOT_SPECIFIED; } return $file; } diff --git a/core/modules/locale/locale.install b/core/modules/locale/locale.install index 0bcf093..af08d52 100644 --- a/core/modules/locale/locale.install +++ b/core/modules/locale/locale.install @@ -5,6 +5,8 @@ * Install, update, and uninstall functions for the Locale module. */ +use Drupal\Core\Language\Language; + /** * Implements hook_install(). */ @@ -663,9 +665,9 @@ function locale_update_8007() { // Add all language type weight variables. As the function language_types() // is not available its functionality is rebuild. $language_types = update_variable_get('language_types', array( - LANGUAGE_TYPE_INTERFACE => TRUE, - LANGUAGE_TYPE_CONTENT => FALSE, - LANGUAGE_TYPE_URL => FALSE, + Language::TYPE_INTERFACE => TRUE, + Language::TYPE_CONTENT => FALSE, + Language::TYPE_URL => FALSE, )); foreach ($language_types as $language_type => $configurable) { $variable_names[] = 'language_negotiation_methods_weight_' . $language_type; diff --git a/core/modules/locale/locale.module b/core/modules/locale/locale.module index 880e335..c5fc8b1 100644 --- a/core/modules/locale/locale.module +++ b/core/modules/locale/locale.module @@ -10,6 +10,7 @@ * object files are supported. */ +use Drupal\Core\Language\Language; use Drupal\locale\LocaleLookup; use Drupal\locale\LocaleConfigSubscriber; use Drupal\locale\SourceString; @@ -358,7 +359,7 @@ function locale_translatable_language_list() { * Language code to use for the lookup. */ function locale($string = NULL, $context = NULL, $langcode = NULL) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Use the advanced drupal_static() pattern, since this is called very often. static $drupal_static_fast; @@ -432,7 +433,7 @@ function locale_storage() { * plural formula. */ function locale_get_plural($count, $langcode = NULL) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Used to locally cache the plural formulas for all languages. $plural_formulas = &drupal_static(__FUNCTION__, array()); @@ -580,7 +581,7 @@ function locale_system_remove($components) { */ function locale_js_alter(&$javascript) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $dir = 'public://' . config('local.settings')->get('javascript.directory'); $parsed = state()->get('system.javascript_parsed') ?: array(); @@ -672,7 +673,7 @@ function locale_library_info() { */ function locale_library_info_alter(&$libraries, $module) { if ($module == 'system' && isset($libraries['jquery.ui.datepicker'])) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // locale.datepicker.js should be added in the JS_LIBRARY group, so that // this attach behavior will execute early. JS_LIBRARY is the default for // hook_library_info_alter(), thus does not have to be specified explicitly. @@ -682,7 +683,7 @@ function locale_library_info_alter(&$libraries, $module) { 'jquery' => array( 'ui' => array( 'datepicker' => array( - 'isRTL' => $language_interface->direction == LANGUAGE_RTL, + 'isRTL' => $language_interface->direction == Language::DIRECTION_RTL, 'firstDay' => config('system.date')->get('first_day'), ), ), @@ -847,8 +848,8 @@ function locale_system_file_system_settings_submit(&$form, $form_state) { * Implements hook_preprocess_HOOK() for node.tpl.php. */ function locale_preprocess_node(&$variables) { - if ($variables['node']->langcode != LANGUAGE_NOT_SPECIFIED) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + if ($variables['node']->langcode != Language::LANGCODE_NOT_SPECIFIED) { + $language_interface = language(Language::TYPE_INTERFACE); $node_language = language_load($variables['node']->langcode); if ($node_language->langcode != $language_interface->langcode) { @@ -1200,7 +1201,7 @@ function _locale_invalidate_js($langcode = NULL) { function _locale_rebuild_js($langcode = NULL) { $config = config('locale.settings'); if (!isset($langcode)) { - $language = language(LANGUAGE_TYPE_INTERFACE); + $language = language(Language::TYPE_INTERFACE); } else { // Get information about the locale. diff --git a/core/modules/locale/locale.pages.inc b/core/modules/locale/locale.pages.inc index fc68a51..45149aa 100644 --- a/core/modules/locale/locale.pages.inc +++ b/core/modules/locale/locale.pages.inc @@ -5,6 +5,7 @@ * Interface translation summary, editing and deletion user interfaces. */ +use Drupal\Core\Language\Language; use Drupal\locale\SourceString; use Drupal\locale\TranslationString; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -107,7 +108,7 @@ function locale_translate_filters() { } // Pick the current interface language code for the filter. - $default_langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; + $default_langcode = language(Language::TYPE_INTERFACE)->langcode; if (!isset($language_options[$default_langcode])) { $available_langcodes = array_keys($language_options); $default_langcode = array_shift($available_langcodes); diff --git a/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php b/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php index d731718..4a9c187 100644 --- a/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php +++ b/core/modules/menu/lib/Drupal/menu/Tests/MenuNodeTest.php @@ -7,6 +7,7 @@ namespace Drupal\menu\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -61,7 +62,7 @@ function testMenuNodeFormWidget() { // Create a node. $node_title = $this->randomName(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array( "title" => $node_title, "body[$langcode][0][value]" => $this->randomString(), diff --git a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php index 9506602..de02ce2 100644 --- a/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php +++ b/core/modules/menu_link/lib/Drupal/menu_link/MenuLinkFormController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Language\Language; /** * Form controller for the node edit forms. @@ -124,7 +125,7 @@ public function form(array $form, array &$form_state, EntityInterface $menu_link $form['langcode'] = array( '#type' => 'language_select', '#title' => t('Language'), - '#languages' => LANGUAGE_ALL, + '#languages' => Language::STATE_ALL, '#default_value' => $menu_link->langcode, ); diff --git a/core/modules/node/lib/Drupal/node/NodeAccessController.php b/core/modules/node/lib/Drupal/node/NodeAccessController.php index ec68b7e..cb11b61 100644 --- a/core/modules/node/lib/Drupal/node/NodeAccessController.php +++ b/core/modules/node/lib/Drupal/node/NodeAccessController.php @@ -7,6 +7,7 @@ namespace Drupal\node; +use Drupal\Core\Language\Language; use Drupal\user\Plugin\Core\Entity\User; use Drupal\Core\Entity\EntityAccessController; use Drupal\Core\Entity\EntityInterface; @@ -20,7 +21,7 @@ class NodeAccessController extends EntityAccessController { /** * Overrides \Drupal\Core\Entity\EntityAccessController::viewAccess(). */ - public function viewAccess(EntityInterface $node, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function viewAccess(EntityInterface $node, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { if (($cached = $this->getCache($node, 'view', $langcode, $account)) !== NULL ) { return $cached; } @@ -38,7 +39,7 @@ public function viewAccess(EntityInterface $node, $langcode = LANGUAGE_DEFAULT, /** * Overrides \Drupal\Core\Entity\EntityAccessController::access(). */ - protected function access(EntityInterface $node, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + protected function access(EntityInterface $node, $operation, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { if (user_access('bypass node access', $account)) { return TRUE; } @@ -89,7 +90,7 @@ protected function access(EntityInterface $node, $operation, $langcode = LANGUAG * 'delete'. * @param string $langcode * (optional) The language code for which to check access. Defaults to - * LANGUAGE_DEFAULT. + * Language::LANGCODE_DEFAULT. * @param \Drupal\user\Plugin\Core\Entity\User $account * (optional) The user for which to check access, or NULL to check access * for the current user. Defaults to NULL. @@ -99,7 +100,7 @@ protected function access(EntityInterface $node, $operation, $langcode = LANGUAG * module implements hook_node_grants(), the node does not (yet) have an id * or none of the implementing modules explicitly granted or denied access. */ - protected function accessGrants(EntityInterface $node, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + protected function accessGrants(EntityInterface $node, $operation, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { // If no module implements the hook or the node does not have an id there is // no point in querying the database for access grants. if (!module_implements('node_grants') || !$node->id()) { diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 63b4189..81c3160 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -11,6 +11,7 @@ use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Language\Language; /** * Form controller for the node edit forms. @@ -106,7 +107,7 @@ public function form(array $form, array &$form_state, EntityInterface $node) { '#title' => t('Language'), '#type' => 'language_select', '#default_value' => $node->langcode, - '#languages' => LANGUAGE_ALL, + '#languages' => Language::STATE_ALL, '#access' => isset($language_configuration['language_show']) && $language_configuration['language_show'], ); diff --git a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php index 7ee1e85..2fc38ad 100644 --- a/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/MultiStepNodeFormBasicOptionsTest.php @@ -7,6 +7,7 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -64,7 +65,7 @@ function testMultiStepNodeFormBasicOptions() { ), ); field_create_instance($this->instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array( 'title' => 'a', diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php index 0db0bda..df94cec 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessFieldTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; + /** * Tests the interaction of the node access system with fields. */ @@ -55,7 +57,7 @@ public function setUp() { */ function testNodeAccessAdministerField() { // Create a page node. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $field_data = array(); $value = $field_data[0]['value'] = $this->randomName(); $node = $this->drupalCreateNode(array($this->field_name => $field_data)); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php index fceb154..8ba7788 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessLanguageTest.php @@ -78,7 +78,7 @@ function testNodeAccess() { // Creating a public node with no special langcode, like when no language // module enabled. $node_public_no_language = $this->drupalCreateNode(array('private' => FALSE)); - $this->assertTrue($node_public_no_language->langcode == LANGUAGE_NOT_SPECIFIED, 'Node created with not specified language.'); + $this->assertTrue($node_public_no_language->langcode == Language::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); // Tests that access is granted if requested with no language. $this->assertNodeAccess($expected_node_access, $node_public_no_language, $web_user); @@ -137,7 +137,7 @@ function testNodeAccessPrivate() { // Creating a private node with no special langcode, like when no language // module enabled. $node_private_no_language = $this->drupalCreateNode(array('private' => TRUE)); - $this->assertTrue($node_private_no_language->langcode == LANGUAGE_NOT_SPECIFIED, 'Node created with not specified language.'); + $this->assertTrue($node_private_no_language->langcode == Language::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); // Tests that access is not granted if requested with no language. $this->assertNodeAccess($expected_node_access_no_access, $node_private_no_language, $web_user); @@ -189,7 +189,7 @@ function testNodeAccessQueryTag() { // Creating a public node with no special langcode, like when no language // module enabled. $node_no_language = $this->drupalCreateNode(array('private' => FALSE)); - $this->assertTrue($node_no_language->langcode == LANGUAGE_NOT_SPECIFIED, 'Node created with not specified language.'); + $this->assertTrue($node_no_language->langcode == Language::LANGCODE_NOT_SPECIFIED, 'Node created with not specified language.'); // Query the nodes table as the web user with the node access tag and no // specific langcode. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php index a9ae1c3..9d022c5 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeAccessPagerTest.php @@ -7,6 +7,7 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php index 36baad2..5876974 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeCreationTest.php @@ -8,6 +8,7 @@ namespace Drupal\node\Tests; use Drupal\Core\Database\Database; +use Drupal\Core\Language\Language; use Exception; /** @@ -45,7 +46,7 @@ function setUp() { function testNodeCreation() { // Create a node. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(8); $edit["body[$langcode][0][value]"] = $this->randomName(16); $this->drupalPost('node/add/page', $edit, t('Save')); @@ -67,7 +68,7 @@ function testFailedPageCreation() { 'uid' => $this->loggedInUser->uid, 'name' => $this->loggedInUser->name, 'type' => 'page', - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'title' => 'testing_transaction_exception', ); @@ -112,7 +113,7 @@ function testUnpublishedNodeCreation() { // Create a node. $edit = array(); $edit["title"] = $this->randomName(8); - $edit["body[" . LANGUAGE_NOT_SPECIFIED . "][0][value]"] = $this->randomName(16); + $edit["body[" . Language::LANGCODE_NOT_SPECIFIED . "][0][value]"] = $this->randomName(16); $this->drupalPost('node/add/page', $edit, t('Save')); // Check that the user was redirected to the home page. diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeEntityFieldQueryAlterTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeEntityFieldQueryAlterTest.php index 9cc80f7..b284d96 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeEntityFieldQueryAlterTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeEntityFieldQueryAlterTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; + /** * Tests node_query_entity_field_access_alter(). */ @@ -44,7 +46,7 @@ function setUp() { // Creating 4 nodes with an entity field so we can test that sort of query // alter. All field values starts with 'A' so we can identify and fetch them // in the node_access_test module. - $settings = array('langcode' => LANGUAGE_NOT_SPECIFIED); + $settings = array('langcode' => Language::LANGCODE_NOT_SPECIFIED); for ($i = 0; $i < 4; $i++) { $body = array( 'value' => 'A' . $this->randomName(32), diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeEntityViewModeAlterTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeEntityViewModeAlterTest.php index f072254..1915dbf 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeEntityViewModeAlterTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeEntityViewModeAlterTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; + /** * Tests changing view modes for nodes. */ @@ -34,7 +36,7 @@ function testNodeViewModeChange() { // Create a node. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(8); $edit["body[$langcode][0][value]"] = t('Data that should appear only in the body for the node.'); $edit["body[$langcode][0][summary]"] = t('Extra data that should appear only in the teaser for the node.'); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php index f382457..cffc3f3 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeFieldMultilingualTestCase.php @@ -99,7 +99,7 @@ function testMultilingualNodeForm() { $this->assertTrue($node->language()->langcode == $langcode && $node->body->value == $body_value, 'Field language correctly changed.'); // Enable content language URL detection. - language_negotiation_set(LANGUAGE_TYPE_CONTENT, array(LANGUAGE_NEGOTIATION_URL => 0)); + language_negotiation_set(Language::TYPE_CONTENT, array(LANGUAGE_NEGOTIATION_URL => 0)); // Test multilingual field language fallback logic. $this->drupalGet("it/node/{$node->id()}"); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php index ce48614..c72dc25 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodePostSettingsTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; + /** * Checks that the post information displays when enabled for a content type. */ @@ -39,7 +41,7 @@ function testPagePostInfo() { // Create a node. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(8); $edit["body[$langcode][0][value]"] = $this->randomName(16); $this->drupalPost('node/add/page', $edit, t('Save')); @@ -62,7 +64,7 @@ function testPageNotPostInfo() { // Create a node. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(8); $edit["body[$langcode][0][value]"] = $this->randomName(16); $this->drupalPost('node/add/page', $edit, t('Save')); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php index 90a7305..746915e 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsAllTestCase.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; + /** * Tests actions against revisions for user with access to all revisions. */ @@ -96,7 +98,7 @@ function testRevisions() { // Confirm the correct revision text appears on "view revisions" page. $this->drupalGet("node/$node->nid/revisions/$node->vid/view"); - $this->assertText($node->body[LANGUAGE_NOT_SPECIFIED][0]['value'], t('Correct text displays for version.')); + $this->assertText($node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], t('Correct text displays for version.')); // Confirm the correct log message appears on "revisions overview" page. $this->drupalGet("node/$node->nid/revisions"); @@ -117,7 +119,7 @@ function testRevisions() { )), 'Revision reverted.'); $reverted_node = node_load($node->nid, TRUE); - $this->assertTrue(($nodes[1]->body[LANGUAGE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[LANGUAGE_NOT_SPECIFIED][0]['value']), t('Node reverted correctly.')); + $this->assertTrue(($nodes[1]->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value']), t('Node reverted correctly.')); // Confirm that this is not the current version. $node = node_revision_load($node->vid); diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php index 46244b8..27e49cd 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeRevisionsTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; + /** * Tests the node revision functionality. */ @@ -84,7 +86,7 @@ function testRevisions() { // Confirm the correct revision text appears on "view revisions" page. $this->drupalGet("node/$node->nid/revisions/$node->vid/view"); - $this->assertText($node->body[LANGUAGE_NOT_SPECIFIED][0]['value'], 'Correct text displays for version.'); + $this->assertText($node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], 'Correct text displays for version.'); // Confirm the correct log message appears on "revisions overview" page. $this->drupalGet("node/$node->nid/revisions"); @@ -101,7 +103,7 @@ function testRevisions() { array('@type' => 'Basic page', '%title' => $nodes[1]->label(), '%revision-date' => format_date($nodes[1]->revision_timestamp))), 'Revision reverted.'); $reverted_node = node_load($node->nid, TRUE); - $this->assertTrue(($nodes[1]->body[LANGUAGE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[LANGUAGE_NOT_SPECIFIED][0]['value']), 'Node reverted correctly.'); + $this->assertTrue(($nodes[1]->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value']), 'Node reverted correctly.'); // Confirm that this is not the default version. $node = node_revision_load($node->vid); @@ -134,7 +136,7 @@ function testRevisions() { // This will create a new revision that is not "front facing". $new_node_revision = clone $node; $new_body = $this->randomName(); - $new_node_revision->body[LANGUAGE_NOT_SPECIFIED][0]['value'] = $new_body; + $new_node_revision->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = $new_body; // Save this as a non-default revision. $new_node_revision->setNewRevision(); $new_node_revision->isDefaultRevision = FALSE; diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php index d17de34..5f44bf0 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTokenReplaceTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; + /** * Test node token replacement in strings. */ @@ -23,7 +25,7 @@ public static function getInfo() { * Creates a node, then tests the tokens generated from it. */ function testNodeTokenReplacement() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $url_options = array( 'absolute' => TRUE, 'language' => $language_interface, diff --git a/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php b/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php index 2643981..27e31c6 100644 --- a/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/NodeTypeInitialLanguageTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; + /** * Tests related to node type initial language. */ @@ -98,7 +100,7 @@ function testNodeTypeInitialLanguageDefaults() { * Tests language field visibility features. */ function testLanguageFieldVisibility() { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Creates a node to test Language field visibility feature. $edit = array( diff --git a/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php b/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php index b461492..8d963d4 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PageEditTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; + /** * Tests the node edit functionality. */ @@ -35,7 +37,7 @@ function setUp() { function testPageEdit() { $this->drupalLogin($this->web_user); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $title_key = "title"; $body_key = "body[$langcode][0][value]"; // Create node to edit. @@ -103,7 +105,7 @@ function testPageAuthoredBy() { $this->drupalLogin($this->admin_user); // Create node to edit. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $body_key = "body[$langcode][0][value]"; $edit = array(); $edit['title'] = $this->randomName(8); diff --git a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php index 28b04cd..0c82d25 100644 --- a/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php +++ b/core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php @@ -7,6 +7,8 @@ namespace Drupal\node\Tests; +use Drupal\Core\Language\Language; + /** * Tests the node entity preview functionality. */ @@ -38,7 +40,7 @@ function setUp() { 'name' => $this->randomName(), 'description' => $this->randomName(), 'vid' => $this->randomName(), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGUAGE_NOT_SPECIFIED, 'help' => '', )); $vocabulary->save(); @@ -50,7 +52,7 @@ function setUp() { 'name' => $this->randomName(), 'description' => $this->randomName(), 'vid' => $this->vocabulary->id(), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGUAGE_NOT_SPECIFIED, )); $term->save(); @@ -96,7 +98,7 @@ function setUp() { * Checks the node preview functionality. */ function testPagePreview() { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $title_key = "title"; $body_key = "body[$langcode][0][value]"; $term_key = "{$this->field_name}[$langcode]"; @@ -125,7 +127,7 @@ function testPagePreview() { * Checks the node preview functionality, when using revisions. */ function testPagePreviewWithRevisions() { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $title_key = "title"; $body_key = "body[$langcode][0][value]"; $term_key = "{$this->field_name}[$langcode]"; diff --git a/core/modules/node/node.admin.inc b/core/modules/node/node.admin.inc index 139b2d2..3b05a80 100644 --- a/core/modules/node/node.admin.inc +++ b/core/modules/node/node.admin.inc @@ -6,6 +6,7 @@ */ use Drupal\Core\Database\Query\SelectInterface; +use Drupal\Core\Language\Language; /** * Page callback: Form constructor for the permission rebuild confirmation form. @@ -110,7 +111,7 @@ function node_filters() { // Language filter if language support is present. if (language_multilingual()) { - $languages = language_list(LANGUAGE_ALL); + $languages = language_list(Language::STATE_ALL); foreach ($languages as $langcode => $language) { // Make locked languages appear special in the list. $language_options[$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; @@ -517,7 +518,7 @@ function node_admin_nodes() { $nodes = node_load_multiple($nids); // Prepare the list of nodes. - $languages = language_list(LANGUAGE_ALL); + $languages = language_list(Language::STATE_ALL); $destination = drupal_get_destination(); $form['nodes'] = array( '#type' => 'table', @@ -525,7 +526,7 @@ function node_admin_nodes() { '#empty' => t('No content available.'), ); foreach ($nodes as $node) { - $l_options = $node->langcode != LANGUAGE_NOT_SPECIFIED && isset($languages[$node->langcode]) ? array('language' => $languages[$node->langcode]) : array(); + $l_options = $node->langcode != Language::LANGCODE_NOT_SPECIFIED && isset($languages[$node->langcode]) ? array('language' => $languages[$node->langcode]) : array(); $form['nodes'][$node->nid]['title'] = array( '#type' => 'link', '#title' => $node->label(), diff --git a/core/modules/node/node.install b/core/modules/node/node.install index b0735d3..67cd0c3 100644 --- a/core/modules/node/node.install +++ b/core/modules/node/node.install @@ -5,6 +5,8 @@ * Install, update and uninstall functions for the node module. */ +use Drupal\Core\Language\Language; + /** * Implements hook_schema(). */ @@ -516,7 +518,7 @@ function node_update_8002() { function node_update_8003() { $types = db_query('SELECT type FROM {node_type}')->fetchCol(); foreach ($types as $type) { - update_variable_set('node_type_language_default_' . $type, LANGUAGE_NOT_SPECIFIED); + update_variable_set('node_type_language_default_' . $type, Language::LANGCODE_NOT_SPECIFIED); $node_type_language = update_variable_get('node_type_language_' . $type, 0); if ($node_type_language == 0) { update_variable_set('node_type_language_show_' . $type, FALSE); @@ -524,7 +526,7 @@ function node_update_8003() { if ($node_type_language == 2) { // Translation was enabled, so enable it again and // unhide the language selector. Because if language is - // LANGUAGE_NOT_SPECIFIED and the selector hidden, translation + // Language::LANGCODE_NOT_SPECIFIED and the selector hidden, translation // cannot be enabled. update_variable_set('node_type_language_show_' . $type, TRUE); update_variable_set('node_type_language_translation_enabled_' . $type, TRUE); diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 36dcfe0..d5d2840 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -8,6 +8,7 @@ * API pattern. */ +use Drupal\Core\Language\Language; use Symfony\Component\HttpFoundation\Response; use Drupal\Core\Cache\CacheBackendInterface; @@ -716,7 +717,7 @@ function node_type_update_nodes($old_type, $type) { * type object by $type->disabled being set to TRUE. */ function _node_types_build($rebuild = FALSE) { - $cid = 'node_types:' . language(LANGUAGE_TYPE_INTERFACE)->langcode; + $cid = 'node_types:' . language(Language::TYPE_INTERFACE)->langcode; if (!$rebuild) { $_node_types = &drupal_static(__FUNCTION__); @@ -2078,7 +2079,7 @@ function node_block_access($block) { */ function node_feed($nids = FALSE, $channel = array()) { global $base_url; - $language_content = language(LANGUAGE_TYPE_CONTENT); + $language_content = language(Language::TYPE_CONTENT); $rss_config = config('system.rss'); if ($nids === FALSE) { @@ -2321,7 +2322,7 @@ function node_form_search_form_alter(&$form, $form_state) { // Languages: $language_options = array(); - foreach (language_list(LANGUAGE_ALL) as $langcode => $language) { + foreach (language_list(Language::STATE_ALL) as $langcode => $language) { // Make locked languages appear special in the list. $language_options[$langcode] = $language->locked ? t('- @name -', array('@name' => $language->name)) : $language->name; } @@ -2525,7 +2526,7 @@ function node_access($op, $node, $account = NULL, $langcode = NULL) { // Load languages the node exists in. $node_translations = $node->getTranslationLanguages(); // Load the language from content negotiation. - $content_negotiation_langcode = language(LANGUAGE_TYPE_CONTENT)->langcode; + $content_negotiation_langcode = language(Language::TYPE_CONTENT)->langcode; // If there is a translation available, use it. if (isset($node_translations[$content_negotiation_langcode])) { $langcode = $content_negotiation_langcode; diff --git a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php index 925828c..2d23ad9 100644 --- a/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php +++ b/core/modules/number/lib/Drupal/number/Tests/NumberFieldTest.php @@ -7,6 +7,7 @@ namespace Drupal\number\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -76,7 +77,7 @@ function testNumberDecimalField() { // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value]", '', 'Widget is displayed'); $this->assertRaw('placeholder="0.00"'); diff --git a/core/modules/openid/openid.inc b/core/modules/openid/openid.inc index 8d5aae9..a4b9b2c 100644 --- a/core/modules/openid/openid.inc +++ b/core/modules/openid/openid.inc @@ -5,6 +5,8 @@ * OpenID utility functions. */ +use Drupal\Core\Language\Language; + /** * Diffie-Hellman Key Exchange Default Value. * @@ -83,7 +85,7 @@ function openid_redirect_http($url, $message) { * Creates a js auto-submit redirect for (for the 2.x protocol) */ function openid_redirect($url, $message) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $output = '' . "\n"; $output .= '' . "\n"; diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesValidationTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesValidationTest.php index 693605a..5ede47b 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesValidationTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsDynamicValuesValidationTest.php @@ -7,6 +7,7 @@ namespace Drupal\options\Tests; +use Drupal\Core\Language\Language; use Drupal\field\FieldValidationException; /** @@ -27,7 +28,7 @@ public static function getInfo() { function testDynamicAllowedValues() { // Verify that the test passes against every value we had. foreach ($this->test as $key => $value) { - $this->entity->test_options[LANGUAGE_NOT_SPECIFIED][0]['value'] = $value; + $this->entity->test_options[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = $value; try { field_attach_validate($this->entity); $this->pass("$key should pass"); @@ -39,7 +40,7 @@ function testDynamicAllowedValues() { } // Now verify that the test does not pass against anything else. foreach ($this->test as $key => $value) { - $this->entity->test_options[LANGUAGE_NOT_SPECIFIED][0]['value'] = is_numeric($value) ? (100 - $value) : ('X' . $value); + $this->entity->test_options[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = is_numeric($value) ? (100 - $value) : ('X' . $value); $pass = FALSE; try { field_attach_validate($this->entity); diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php index ca9d605..e6f2881 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsFieldTest.php @@ -7,6 +7,7 @@ namespace Drupal\options\Tests; +use Drupal\Core\Language\Language; use Drupal\field\FieldException; use Drupal\field\Tests\FieldUnitTestBase; @@ -61,7 +62,7 @@ function setUp() { * Test that allowed values can be updated. */ function testUpdateAllowedValues() { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // All three options appear. $entity = entity_create('entity_test', array()); diff --git a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php index 023f012..818fd48 100644 --- a/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php +++ b/core/modules/options/lib/Drupal/options/Tests/OptionsWidgetsTest.php @@ -7,6 +7,7 @@ namespace Drupal\options\Tests; +use Drupal\Core\Language\Language; use Drupal\field\Tests\FieldTestBase; /** @@ -87,7 +88,7 @@ function testRadioButtons() { ), ); $instance = field_create_instance($instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity. $entity_init = field_test_create_entity(); @@ -141,7 +142,7 @@ function testCheckBoxes() { ), ); $instance = field_create_instance($instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity. $entity_init = field_test_create_entity(); @@ -229,7 +230,7 @@ function testSelectListSingle() { ), ); $instance = field_create_instance($instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity. $entity_init = field_test_create_entity(); @@ -325,7 +326,7 @@ function testSelectListMultiple() { ), ); $instance = field_create_instance($instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity. $entity_init = field_test_create_entity(); @@ -442,7 +443,7 @@ function testOnOffCheckbox() { ), ); $instance = field_create_instance($instance); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Create an entity. $entity_init = field_test_create_entity(); diff --git a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php index 455a3f6..f592b72 100644 --- a/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php +++ b/core/modules/path/lib/Drupal/path/Tests/PathLanguageTest.php @@ -7,6 +7,8 @@ namespace Drupal\path\Tests; +use Drupal\Core\Language\Language; + /** * Tests URL aliases for translated nodes. */ @@ -74,7 +76,7 @@ function testAliasTranslation() { $this->drupalGet('node/' . $english_node->nid . '/translate'); $this->clickLink(t('Add translation')); $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(); $edit["body[$langcode][0][value]"] = $this->randomName(); $french_alias = $this->randomName(); diff --git a/core/modules/path/path.admin.inc b/core/modules/path/path.admin.inc index 0535454..ff92741 100644 --- a/core/modules/path/path.admin.inc +++ b/core/modules/path/path.admin.inc @@ -5,6 +5,8 @@ * Administrative page callbacks for the path module. */ +use Drupal\Core\Language\Language; + /** * Returns a listing of all defined URL aliases. * @@ -16,7 +18,7 @@ function path_admin_overview($keys = NULL) { $build['path_admin_filter_form'] = drupal_get_form('path_admin_filter_form', $keys); // Enable language column if language.module is enabled or if we have any // alias with a language. - $alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE langcode <> :langcode', 0, 1, array(':langcode' => LANGUAGE_NOT_SPECIFIED))->fetchField(); + $alias_exists = (bool) db_query_range('SELECT 1 FROM {url_alias} WHERE langcode <> :langcode', 0, 1, array(':langcode' => Language::LANGCODE_NOT_SPECIFIED))->fetchField(); $multilanguage = (module_exists('language') || $alias_exists); $header = array(); @@ -127,7 +129,7 @@ function path_admin_edit($path = array()) { * @see path_admin_form_submit() * @see path_admin_form_delete_submit() */ -function path_admin_form($form, &$form_state, $path = array('source' => '', 'alias' => '', 'langcode' => LANGUAGE_NOT_SPECIFIED, 'pid' => NULL)) { +function path_admin_form($form, &$form_state, $path = array('source' => '', 'alias' => '', 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'pid' => NULL)) { $form['source'] = array( '#type' => 'textfield', '#title' => t('Existing system path'), @@ -160,7 +162,7 @@ function path_admin_form($form, &$form_state, $path = array('source' => '', 'ali '#type' => 'select', '#title' => t('Language'), '#options' => $language_options, - '#empty_value' => LANGUAGE_NOT_SPECIFIED, + '#empty_value' => Language::LANGCODE_NOT_SPECIFIED, '#empty_option' => t('- None -'), '#default_value' => $path['langcode'], '#weight' => -10, @@ -222,7 +224,7 @@ function path_admin_form_validate($form, &$form_state) { $pid = isset($form_state['values']['pid']) ? $form_state['values']['pid'] : 0; // Language is only set if language.module is enabled, otherwise save for all // languages. - $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : LANGUAGE_NOT_SPECIFIED; + $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : Language::LANGCODE_NOT_SPECIFIED; $has_alias = db_query("SELECT COUNT(alias) FROM {url_alias} WHERE pid <> :pid AND alias = :alias AND langcode = :langcode", array( ':pid' => $pid, @@ -255,7 +257,7 @@ function path_admin_form_submit($form, &$form_state) { $alias = $form_state['values']['alias']; // Language is only set if language.module is enabled, otherwise save for all // languages. - $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : LANGUAGE_NOT_SPECIFIED; + $langcode = isset($form_state['values']['langcode']) ? $form_state['values']['langcode'] : Language::LANGCODE_NOT_SPECIFIED; drupal_container()->get('path.crud')->save($source, $alias, $langcode, $pid); diff --git a/core/modules/path/path.module b/core/modules/path/path.module index b6a38f6..a15819c 100644 --- a/core/modules/path/path.module +++ b/core/modules/path/path.module @@ -7,6 +7,7 @@ use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\taxonomy\Plugin\Core\Entity\Term; /** @@ -103,7 +104,7 @@ function path_form_node_form_alter(&$form, $form_state) { $path = array(); if (!empty($node->nid)) { $conditions = array('source' => 'node/' . $node->nid); - if ($node->langcode != LANGUAGE_NOT_SPECIFIED) { + if ($node->langcode != Language::LANGCODE_NOT_SPECIFIED) { $conditions['langcode'] = $node->langcode; } $path = drupal_container()->get('path.crud')->load($conditions); @@ -115,7 +116,7 @@ function path_form_node_form_alter(&$form, $form_state) { 'pid' => NULL, 'source' => isset($node->nid) ? 'node/' . $node->nid : NULL, 'alias' => '', - 'langcode' => isset($node->langcode) ? $node->langcode : LANGUAGE_NOT_SPECIFIED, + 'langcode' => isset($node->langcode) ? $node->langcode : Language::LANGCODE_NOT_SPECIFIED, ); $form['path'] = array( @@ -193,7 +194,7 @@ function path_node_insert(EntityInterface $node) { if (!empty($alias)) { // Ensure fields for programmatic executions. $source = 'node/' . $node->nid; - $langcode = isset($node->langcode) ? $node->langcode : LANGUAGE_NOT_SPECIFIED; + $langcode = isset($node->langcode) ? $node->langcode : Language::LANGCODE_NOT_SPECIFIED; drupal_container()->get('path.crud')->save($source, $alias, $langcode); } } @@ -214,7 +215,7 @@ function path_node_update(EntityInterface $node) { if (!empty($path['alias'])) { // Ensure fields for programmatic executions. $source = 'node/' . $node->nid; - $langcode = isset($node->langcode) ? $node->langcode : LANGUAGE_NOT_SPECIFIED; + $langcode = isset($node->langcode) ? $node->langcode : Language::LANGCODE_NOT_SPECIFIED; drupal_container()->get('path.crud')->save($source, $alias, $langcode, $path['pid']); } } @@ -243,7 +244,7 @@ function path_form_taxonomy_term_form_alter(&$form, $form_state) { 'pid' => NULL, 'source' => isset($term->tid) ? 'taxonomy/term/' . $term->tid : NULL, 'alias' => '', - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, ); $form['path'] = array( '#access' => user_access('create url aliases') || user_access('administer url aliases'), @@ -275,7 +276,7 @@ function path_taxonomy_term_insert(Term $term) { if (!empty($path['alias'])) { // Ensure fields for programmatic executions. $path['source'] = 'taxonomy/term/' . $term->tid; - $path['langcode'] = LANGUAGE_NOT_SPECIFIED; + $path['langcode'] = Language::LANGCODE_NOT_SPECIFIED; drupal_container()->get('path.crud')->save($path['source'], $path['alias'], $path['langcode']); } } @@ -297,7 +298,7 @@ function path_taxonomy_term_update(Term $term) { $pid = (!empty($path['pid']) ? $path['pid'] : NULL); // Ensure fields for programmatic executions. $path['source'] = 'taxonomy/term/' . $term->tid; - $path['langcode'] = LANGUAGE_NOT_SPECIFIED; + $path['langcode'] = Language::LANGCODE_NOT_SPECIFIED; drupal_container()->get('path.crud')->save($path['source'], $path['alias'], $path['langcode'], $pid); } } diff --git a/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php b/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php index ffab8c5..f954bdd 100644 --- a/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php +++ b/core/modules/php/lib/Drupal/php/Tests/PhpFilterTest.php @@ -7,6 +7,8 @@ namespace Drupal\php\Tests; +use Drupal\Core\Language\Language; + /** * Tests to make sure the PHP filter actually evaluates PHP code when used. */ @@ -37,7 +39,7 @@ function testPhpFilter() { // Change filter to PHP filter and see that PHP code is evaluated. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["body[$langcode][0][format]"] = $this->php_code_format->format; $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); $this->assertRaw(t('Basic page %title has been updated.', array('%title' => $node->label())), 'PHP code filter turned on.'); diff --git a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php index c8cd4cb..3d61841 100644 --- a/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php +++ b/core/modules/picture/lib/Drupal/picture/Tests/PictureFieldDisplayTest.php @@ -7,6 +7,7 @@ namespace Drupal\picture\Tests; +use Drupal\Core\Language\Language; use Drupal\breakpoint\Plugin\Core\Entity\Breakpoint; use Drupal\image\Tests\ImageFieldTestBase; @@ -122,7 +123,7 @@ public function _testPictureFieldFormatters($scheme) { $node = node_load($nid, TRUE); // Test that the default formatter is being used. - $image_uri = file_load($node->{$field_name}[LANGUAGE_NOT_SPECIFIED][0]['fid'])->uri; + $image_uri = file_load($node->{$field_name}[Language::LANGCODE_NOT_SPECIFIED][0]['fid'])->uri; $image_info = array( 'uri' => $image_uri, 'width' => 40, diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php index 6f99dae..9904ca8 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php @@ -7,6 +7,7 @@ namespace Drupal\rdf\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -102,7 +103,7 @@ function testAttributesInMarkupFile() { $admin_user = $this->drupalCreateUser(array('edit own article content', 'revert article revisions', 'administer content types')); $this->drupalLogin($admin_user); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $bundle_name = "article"; $field_name = 'file_test'; @@ -157,7 +158,7 @@ function testAttributesInMarkupFile() { $tag1 = $this->randomName(8); $tag2 = $this->randomName(8); $edit = array(); - $edit['field_tags[' . LANGUAGE_NOT_SPECIFIED . ']'] = "$tag1, $tag2"; + $edit['field_tags[' . Language::LANGCODE_NOT_SPECIFIED . ']'] = "$tag1, $tag2"; $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save')); $term_1_id = key(taxonomy_term_load_multiple_by_name($tag1)); $taxonomy_term_1_uri = url('taxonomy/term/' . $term_1_id, array('absolute' => TRUE)); diff --git a/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php b/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php index b78cabd..0e6e4bb 100644 --- a/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php +++ b/core/modules/rdf/lib/Drupal/rdf/Tests/TrackerAttributesTest.php @@ -7,6 +7,7 @@ namespace Drupal\rdf\Tests; +use Drupal\Core\Language\Language; use Drupal\Core\Entity\EntityInterface; use Drupal\simpletest\WebTestBase; @@ -125,7 +126,7 @@ function _testBasicTrackerRdfaMarkup(EntityInterface $node) { // Adds new comment to ensure the tracker is updated accordingly. $comment = array( 'subject' => $this->randomName(), - 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this->randomName(), + 'comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]' => $this->randomName(), ); $this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save')); diff --git a/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php b/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php index cb7fb6e..51dd335 100644 --- a/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php +++ b/core/modules/rest/lib/Drupal/rest/Tests/ReadTest.php @@ -7,6 +7,7 @@ namespace Drupal\rest\Tests; +use Drupal\Core\Language\Language; use Drupal\rest\Tests\RESTTestBase; /** diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php index 30073d7..5ea6932 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentCountToggleTest.php @@ -7,6 +7,8 @@ namespace Drupal\search\Tests; +use Drupal\Core\Language\Language; + /** * Tests that comment count display toggles properly on comment status of node * @@ -58,7 +60,7 @@ function setUp() { // Create a comment array $edit_comment = array(); $edit_comment['subject'] = $this->randomName(); - $edit_comment['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]'] = $this->randomName(); + $edit_comment['comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]'] = $this->randomName(); // Post comment to the test node with comment $this->drupalPost('comment/reply/' . $this->searchable_nodes['1 comment']->nid, $edit_comment, t('Save')); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php index 04d78a4..4d2a7ed 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchCommentTest.php @@ -7,6 +7,8 @@ namespace Drupal\search\Tests; +use Drupal\Core\Language\Language; + /** * Test integration searching comments. */ @@ -75,9 +77,9 @@ function testSearchResultsComment() { // Post a comment using 'Full HTML' text format. $edit_comment = array(); $edit_comment['subject'] = 'Test comment subject'; - $edit_comment['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]'] = '

' . $comment_body . '

'; + $edit_comment['comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]'] = '

' . $comment_body . '

'; $full_html_format_id = 'full_html'; - $edit_comment['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][format]'] = $full_html_format_id; + $edit_comment['comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][format]'] = $full_html_format_id; $this->drupalPost('comment/reply/' . $node->nid, $edit_comment, t('Save')); // Invoke search index update. @@ -103,7 +105,7 @@ function testSearchResultsComment() { // Verify that comment is rendered using proper format. $this->assertText($comment_body, 'Comment body text found in search results.'); $this->assertNoRaw(t('n/a'), 'HTML in comment body is not hidden.'); - $this->assertNoRaw(check_plain($edit_comment['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]']), 'HTML in comment body is not escaped.'); + $this->assertNoRaw(check_plain($edit_comment['comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]']), 'HTML in comment body is not escaped.'); // Hide comments. $this->drupalLogin($this->admin_user); @@ -136,7 +138,7 @@ function testSearchResultsCommentAccess() { // Post a comment using 'Full HTML' text format. $edit_comment = array(); $edit_comment['subject'] = $this->comment_subject; - $edit_comment['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]'] = '

' . $comment_body . '

'; + $edit_comment['comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]'] = '

' . $comment_body . '

'; $this->drupalPost('comment/reply/' . $this->node->nid, $edit_comment, t('Save')); $this->drupalLogout(); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php index 894fd67..8d91a82 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchConfigSettingsFormTest.php @@ -7,6 +7,8 @@ namespace Drupal\search\Tests; +use Drupal\Core\Language\Language; + /** * Test config page. */ @@ -42,7 +44,7 @@ function setUp() { $this->search_node = $node; // Link the node to itself to test that it's only indexed once. The content // also needs the word "pizza" so we can use it as the search keyword. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $body_key = "body[$langcode][0][value]"; $edit[$body_key] = l($node->label(), 'node/' . $node->nid) . ' pizza sandwich'; $this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save and keep published')); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchMatchTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchMatchTest.php index 118cbf7..0f3d574 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchMatchTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchMatchTest.php @@ -7,6 +7,8 @@ namespace Drupal\search\Tests; +use Drupal\Core\Language\Language; + // The search index can contain different types of content. Typically the type // is 'node'. Here we test with _test_ and _test2_ as the type. const SEARCH_TYPE = '_test_'; @@ -37,10 +39,10 @@ function _setup() { config('search.settings')->set('index.minimum_word_size', 3)->save(); for ($i = 1; $i <= 7; ++$i) { - search_index($i, SEARCH_TYPE, $this->getText($i), LANGUAGE_NOT_SPECIFIED); + search_index($i, SEARCH_TYPE, $this->getText($i), Language::LANGCODE_NOT_SPECIFIED); } for ($i = 1; $i <= 5; ++$i) { - search_index($i + 7, SEARCH_TYPE_2, $this->getText2($i), LANGUAGE_NOT_SPECIFIED); + search_index($i + 7, SEARCH_TYPE_2, $this->getText2($i), Language::LANGCODE_NOT_SPECIFIED); } // No getText builder function for Japanese text; just a simple array. foreach (array( @@ -48,7 +50,7 @@ function _setup() { 14 => 'ドルーパルが大好きよ!', 15 => 'コーヒーとケーキ', ) as $i => $jpn) { - search_index($i, SEARCH_TYPE_JPN, $jpn, LANGUAGE_NOT_SPECIFIED); + search_index($i, SEARCH_TYPE_JPN, $jpn, Language::LANGCODE_NOT_SPECIFIED); } search_update_totals(); } diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchNumberMatchingTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchNumberMatchingTest.php index 1e3bf78..119bd4c 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchNumberMatchingTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchNumberMatchingTest.php @@ -7,6 +7,8 @@ namespace Drupal\search\Tests; +use Drupal\Core\Language\Language; + /** * Tests that numbers can be searched, with more complex matching. */ @@ -47,7 +49,7 @@ function setUp() { $info = array( 'body' => array(array('value' => $num)), 'type' => 'page', - 'language' => LANGUAGE_NOT_SPECIFIED, + 'language' => Language::LANGCODE_NOT_SPECIFIED, ); $this->nodes[] = $this->drupalCreateNode($info); } diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchNumbersTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchNumbersTest.php index 6e81e5e..e52dfd4 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchNumbersTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchNumbersTest.php @@ -7,6 +7,8 @@ namespace Drupal\search\Tests; +use Drupal\Core\Language\Language; + /** * Tests that numbers can be searched. */ @@ -53,7 +55,7 @@ function setUp() { $info = array( 'body' => array(array('value' => $num)), 'type' => 'page', - 'language' => LANGUAGE_NOT_SPECIFIED, + 'language' => Language::LANGCODE_NOT_SPECIFIED, 'title' => $doc . ' number', ); $this->nodes[$doc] = $this->drupalCreateNode($info); diff --git a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php index b029032..76f3901 100644 --- a/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php +++ b/core/modules/search/lib/Drupal/search/Tests/SearchRankingTest.php @@ -7,6 +7,8 @@ namespace Drupal\search\Tests; +use Drupal\Core\Language\Language; + class SearchRankingTest extends SearchTestBase { /** @@ -70,7 +72,7 @@ function testRankings() { // Add a comment to one of the nodes. $edit = array(); $edit['subject'] = 'my comment title'; - $edit['comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]'] = 'some random comment'; + $edit['comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]'] = 'some random comment'; $this->drupalGet('comment/reply/' . $nodes['comments'][1]->nid); $this->drupalPost(NULL, $edit, t('Preview')); $this->drupalPost(NULL, $edit, t('Save')); diff --git a/core/modules/search/search.pages.inc b/core/modules/search/search.pages.inc index eaae71a..aed41f6 100644 --- a/core/modules/search/search.pages.inc +++ b/core/modules/search/search.pages.inc @@ -5,6 +5,8 @@ * User page callbacks for the Search module. */ +use Drupal\Core\Language\Language; + /** * Page callback: Presents the search form and/or search results. * @@ -122,12 +124,12 @@ function template_preprocess_search_results(&$variables) { * - content_attributes: HTML attributes for the content. */ function template_preprocess_search_result(&$variables) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $result = $variables['result']; $variables['url'] = check_url($result['link']); $variables['title'] = check_plain($result['title']); - if (isset($result['language']) && $result['language'] != $language_interface->langcode && $result['language'] != LANGUAGE_NOT_SPECIFIED) { + if (isset($result['language']) && $result['language'] != $language_interface->langcode && $result['language'] != Language::LANGCODE_NOT_SPECIFIED) { $variables['title_attributes']['lang'] = $result['language']; $variables['content_attributes']['lang'] = $result['language']; } diff --git a/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php index fb7019e..2967762 100644 --- a/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php +++ b/core/modules/serialization/lib/Drupal/serialization/Tests/EntitySerializationTest.php @@ -7,6 +7,7 @@ namespace Drupal\serialization\Tests; +use Drupal\Core\Language\Language; use Drupal\serialization\Encoder\JsonEncoder; use Drupal\serialization\Normalizer\ComplexDataNormalizer; use Drupal\serialization\Normalizer\TypedDataNormalizer; @@ -109,7 +110,7 @@ public function testNormalize() { array('value' => $this->entity->uuid()), ), 'langcode' => array( - array('value' => LANGUAGE_NOT_SPECIFIED), + array('value' => Language::LANGCODE_NOT_SPECIFIED), ), 'default_langcode' => array( array('value' => NULL), @@ -162,7 +163,7 @@ public function testSerialize() { 'id' => '' . $this->entity->id() . '', 'revision_id' => '' . $this->entity->getRevisionId() . '', 'uuid' => '' . $this->entity->uuid() . '', - 'langcode' => '' . LANGUAGE_NOT_SPECIFIED . '', + 'langcode' => '' . Language::LANGCODE_NOT_SPECIFIED . '', 'default_langcode' => '', 'name' => '' . $this->values['name'] . '', 'user_id' => '' . $this->values['user_id'] . '', diff --git a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php index 35af531..94f3d79 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/TestBase.php @@ -12,6 +12,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\Database\ConnectionNotDefinedException; use Drupal\Core\DrupalKernel; +use Drupal\Core\Language\Language; use ReflectionMethod; use ReflectionObject; use Exception; @@ -838,7 +839,7 @@ protected function changeDatabasePrefix() { */ protected function prepareEnvironment() { global $user, $conf; - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // When running the test runner within a test, back up the original database // prefix and re-set the new/nested prefix in drupal_valid_test_ua(). diff --git a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php index 4e7b6b1..221ceb9 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php @@ -11,6 +11,7 @@ use Drupal\Core\DrupalKernel; use Drupal\Core\Database\Database; use Drupal\Core\Database\ConnectionNotDefinedException; +use Drupal\Core\Language\Language; use PDO; use stdClass; use DOMDocument; @@ -214,7 +215,7 @@ function drupalGetNodeByTitle($title, $reset = FALSE) { * - status: NODE_PUBLISHED. * - sticky: NODE_NOT_STICKY. * - type: 'page'. - * - langcode: LANGUAGE_NOT_SPECIFIED. + * - langcode: Language::LANGCODE_NOT_SPECIFIED. * - uid: The currently logged in user, or the user running test. * - revision: 1. (Backwards-compatible binary flag indicating whether a * new revision should be created; use 1 to specify a new revision.) @@ -234,7 +235,7 @@ protected function drupalCreateNode(array $settings = array()) { 'status' => NODE_PUBLISHED, 'sticky' => NODE_NOT_STICKY, 'type' => 'page', - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, ); // Add in comment settings for nodes. diff --git a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php index 0b5909d..3ce84fb 100644 --- a/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php +++ b/core/modules/statistics/lib/Drupal/statistics/Tests/StatisticsTokenReplaceTest.php @@ -7,6 +7,8 @@ namespace Drupal\statistics\Tests; +use Drupal\Core\Language\Language; + /** * Tests statistics token replacement in strings. */ @@ -23,7 +25,7 @@ public static function getInfo() { * Creates a node, then tests the statistics tokens generated from it. */ function testStatisticsTokenReplacement() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Create user and node. $user = $this->drupalCreateUser(array('create page content')); diff --git a/core/modules/system/language.api.php b/core/modules/system/language.api.php index 7c7375f..fb165a4 100644 --- a/core/modules/system/language.api.php +++ b/core/modules/system/language.api.php @@ -25,9 +25,9 @@ * The current path. */ function hook_language_switch_links_alter(array &$links, $type, $path) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(\Drupal\Core\Language\Language::TYPE_INTERFACE); - if ($type == LANGUAGE_TYPE_CONTENT && isset($links[$language_interface->langcode])) { + if ($type == \Drupal\Core\Language\Language::TYPE_CONTENT && isset($links[$language_interface->langcode])) { foreach ($links[$language_interface->langcode] as $link) { $link['attributes']['class'][] = 'active-language'; } @@ -189,7 +189,7 @@ function hook_language_fallback_candidates_alter(array &$fallback_candidates) { * Here is a code snippet to transliterate some text: * @code * // Use the current default interface language. - * $langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; + * $langcode = language(\Drupal\Core\Language\Language::TYPE_INTERFACE)->langcode; * // Instantiate the transliteration class. * $trans = drupal_container()->get('transliteration'); * // Use this to transliterate some text. diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php index 746ab99..bb97d52 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/CascadingStylesheetsTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Common; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -207,8 +208,8 @@ function testRenderOverride() { */ function testAlter() { // Switch the language to a right to left language and add system.base.css. - $language_interface = language(LANGUAGE_TYPE_INTERFACE); - $language_interface->direction = LANGUAGE_RTL; + $language_interface = language(Language::TYPE_INTERFACE); + $language_interface->direction = Language::DIRECTION_RTL; $path = drupal_get_path('module', 'system'); drupal_add_css($path . '/system.base.css'); @@ -217,7 +218,7 @@ function testAlter() { $this->assert(strpos($styles, $path . '/system.base-rtl.css') !== FALSE, 'CSS is alterable as right to left overrides are added.'); // Change the language back to left to right. - $language_interface->direction = LANGUAGE_LTR; + $language_interface->direction = Language::DIRECTION_LTR; } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php index 1f2575c..118a059 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Common/FormatDateTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Common; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -90,7 +91,7 @@ function testAdminDefinedFormatDate() { function testFormatDate() { global $user; - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $timestamp = strtotime('2007-03-26T00:00:00+00:00'); $this->assertIdentical(format_date($timestamp, 'custom', 'l, d-M-y H:i:s T', 'America/Los_Angeles', 'en'), 'Sunday, 25-Mar-07 17:00:00 PDT', 'Test all parameters.'); @@ -107,7 +108,7 @@ function testFormatDate() { 'predefined_langcode' => 'custom', 'langcode' => self::LANGCODE, 'name' => self::LANGCODE, - 'direction' => LANGUAGE_LTR, + 'direction' => Language::DIRECTION_LTR, ); $this->drupalPost('admin/config/regional/language/add', $edit, t('Add custom language')); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php index 67f190e..5f22971 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityCrudHookTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Entity; +use Drupal\Core\Language\Language; use Drupal\Core\Database\Database; /** @@ -140,7 +141,7 @@ public function testCommentHooks() { 'comment' => 2, 'promote' => 0, 'sticky' => 0, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'created' => REQUEST_TIME, 'changed' => REQUEST_TIME, )); @@ -158,7 +159,7 @@ public function testCommentHooks() { 'created' => REQUEST_TIME, 'changed' => REQUEST_TIME, 'status' => 1, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $this->assertHookMessageOrder(array( @@ -283,7 +284,7 @@ public function testNodeHooks() { 'comment' => 2, 'promote' => 0, 'sticky' => 0, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'created' => REQUEST_TIME, 'changed' => REQUEST_TIME, )); @@ -342,7 +343,7 @@ public function testTaxonomyTermHooks() { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Test vocabulary', 'vid' => 'test', - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'description' => NULL, 'module' => 'entity_crud_hook_test', )); @@ -352,7 +353,7 @@ public function testTaxonomyTermHooks() { $term = entity_create('taxonomy_term', array( 'vid' => $vocabulary->id(), 'name' => 'Test term', - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'description' => NULL, 'format' => 1, )); @@ -411,7 +412,7 @@ public function testTaxonomyVocabularyHooks() { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => 'Test vocabulary', 'vid' => 'test', - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'description' => NULL, 'module' => 'entity_crud_hook_test', )); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php index 3c5679b..cd51bfb 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFieldTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\Field\FieldInterface; use Drupal\Core\Entity\Field\FieldItemInterface; +use Drupal\Core\Language\Language; use Drupal\Core\TypedData\TypedDataInterface; /** @@ -182,8 +183,8 @@ protected function assertReadWrite($entity_type) { $this->assertFalse(isset($entity->name->value), format_string('%entity_type: Name is not set.', array('%entity_type' => $entity_type))); // Access the language field. - $this->assertEqual(LANGUAGE_NOT_SPECIFIED, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); - $this->assertEqual(language_load(LANGUAGE_NOT_SPECIFIED), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type))); + $this->assertEqual(Language::LANGCODE_NOT_SPECIFIED, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); + $this->assertEqual(language_load(Language::LANGCODE_NOT_SPECIFIED), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type))); // Change the language by code. $entity->langcode->value = language_default()->langcode; @@ -191,7 +192,7 @@ protected function assertReadWrite($entity_type) { $this->assertEqual(language_default(), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type))); // Revert language by code then try setting it by language object. - $entity->langcode->value = LANGUAGE_NOT_SPECIFIED; + $entity->langcode->value = Language::LANGCODE_NOT_SPECIFIED; $entity->langcode->language = language_default(); $this->assertEqual(language_default()->langcode, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); $this->assertEqual(language_default(), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type))); @@ -325,8 +326,8 @@ protected function assertSave($entity_type) { // Access the name field. $this->assertEqual(1, $entity->id->value, format_string('%entity_type: ID value can be read.', array('%entity_type' => $entity_type))); $this->assertTrue(is_string($entity->uuid->value), format_string('%entity_type: UUID value can be read.', array('%entity_type' => $entity_type))); - $this->assertEqual(LANGUAGE_NOT_SPECIFIED, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); - $this->assertEqual(language_load(LANGUAGE_NOT_SPECIFIED), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type))); + $this->assertEqual(Language::LANGCODE_NOT_SPECIFIED, $entity->langcode->value, format_string('%entity_type: Language code can be read.', array('%entity_type' => $entity_type))); + $this->assertEqual(language_load(Language::LANGCODE_NOT_SPECIFIED), $entity->langcode->language, format_string('%entity_type: Language object can be read.', array('%entity_type' => $entity_type))); $this->assertEqual($this->entity_user->uid, $entity->user_id->target_id, format_string('%entity_type: User id can be read.', array('%entity_type' => $entity_type))); $this->assertEqual($this->entity_user->name, $entity->user_id->entity->name, format_string('%entity_type: User name can be read.', array('%entity_type' => $entity_type))); $this->assertEqual($this->entity_field_text, $entity->field_test_text->value, format_string('%entity_type: Text field can be read.', array('%entity_type' => $entity_type))); @@ -489,7 +490,7 @@ protected function assertDataStructureInterfaces($entity_type) { // the user name and other user entity strings as well. $target_strings = array( $entity->uuid->value, - LANGUAGE_NOT_SPECIFIED, + Language::LANGCODE_NOT_SPECIFIED, $this->entity_name, $this->entity_field_text, // Field format. diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php index fbbd131..67c9654 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityFormTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Entity; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -52,7 +53,7 @@ function testFormCRUD() { * The entity type to run the tests with. */ protected function assertFormCRUD($entity_type) { - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $name1 = $this->randomName(8); $name2 = $this->randomName(10); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php index ae51625..b1909c2 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityQueryTest.php @@ -7,6 +7,8 @@ namespace Drupal\system\Tests\Entity; +use Drupal\Core\Language\Language; + /** * Tests the basic Entity API. */ @@ -83,11 +85,11 @@ function setUp() { $bundles[] = $bundle; } // Each unit is a list of field name, langcode and a column-value array. - $units[] = array($figures, LANGUAGE_NOT_SPECIFIED, array( + $units[] = array($figures, Language::LANGCODE_NOT_SPECIFIED, array( 'color' => 'red', 'shape' => 'triangle', )); - $units[] = array($figures, LANGUAGE_NOT_SPECIFIED, array( + $units[] = array($figures, Language::LANGCODE_NOT_SPECIFIED, array( 'color' => 'blue', 'shape' => 'circle', )); diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php index 7672fbe..43a9ac7 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationFormTest.php @@ -60,9 +60,9 @@ function testEntityFormLanguage() { $web_user = $this->drupalCreateUser(array('create page content', 'edit own page content', 'administer content types')); $this->drupalLogin($web_user); - // Create a node with language LANGUAGE_NOT_SPECIFIED. + // Create a node with language Language::LANGCODE_NOT_SPECIFIED. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(8); $edit["body[$langcode][0][value]"] = $this->randomName(16); @@ -87,14 +87,14 @@ function testEntityFormLanguage() { // Enable language selector. $this->drupalGet('admin/structure/types/manage/page'); - $edit = array('language_configuration[language_show]' => TRUE, 'language_configuration[langcode]' => LANGUAGE_NOT_SPECIFIED); + $edit = array('language_configuration[language_show]' => TRUE, 'language_configuration[langcode]' => Language::LANGCODE_NOT_SPECIFIED); $this->drupalPost('admin/structure/types/manage/page', $edit, t('Save content type')); $this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Basic page')), 'Basic page content type has been updated.'); // Create a node with language. $edit = array(); $langcode = $this->langcodes[0]; - $field_langcode = LANGUAGE_NOT_SPECIFIED; + $field_langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(8); $edit["body[$field_langcode][0][value]"] = $this->randomName(16); $edit['langcode'] = $langcode; diff --git a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php index cccdc5f..fdb2110 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Entity/EntityTranslationTest.php @@ -110,13 +110,13 @@ protected function assertEntityLanguageMethods($entity_type) { 'name' => 'test', 'user_id' => $GLOBALS['user']->uid, )); - $this->assertEqual($entity->language()->langcode, LANGUAGE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', array('%entity_type' => $entity_type))); + $this->assertEqual($entity->language()->langcode, Language::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity language not specified.', array('%entity_type' => $entity_type))); $this->assertFalse($entity->getTranslationLanguages(FALSE), format_string('%entity_type: No translations are available', array('%entity_type' => $entity_type))); // Set the value in default language. $entity->set($this->field_name, array(0 => array('value' => 'default value'))); // Get the value. - $this->assertEqual($entity->getTranslation(LANGUAGE_DEFAULT)->get($this->field_name)->value, 'default value', format_string('%entity_type: Untranslated value retrieved.', array('%entity_type' => $entity_type))); + $this->assertEqual($entity->getTranslation(Language::LANGCODE_DEFAULT)->get($this->field_name)->value, 'default value', format_string('%entity_type: Untranslated value retrieved.', array('%entity_type' => $entity_type))); // Set the value in a certain language. As the entity is not // language-specific it should use the default language and so ignore the @@ -229,9 +229,9 @@ protected function assertMultilingualProperties($entity_type) { $entity = entity_create($entity_type, array('name' => $name, 'user_id' => $uid)); $entity->save(); $entity = entity_load($entity_type, $entity->id()); - $this->assertEqual($entity->language()->langcode, LANGUAGE_NOT_SPECIFIED, format_string('%entity_type: Entity created as language neutral.', array('%entity_type' => $entity_type))); - $this->assertEqual($name, $entity->getTranslation(LANGUAGE_DEFAULT)->get('name')->value, format_string('%entity_type: The entity name has been correctly stored as language neutral.', array('%entity_type' => $entity_type))); - $this->assertEqual($uid, $entity->getTranslation(LANGUAGE_DEFAULT)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored as language neutral.', array('%entity_type' => $entity_type))); + $this->assertEqual($entity->language()->langcode, Language::LANGCODE_NOT_SPECIFIED, format_string('%entity_type: Entity created as language neutral.', array('%entity_type' => $entity_type))); + $this->assertEqual($name, $entity->getTranslation(Language::LANGCODE_DEFAULT)->get('name')->value, format_string('%entity_type: The entity name has been correctly stored as language neutral.', array('%entity_type' => $entity_type))); + $this->assertEqual($uid, $entity->getTranslation(Language::LANGCODE_DEFAULT)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored as language neutral.', array('%entity_type' => $entity_type))); // As fields, translatable properties should ignore the given langcode and // use neutral language if the entity is not translatable. $this->assertEqual($name, $entity->getTranslation($langcode)->get('name')->value, format_string('%entity_type: The entity name defaults to neutral language.', array('%entity_type' => $entity_type))); @@ -248,9 +248,9 @@ protected function assertMultilingualProperties($entity_type) { $this->assertEqual($name, $entity->getTranslation($langcode)->get('name')->value, format_string('%entity_type: The entity name has been correctly stored as a language-aware property.', array('%entity_type' => $entity_type))); $this->assertEqual($uid, $entity->getTranslation($langcode)->get('user_id')->target_id, format_string('%entity_type: The entity author has been correctly stored as a language-aware property.', array('%entity_type' => $entity_type))); // Translatable properties on a translatable entity should use default - // language if LANGUAGE_NOT_SPECIFIED is passed. - $this->assertEqual($name, $entity->getTranslation(LANGUAGE_NOT_SPECIFIED)->get('name')->value, format_string('%entity_type: The entity name defaults to the default language.', array('%entity_type' => $entity_type))); - $this->assertEqual($uid, $entity->getTranslation(LANGUAGE_NOT_SPECIFIED)->get('user_id')->target_id, format_string('%entity_type: The entity author defaults to the default language.', array('%entity_type' => $entity_type))); + // language if Language::LANGCODE_NOT_SPECIFIED is passed. + $this->assertEqual($name, $entity->getTranslation(Language::LANGCODE_NOT_SPECIFIED)->get('name')->value, format_string('%entity_type: The entity name defaults to the default language.', array('%entity_type' => $entity_type))); + $this->assertEqual($uid, $entity->getTranslation(Language::LANGCODE_NOT_SPECIFIED)->get('user_id')->target_id, format_string('%entity_type: The entity author defaults to the default language.', array('%entity_type' => $entity_type))); $this->assertEqual($name, $entity->get('name')->value, format_string('%entity_type: The entity name can be retrieved without specifying a language.', array('%entity_type' => $entity_type))); $this->assertEqual($uid, $entity->get('user_id')->target_id, format_string('%entity_type: The entity author can be retrieved without specifying a language.', array('%entity_type' => $entity_type))); diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/LanguageSelectElementTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/LanguageSelectElementTest.php index f5c589b..09044e6 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/LanguageSelectElementTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/LanguageSelectElementTest.php @@ -49,10 +49,10 @@ function testLanguageSelectElementOptions() { $this->drupalGet('form-test/language_select'); // Check that the language fields were rendered on the page. - $ids = array('edit-languages-all' => LANGUAGE_ALL, - 'edit-languages-configurable' => LANGUAGE_CONFIGURABLE, - 'edit-languages-locked' => LANGUAGE_LOCKED, - 'edit-languages-config-and-locked' => LANGUAGE_CONFIGURABLE | LANGUAGE_LOCKED); + $ids = array('edit-languages-all' => Language::STATE_ALL, + 'edit-languages-configurable' => Language::STATE_CONFIGURABLE, + 'edit-languages-locked' => Language::STATE_LOCKED, + 'edit-languages-config-and-locked' => Language::STATE_CONFIGURABLE | Language::STATE_LOCKED); foreach ($ids as $id => $flags) { $this->assertField($id, format_string('The @id field was found on the page.', array('@id' => $id))); $options = array(); @@ -90,7 +90,7 @@ function testHiddenLanguageSelectElement() { $values = drupal_json_decode($this->drupalGetContent()); $this->assertEqual($values['languages_all'], 'xx'); $this->assertEqual($values['languages_configurable'], 'en'); - $this->assertEqual($values['languages_locked'], LANGUAGE_NOT_SPECIFIED); + $this->assertEqual($values['languages_locked'], Language::LANGCODE_NOT_SPECIFIED); $this->assertEqual($values['languages_config_and_locked'], 'dummy_value'); $this->assertEqual($values['language_custom_options'], 'opt2'); } diff --git a/core/modules/system/lib/Drupal/system/Tests/Mail/MailTest.php b/core/modules/system/lib/Drupal/system/Tests/Mail/MailTest.php index 155fdb8..3dad764 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Mail/MailTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Mail/MailTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\Mail; +use Drupal\Core\Language\Language; use Drupal\Core\Mail\MailInterface; use Drupal\simpletest\WebTestBase; @@ -49,7 +50,7 @@ function setUp() { * Assert that the pluggable mail system is functional. */ public function testPluggableFramework() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Use MailTestCase for sending a message. $message = drupal_mail('simpletest', 'mail_test', 'testing@example.com', $language_interface->langcode); @@ -64,7 +65,7 @@ public function testPluggableFramework() { * @see simpletest_mail_alter() */ public function testCancelMessage() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Reset the class variable holding a copy of the last sent message. self::$sent_message = NULL; diff --git a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php index c5bfd17..47c0d31 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Menu/BreadcrumbTest.php @@ -7,6 +7,8 @@ namespace Drupal\system\Tests\Menu; +use Drupal\Core\Language\Language; + /** * Menu breadcrumbs related tests. */ @@ -60,7 +62,7 @@ function testBreadCrumbs() { $admin = $home + array('admin' => t('Administration')); $config = $admin + array('admin/config' => t('Configuration')); $type = 'article'; - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Verify breadcrumbs for default local tasks. $expected = array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php b/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php index cd432a7..8936815 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Path/AliasTest.php @@ -148,7 +148,7 @@ function testLookupPath() { // Test the situation where the alias and language are the same, but // the source differs. The newer alias record should be returned. $pathObject->save('user/2', 'bar'); - $this->assertEqual($aliasManager->getSystemPath('bar'), 'user/2', 'Newer alias record is returned when comparing two LANGUAGE_NOT_SPECIFIED paths with the same alias.'); + $this->assertEqual($aliasManager->getSystemPath('bar'), 'user/2', 'Newer alias record is returned when comparing two Language::LANGCODE_NOT_SPECIFIED paths with the same alias.'); } /** diff --git a/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php b/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php index ff16e61..4d98340 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/DateFormatsLanguageTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\System; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -51,7 +52,7 @@ function testLocalizeDateFormats() { $this->drupalPost('admin/config/regional/language/add', $edit, t('Add language')); // Set language negotiation. - $language_type = LANGUAGE_TYPE_INTERFACE; + $language_type = Language::TYPE_INTERFACE; $edit = array( "{$language_type}[enabled][language-url]" => TRUE, ); diff --git a/core/modules/system/lib/Drupal/system/Tests/System/PageTitleFilteringTest.php b/core/modules/system/lib/Drupal/system/Tests/System/PageTitleFilteringTest.php index 7e89cf7..9d96be8 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/PageTitleFilteringTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/PageTitleFilteringTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\System; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; class PageTitleFilteringTest extends WebTestBase { @@ -69,7 +70,7 @@ function testTitleTags() { drupal_set_title($title, PASS_THROUGH); $this->assertTrue(strpos(drupal_get_title(), '') !== FALSE, 'Tags in title are not converted to entities when $output is PASS_THROUGH.'); // Generate node content. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array( "title" => '!SimpleTest! ' . $title . $this->randomName(20), "body[$langcode][0][value]" => '!SimpleTest! test body' . $this->randomName(200), diff --git a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php index 3859041..e45b48a 100644 --- a/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/System/TokenReplaceTest.php @@ -7,6 +7,7 @@ namespace Drupal\system\Tests\System; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -30,7 +31,7 @@ function testTokenReplacement() { $node = $this->drupalCreateNode(array('uid' => $account->uid)); $node->title = 'Blinking Text'; global $user; - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $source = '[node:title]'; // Title of the node we passed in $source .= '[node:author:name]'; // Node author's name @@ -75,7 +76,7 @@ function testTokenReplacement() { * Test whether token-replacement works in various contexts. */ function testSystemTokenRecognition() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Generate prefixes and suffixes for the token context. $tests = array( @@ -104,7 +105,7 @@ function testSystemTokenRecognition() { * Tests the generation of all system site information tokens. */ function testSystemSiteTokenReplacement() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $url_options = array( 'absolute' => TRUE, 'language' => $language_interface, @@ -147,7 +148,7 @@ function testSystemSiteTokenReplacement() { * Tests the generation of all system date tokens. */ function testSystemDateTokenReplacement() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Set time to one hour before request. $date = REQUEST_TIME - 3600; diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php index 6b669a5..4771869 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/LanguageUpgradePathTest.php @@ -9,6 +9,8 @@ use Drupal\Core\Database\DatabaseException; +use Drupal\Core\Language\Language; + /** * Tests upgrading a filled database with language data. * @@ -42,7 +44,7 @@ public function testLanguageUpgrade() { // Ensure Catalan was properly upgraded to be the new default language. $this->assertTrue(language_default()->langcode == 'ca', 'Catalan is the default language'); - $languages = language_list(LANGUAGE_ALL); + $languages = language_list(Language::STATE_ALL); foreach ($languages as $language) { $this->assertTrue($language->default == ($language->langcode == 'ca'), format_string('@language default property properly set', array('@language' => $language->name))); } @@ -69,7 +71,7 @@ public function testLanguageUpgrade() { $translation_source_nid = 52; $translation_nid = 53; // Check directly for the $node->langcode property. - $this->assertEqual(node_load($language_none_nid)->langcode, LANGUAGE_NOT_SPECIFIED, "'language' property was renamed to 'langcode' for LANGUAGE_NOT_SPECIFIED node."); + $this->assertEqual(node_load($language_none_nid)->langcode, Language::LANGCODE_NOT_SPECIFIED, "'language' property was renamed to 'langcode' for Language::LANGCODE_NOT_SPECIFIED node."); $this->assertEqual(node_load($spanish_nid)->langcode, 'ca', "'language' property was renamed to 'langcode' for Catalan node."); // Check that the translation table works correctly. $this->drupalGet("node/$translation_source_nid/translate"); @@ -98,9 +100,9 @@ public function testLanguageUpgrade() { $this->assertEqual($term->langcode, 'ca'); // A langcode property was added to files. Check that existing files got - // assigned LANGUAGE_NOT_SPECIFIED. + // assigned Language::LANGCODE_NOT_SPECIFIED. $file = db_query('SELECT * FROM {file_managed} WHERE fid = :fid', array(':fid' => 1))->fetchObject(); - $this->assertEqual($file->langcode, LANGUAGE_NOT_SPECIFIED); + $this->assertEqual($file->langcode, Language::LANGCODE_NOT_SPECIFIED); // Check if language negotiation weights were renamed properly. This is a // reproduction of the previous weights from the dump. diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php index 04070c9..f15780f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/UserPictureUpgradePathTest.php @@ -7,6 +7,8 @@ namespace Drupal\system\Tests\Upgrade; +use Drupal\Core\Language\Language; + /** * Tests upgrading a filled database with user picture data. * @@ -44,7 +46,7 @@ public function testUserPictureUpgrade() { $this->assertIdentical($instance['settings']['default_image'], $file->id(), 'Default user picture has been migrated.'); $this->assertEqual($file->uri, 'public://user_pictures_dir/druplicon.png', 'File id matches the uri expected.'); $this->assertEqual($file->filename, 'druplicon.png'); - $this->assertEqual($file->langcode, LANGUAGE_NOT_SPECIFIED); + $this->assertEqual($file->langcode, Language::LANGCODE_NOT_SPECIFIED); $this->assertEqual($file->filemime, 'image/png'); $this->assertFalse(empty($file->uuid)); @@ -67,7 +69,7 @@ public function testUserPictureUpgrade() { // Check the user picture and file usage record. $user = user_load(1); - $file = file_load($user->user_picture[LANGUAGE_NOT_SPECIFIED][0]['fid']); + $file = file_load($user->user_picture[Language::LANGCODE_NOT_SPECIFIED][0]['fid']); $this->assertEqual('public://user_pictures_dir/faked_image.png', $file->uri); $usage = file_usage()->listUsage($file); $this->assertEqual(1, $usage['file']['user'][1]); diff --git a/core/modules/system/system.api.php b/core/modules/system/system.api.php index 68127e2..269e5a0 100644 --- a/core/modules/system/system.api.php +++ b/core/modules/system/system.api.php @@ -1815,7 +1815,7 @@ function hook_custom_theme() { */ function hook_watchdog(array $log_entry) { global $base_url; - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(\Drupal\Core\Language\Language::TYPE_INTERFACE); $severity_list = array( WATCHDOG_EMERGENCY => t('Emergency'), diff --git a/core/modules/system/system.install b/core/modules/system/system.install index a93a124..cea8ee1 100644 --- a/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1,6 +1,7 @@ TRUE, - '#default_value' => LANGUAGE_NOT_SPECIFIED, + '#default_value' => Language::LANGCODE_NOT_SPECIFIED, ); $types['weight'] = array( '#input' => TRUE, diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php index b9e9361..04639c5 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestAccessController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityAccessController; +use Drupal\Core\Language\Language; use Drupal\user\Plugin\Core\Entity\User; /** @@ -19,8 +20,8 @@ class EntityTestAccessController extends EntityAccessController { /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::viewAccess(). */ - public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { - if ($langcode != LANGUAGE_DEFAULT) { + public function viewAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { + if ($langcode != Language::LANGCODE_DEFAULT) { return user_access('view test entity translations', $account); } return user_access('view test entity', $account); @@ -29,21 +30,21 @@ public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::createAccess(). */ - public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function createAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer entity_test content', $account); } /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::updateAccess(). */ - public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function updateAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer entity_test content', $account); } /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::deleteAccess(). */ - public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function deleteAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer entity_test content', $account); } diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php index c08e3b3..ede167c 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/EntityTestFormController.php @@ -8,6 +8,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormControllerNG; +use Drupal\Core\Language\Language; /** * Form controller for the test entity edit forms. @@ -47,7 +48,7 @@ public function form(array $form, array &$form_state, EntityInterface $entity) { '#title' => t('Language'), '#type' => 'language_select', '#default_value' => $entity->language()->langcode, - '#languages' => LANGUAGE_ALL, + '#languages' => Language::STATE_ALL, ); return $form; diff --git a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTest.php b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTest.php index 0bfb73e..2b715db 100644 --- a/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTest.php +++ b/core/modules/system/tests/modules/entity_test/lib/Drupal/entity_test/Plugin/Core/Entity/EntityTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\EntityNG; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Language\Language; /** * Defines the test entity class. @@ -78,7 +79,7 @@ protected function init() { /** * Overrides Drupal\entity\Entity::label(). */ - public function label($langcode = LANGUAGE_DEFAULT) { + public function label($langcode = Language::LANGCODE_DEFAULT) { $info = $this->entityInfo(); if (isset($info['entity_keys']['label']) && $info['entity_keys']['label'] == 'name') { return $this->getTranslation($langcode)->name->value; diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index c7a85a3..588b6dc 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -5,6 +5,7 @@ * Helper module for the form API tests. */ +use Drupal\Core\Language\Language; use Drupal\form_test\Callbacks; use Drupal\form_test\FormTestObject; use Drupal\form_test\SystemConfigFormTestForm; @@ -1325,26 +1326,26 @@ function form_test_language_select() { $form['languages_all'] = array( '#type' => 'language_select', - '#languages' => LANGUAGE_ALL, + '#languages' => Language::STATE_ALL, '#default_value' => 'xx', ); $form['languages_configurable'] = array( '#type' => 'language_select', - '#languages' => LANGUAGE_CONFIGURABLE, + '#languages' => Language::STATE_CONFIGURABLE, '#default_value' => 'en', ); $form['languages_locked'] = array( '#type' => 'language_select', - '#languages' => LANGUAGE_LOCKED, + '#languages' => Language::STATE_LOCKED, ); $form['languages_config_and_locked'] = array( '#type' => 'language_select', - '#languages' => LANGUAGE_CONFIGURABLE | LANGUAGE_LOCKED, + '#languages' => Language::STATE_CONFIGURABLE | Language::STATE_LOCKED, '#default_value' => 'dummy_value', ); $form['language_custom_options'] = array( '#type' => 'language_select', - '#languages' => LANGUAGE_CONFIGURABLE | LANGUAGE_LOCKED, + '#languages' => Language::STATE_CONFIGURABLE | Language::STATE_LOCKED, '#options' => array('opt1' => 'First option', 'opt2' => 'Second option', 'opt3' => 'Third option'), '#default_value' => 'opt2', ); @@ -2255,7 +2256,7 @@ function form_test_two_instances() { 'uid' => $user->uid, 'name' => (isset($user->name) ? $user->name : ''), 'type' => 'page', - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $node2 = clone($node1); $return['node_form_1'] = entity_get_form($node1); diff --git a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/CachedMockBlockManager.php b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/CachedMockBlockManager.php index 07ba59e..139a01f 100644 --- a/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/CachedMockBlockManager.php +++ b/core/modules/system/tests/modules/plugin_test/lib/Drupal/plugin_test/Plugin/CachedMockBlockManager.php @@ -7,6 +7,7 @@ namespace Drupal\plugin_test\Plugin; +use Drupal\Core\Language\Language; use Drupal\Core\Plugin\Discovery\CacheDecorator; /** @@ -24,6 +25,6 @@ public function __construct() { // The CacheDecorator allows us to cache these plugin definitions for // quicker retrieval. In this case we are generating a cache key by // language. - $this->discovery = new CacheDecorator($this->discovery, 'mock_block:' . language(LANGUAGE_TYPE_INTERFACE)->langcode, 'cache', 1542646800, array('plugin_test')); + $this->discovery = new CacheDecorator($this->discovery, 'mock_block:' . language(Language::TYPE_INTERFACE)->langcode, 'cache', 1542646800, array('plugin_test')); } } diff --git a/core/modules/system/tests/upgrade/drupal-7.language.database.php b/core/modules/system/tests/upgrade/drupal-7.language.database.php index 5687361..5ecf769 100644 --- a/core/modules/system/tests/upgrade/drupal-7.language.database.php +++ b/core/modules/system/tests/upgrade/drupal-7.language.database.php @@ -422,7 +422,7 @@ // Add sample nodes to test language assignment and translation functionality. // The first node is also used for testing comment language functionality. This -// is a simple node with LANGUAGE_NOT_SPECIFIED as language code. The second +// is a simple node with Language::LANGCODE_NOT_SPECIFIED as language code. The second // node is a Catalan node (language code 'ca'). The third and fourth node are a // translation set with an English source translation (language code 'en') and // a Chuvash translation (language code 'cv'). @@ -545,7 +545,7 @@ 'vid' => '70', 'uid' => '6', 'title' => 'Node title 50', - 'log' => 'Added a LANGUAGE_NOT_SPECIFIED node to comment on.', + 'log' => 'Added a Language::LANGCODE_NOT_SPECIFIED node to comment on.', 'timestamp' => '1314997642', 'status' => '1', 'comment' => '2', diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php index c45aa02..4b96172 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermAccessController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityAccessController; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\user\Plugin\Core\Entity\User; /** @@ -21,28 +22,28 @@ class TermAccessController extends EntityAccessController { /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::viewAccess(). */ - public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function viewAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('access content', $account); } /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::createAccess(). */ - public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function createAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer taxonomy', $account); } /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::updateAccess(). */ - public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function updateAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access("update terms in {$entity->bundle()}", $account) || user_access('administer taxonomy', $account); } /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::deleteAccess(). */ - public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function deleteAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access("delete terms in {$entity->bundle()}", $account) || user_access('administer taxonomy', $account); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php index 3735ad6..8070697 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/TermFormController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Language\Language; /** * Base for controller for taxonomy term edit forms. @@ -45,7 +46,7 @@ public function form(array $form, array &$form_state, EntityInterface $term) { $form['langcode'] = array( '#type' => 'language_select', '#title' => t('Language'), - '#languages' => LANGUAGE_ALL, + '#languages' => Language::STATE_ALL, '#default_value' => $term->langcode, '#access' => !is_null($language_configuration['language_show']) && $language_configuration['language_show'], ); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php index 778b1a0..5a34e15 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/LegacyTest.php @@ -9,6 +9,8 @@ use Drupal\Core\Datetime\DrupalDateTime; +use Drupal\Core\Language\Language; + /** * Test for legacy node bug. */ @@ -35,7 +37,7 @@ function setUp() { */ function testTaxonomyLegacyNode() { // Posts an article with a taxonomy term and a date prior to 1970. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $date = new DrupalDateTime('1969-01-01 00:00:00'); $edit = array(); $edit['title'] = $this->randomName(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php index 4c3e3d3..d9629c9 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/RssTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Language\Language; + /** * Tests the rendering of term reference fields in RSS feeds. */ @@ -90,7 +92,7 @@ function testTaxonomyRss() { // Post an article. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(); $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->tid; $this->drupalPost('node/add/article', $edit, t('Save')); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php index ea9bc3e..eae0934 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTermReferenceItemTest.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Language\Language; use Drupal\Core\Entity\Field\FieldInterface; use Drupal\Core\Entity\Field\FieldItemInterface; use Drupal\field\Tests\FieldUnitTestBase; @@ -39,7 +40,7 @@ public function setUp() { $vocabulary = entity_create('taxonomy_vocabulary', array( 'name' => $this->randomName(), 'vid' => drupal_strtolower($this->randomName()), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $vocabulary->save(); $field = array( @@ -68,7 +69,7 @@ public function setUp() { $this->term = entity_create('taxonomy_term', array( 'name' => $this->randomName(), 'vid' => $vocabulary->id(), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $this->term->save(); } @@ -104,7 +105,7 @@ public function testTaxonomyTermReferenceItem() { $term2 = entity_create('taxonomy_term', array( 'name' => $this->randomName(), 'vid' => $this->term->vid, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $term2->save(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php index 815c34b..452da8f 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TaxonomyTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -39,7 +40,7 @@ function createVocabulary() { 'name' => $this->randomName(), 'description' => $this->randomName(), 'vid' => drupal_strtolower($this->randomName()), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'weight' => mt_rand(0, 10), )); $vocabulary->save(); @@ -58,7 +59,7 @@ function createTerm($vocabulary) { // Use the first available text format. 'format' => $format->format, 'vid' => $vocabulary->id(), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); taxonomy_term_save($term); return $term; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php index 8c5571c..ac03e74 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldMultipleVocabularyTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Language\Language; + /** * Tests a taxonomy term reference field that allows multiple vocabularies. */ @@ -84,7 +86,7 @@ function testTaxonomyTermFieldMultipleVocabularies() { $term2 = $this->createTerm($this->vocabulary2); // Submit an entity with both terms. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->drupalGet('test-entity/add/test_bundle'); $this->assertFieldByName("{$this->field_name}[$langcode][]", '', 'Widget is displayed'); $edit = array( diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php index d5de5fa..e3dca5b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermFieldTest.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Language\Language; use Drupal\field\FieldValidationException; /** @@ -75,7 +76,7 @@ function setUp() { */ function testTaxonomyTermFieldValidation() { // Test valid and invalid values with field_attach_validate(). - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $entity = field_test_create_entity(); $term = $this->createTerm($this->vocabulary); $entity->{$this->field_name}[$langcode][0]['tid'] = $term->tid; @@ -107,7 +108,7 @@ function testTaxonomyTermFieldWidgets() { $term = $this->createTerm($this->vocabulary); // Display creation form. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $this->drupalGet('test-entity/add/test_bundle'); $this->assertFieldByName("{$this->field_name}[$langcode]", '', 'Widget is displayed.'); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php index f9cba0d..985f97b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermIndexTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Language\Language; + /** * Tests the hook implementations that maintain the taxonomy index. */ @@ -101,7 +103,7 @@ function testTaxonomyIndex() { // Post an article. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(); $edit["body[$langcode][0][value]"] = $this->randomName(); $edit["{$this->field_name_1}[$langcode][]"] = $term_1->tid; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php index 93cc8d4..f510d45 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Language\Language; + /** * Tests for taxonomy term functions. */ @@ -106,7 +108,7 @@ function testTaxonomyNode() { // Post an article. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(); $edit["body[$langcode][0][value]"] = $this->randomName(); $edit[$this->instance['field_name'] . '[' . $langcode . '][]'] = $term1->tid; @@ -157,7 +159,7 @@ function testNodeTermCreationAndDeletion() { ); $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(); $edit["body[$langcode][0][value]"] = $this->randomName(); // Insert the terms in a comma separated list. Vocabulary 1 is a @@ -511,7 +513,7 @@ function testReSavingTags() { // Create a term and a node using it. $term = $this->createTerm($this->vocabulary); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array(); $edit["title"] = $this->randomName(8); $edit["body[$langcode][0][value]"] = $this->randomName(16); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php index cf3e000..bdfa72a 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TermTranslationUITest.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Language\Language; use Drupal\translation_entity\Tests\EntityTranslationUITest; /** @@ -59,7 +60,7 @@ protected function setupBundle() { 'name' => $this->bundle, 'description' => $this->randomName(), 'vid' => $this->bundle, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'weight' => mt_rand(0, 10), )); $this->vocabulary->save(); @@ -108,7 +109,7 @@ function testTranslateLinkVocabularyAdminPage() { 'name' => 'untranslatable_voc', 'description' => $this->randomName(), 'vid' => 'untranslatable_voc', - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'weight' => mt_rand(0, 10), )); $untranslatable_vocabulary->save(); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php index ea73152..05d46b9 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/TokenReplaceTest.php @@ -7,6 +7,8 @@ namespace Drupal\taxonomy\Tests; +use Drupal\Core\Language\Language; + /** * Test taxonomy token replacement in strings. */ @@ -25,7 +27,7 @@ function setUp() { $this->admin_user = $this->drupalCreateUser(array('administer taxonomy', 'bypass node access')); $this->drupalLogin($this->admin_user); $this->vocabulary = $this->createVocabulary(); - $this->langcode = LANGUAGE_NOT_SPECIFIED; + $this->langcode = Language::LANGCODE_NOT_SPECIFIED; $field = array( 'field_name' => 'taxonomy_' . $this->vocabulary->id(), @@ -62,7 +64,7 @@ function setUp() { * Creates some terms and a node, then tests the tokens generated from them. */ function testTaxonomyTokenReplacement() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); // Create two taxonomy terms. $term1 = $this->createTerm($this->vocabulary); diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php index 5f98990..f81d01b 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/Tests/Views/TaxonomyTestBase.php @@ -7,6 +7,7 @@ namespace Drupal\taxonomy\Tests\Views; +use Drupal\Core\Language\Language; use Drupal\views\Tests\ViewTestBase; use Drupal\views\Tests\ViewTestData; @@ -136,7 +137,7 @@ protected function createTerm() { // Use the first available text format. 'format' => $format->format, 'vid' => $this->vocabulary->id(), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); $term->save(); return $term; diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php index b1ec119..7e36ac2 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyAccessController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityAccessController; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\user\Plugin\Core\Entity\User; /** @@ -21,28 +22,28 @@ class VocabularyAccessController extends EntityAccessController { /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::viewAccess(). */ - public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function viewAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer taxonomy', $account); } /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::createAccess(). */ - public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function createAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer taxonomy', $account); } /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::updateAccess(). */ - public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function updateAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer taxonomy', $account); } /** * Implements \Drupal\Core\Entity\EntityAccessControllerInterface::deleteAccess(). */ - public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function deleteAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer taxonomy', $account); } diff --git a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php index 6785335..1a19271 100644 --- a/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php +++ b/core/modules/taxonomy/lib/Drupal/taxonomy/VocabularyFormController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Language\Language; /** * Base form controller for vocabulary edit forms. @@ -53,7 +54,7 @@ public function form(array $form, array &$form_state, EntityInterface $vocabular $form['langcode'] = array( '#type' => 'language_select', '#title' => t('Vocabulary language'), - '#languages' => LANGUAGE_ALL, + '#languages' => Language::STATE_ALL, '#default_value' => $vocabulary->langcode, ); if (module_exists('language')) { diff --git a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php index 716ead7..f924710 100644 --- a/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/Formatter/TextPlainUnitTest.php @@ -8,6 +8,7 @@ namespace Drupal\text\Tests\Formatter; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\entity\Plugin\Core\Entity\EntityDisplay; use Drupal\simpletest\DrupalUnitTestBase; @@ -96,7 +97,7 @@ function setUp() { )); $this->display->save(); - $this->langcode = LANGUAGE_NOT_SPECIFIED; + $this->langcode = Language::LANGCODE_NOT_SPECIFIED; } /** diff --git a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php index f8c585b..1f4c6e9 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextFieldTest.php @@ -7,6 +7,7 @@ namespace Drupal\text\Tests; +use Drupal\Core\Language\Language; use Drupal\field\FieldValidationException; use Drupal\simpletest\WebTestBase; @@ -73,7 +74,7 @@ function testTextFieldValidation() { // Test valid and invalid values with field_attach_validate(). $entity = field_test_create_entity(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; for ($i = 0; $i <= $max_length + 2; $i++) { $entity->{$this->field['field_name']}[$langcode][0]['value'] = str_repeat('x', $i); try { @@ -123,7 +124,7 @@ function _testTextfieldWidgets($field_type, $widget_type) { ->setComponent($this->field_name) ->save(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Display creation form. $this->drupalGet('test-entity/add/test_bundle'); @@ -183,7 +184,7 @@ function _testTextfieldWidgetsFormatted($field_type, $widget_type) { ->setComponent($this->field_name) ->save(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; // Disable all text formats besides the plain text fallback format. $this->drupalLogin($this->admin_user); diff --git a/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php b/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php index 9aff558..edbe390 100644 --- a/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php +++ b/core/modules/text/lib/Drupal/text/Tests/TextTranslationTest.php @@ -7,6 +7,7 @@ namespace Drupal\text\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -69,7 +70,7 @@ function testTextField() { $this->drupalLogin($this->translator); // Create content. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $body = $this->randomName(); $edit = array( 'title' => $this->randomName(), @@ -112,7 +113,7 @@ function testTextFieldFormatted() { // Populate the body field: the first item gets the "Full HTML" input // format, the second one "Basic HTML". $formats = array('full_html', 'basic_html'); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; foreach ($body as $delta => $value) { $edit = array( "body[$langcode][$delta][value]" => $value, diff --git a/core/modules/toolbar/toolbar.module b/core/modules/toolbar/toolbar.module index 2880a5d..2ed2293 100644 --- a/core/modules/toolbar/toolbar.module +++ b/core/modules/toolbar/toolbar.module @@ -5,6 +5,7 @@ * Administration toolbar for quick access to top level administration items. */ +use Drupal\Core\Language\Language; use Symfony\Component\HttpFoundation\JsonResponse; use Drupal\Core\Template\Attribute; @@ -660,7 +661,7 @@ function toolbar_library_info() { */ function _toolbar_get_subtree_hash() { global $user; - $cid = $user->uid . ':' . language(LANGUAGE_TYPE_INTERFACE)->langcode; + $cid = $user->uid . ':' . language(Language::TYPE_INTERFACE)->langcode; if ($cache = cache('toolbar')->get($cid)) { $hash = $cache->data; } diff --git a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php index 0e7c429..20883ad 100644 --- a/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php +++ b/core/modules/tracker/lib/Drupal/tracker/Tests/TrackerTest.php @@ -7,6 +7,7 @@ namespace Drupal\tracker\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -110,7 +111,7 @@ function testTrackerUser() { )); $comment = array( 'subject' => $this->randomName(), - 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this->randomName(20), + 'comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]' => $this->randomName(20), ); $this->drupalPost('comment/reply/' . $other_published_my_comment->nid, $comment, t('Save')); @@ -170,7 +171,7 @@ function testTrackerNewComments() { // Add a comment to the page. $comment = array( 'subject' => $this->randomName(), - 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this->randomName(20), + 'comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]' => $this->randomName(20), ); // The new comment is automatically viewed by the current user. $this->drupalPost('comment/reply/' . $node->nid, $comment, t('Save')); @@ -183,7 +184,7 @@ function testTrackerNewComments() { // Add another comment as other_user. $comment = array( 'subject' => $this->randomName(), - 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this->randomName(20), + 'comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]' => $this->randomName(20), ); // If the comment is posted in the same second as the last one then Drupal // can't tell the difference, so we wait one second here. @@ -216,7 +217,7 @@ function testTrackerCronIndexing() { $this->drupalLogin($this->other_user); $comment = array( 'subject' => $this->randomName(), - 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this->randomName(20), + 'comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]' => $this->randomName(20), ); $this->drupalPost('comment/reply/' . $nodes[3]->nid, $comment, t('Save')); diff --git a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php index df2c386..4fc436a 100644 --- a/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php +++ b/core/modules/translation/lib/Drupal/translation/Tests/TranslationTest.php @@ -8,6 +8,7 @@ namespace Drupal\translation\Tests; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -105,7 +106,7 @@ function testContentTranslation() { // Attempt a resubmission of the form - this emulates using the back button // to return to the page then resubmitting the form without a refresh. $edit = array(); - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $this->randomName(); $edit["body[$langcode][0][value]"] = $this->randomName(); $this->drupalPost('node/add/page', $edit, t('Save'), array('query' => array('translation' => $node->nid, 'language' => 'es'))); @@ -114,7 +115,7 @@ function testContentTranslation() { // Update original and mark translation as outdated. $node_body = $this->randomName(); - $node->body[LANGUAGE_NOT_SPECIFIED][0]['value'] = $node_body; + $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = $node_body; $edit = array(); $edit["body[$langcode][0][value]"] = $node_body; $edit['translation[retranslate]'] = TRUE; @@ -135,9 +136,9 @@ function testContentTranslation() { // Confirm that language neutral is an option for translators when there are // disabled languages. $this->drupalGet('node/add/page'); - $this->assertFieldByXPath('//select[@name="langcode"]//option', LANGUAGE_NOT_SPECIFIED, 'Language neutral is available in language selection with disabled languages.'); - $node2 = $this->createPage($this->randomName(), $this->randomName(), LANGUAGE_NOT_SPECIFIED); - $this->assertRaw($node2->body[LANGUAGE_NOT_SPECIFIED][0]['value'], 'Language neutral content created with disabled languages available.'); + $this->assertFieldByXPath('//select[@name="langcode"]//option', Language::LANGCODE_NOT_SPECIFIED, 'Language neutral is available in language selection with disabled languages.'); + $node2 = $this->createPage($this->randomName(), $this->randomName(), Language::LANGCODE_NOT_SPECIFIED); + $this->assertRaw($node2->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], 'Language neutral content created with disabled languages available.'); // Leave just one language installed and check that the translation overview // page is still accessible. @@ -215,7 +216,7 @@ function testLanguageSwitcherBlockIntegration() { // Create a language neutral node and check that the language switcher is // left untouched. - $node2 = $this->createPage($this->randomName(), $this->randomName(), LANGUAGE_NOT_SPECIFIED); + $node2 = $this->createPage($this->randomName(), $this->randomName(), Language::LANGCODE_NOT_SPECIFIED); $node2_en = (object) array('nid' => $node2->nid, 'langcode' => 'en'); $node2_es = (object) array('nid' => $node2->nid, 'langcode' => 'es'); $node2_it = (object) array('nid' => $node2->nid, 'langcode' => 'it'); @@ -324,7 +325,7 @@ function addLanguage($langcode) { } else { // It's installed. No need to do anything. - $this->assertTrue(true, 'Language [' . $langcode . '] already installed.'); + $this->assertTrue(TRUE, 'Language [' . $langcode . '] already installed.'); } } @@ -343,7 +344,7 @@ function addLanguage($langcode) { */ function createPage($title, $body, $langcode = NULL) { $edit = array(); - $field_langcode = LANGUAGE_NOT_SPECIFIED; + $field_langcode = Language::LANGCODE_NOT_SPECIFIED; $edit["title"] = $title; $edit["body[$field_langcode][0][value]"] = $body; if (!empty($langcode)) { @@ -377,10 +378,10 @@ function createPage($title, $body, $langcode = NULL) { function createTranslation(EntityInterface $node, $title, $body, $langcode) { $this->drupalGet('node/add/page', array('query' => array('translation' => $node->nid, 'target' => $langcode))); - $field_langcode = LANGUAGE_NOT_SPECIFIED; + $field_langcode = Language::LANGCODE_NOT_SPECIFIED; $body_key = "body[$field_langcode][0][value]"; $this->assertFieldByXPath('//input[@id="edit-title"]', $node->label(), "Original title value correctly populated."); - $this->assertFieldByXPath("//textarea[@name='$body_key']", $node->body[LANGUAGE_NOT_SPECIFIED][0]['value'], "Original body value correctly populated."); + $this->assertFieldByXPath("//textarea[@name='$body_key']", $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], "Original body value correctly populated."); $edit = array(); $edit["title"] = $title; diff --git a/core/modules/translation/translation.module b/core/modules/translation/translation.module index 41d8e83..dbaab38 100644 --- a/core/modules/translation/translation.module +++ b/core/modules/translation/translation.module @@ -20,6 +20,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\entity\Plugin\Core\Entity\EntityDisplay; /** @@ -85,7 +86,7 @@ function translation_menu() { * @see translation_menu() */ function _translation_tab_access($node) { - if ($node->langcode != LANGUAGE_NOT_SPECIFIED && translation_supported_type($node->type) && node_access('view', $node)) { + if ($node->langcode != Language::LANGCODE_NOT_SPECIFIED && translation_supported_type($node->type) && node_access('view', $node)) { return translation_user_can_translate_node($node); } return FALSE; @@ -176,7 +177,7 @@ function translation_form_node_type_form_alter(&$form, &$form_state) { */ function translation_node_type_language_translation_enabled_validate($element, &$form_state, $form) { if (language_is_locked($form_state['values']['language_configuration']['langcode']) && !$form_state['values']['language_configuration']['language_show'] && $form_state['values']['node_type_language_translation_enabled']) { - foreach (language_list(LANGUAGE_LOCKED) as $language) { + foreach (language_list(Language::STATE_LOCKED) as $language) { $locked_languages[] = $language->name; } form_set_error('node_type_language_translation_enabled', t('Translation is not supported if language is always one of: @locked_languages', array('@locked_languages' => implode(", ", $locked_languages)))); @@ -203,7 +204,7 @@ function translation_form_node_form_alter(&$form, &$form_state) { // Disable languages for existing translations, so it is not possible // to switch this node to some language which is already in the // translation set. Also remove the language neutral option. - unset($form['langcode']['#options'][LANGUAGE_NOT_SPECIFIED]); + unset($form['langcode']['#options'][Language::LANGCODE_NOT_SPECIFIED]); foreach (translation_node_get_translations($node->tnid) as $langcode => $translation) { if ($translation->nid != $node->nid) { unset($form['langcode']['#options'][$langcode]); @@ -252,7 +253,7 @@ function translation_node_view(EntityInterface $node, EntityDisplay $display, $v // If the site has no translations or is not multilingual we have no content // translation links to display. if (isset($node->tnid) && language_multilingual() && $translations = translation_node_get_translations($node->tnid)) { - $languages = language_list(LANGUAGE_ALL); + $languages = language_list(Language::STATE_ALL); // There might be a language provider enabled defining custom language // switch links which need to be taken into account while generating the @@ -547,7 +548,7 @@ function translation_language_switch_links_alter(array &$links, $type, $path) { // have translations it might be a language neutral node, in which case we // must leave the language switch links unaltered. This is true also for // nodes not having translation support enabled. - if (empty($node) || $node->langcode == LANGUAGE_NOT_SPECIFIED || !translation_supported_type($node->type)) { + if (empty($node) || $node->langcode == Language::LANGCODE_NOT_SPECIFIED || !translation_supported_type($node->type)) { return; } $translations = array($node->langcode => $node); diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php index ce9d3a0..9ff7615 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/EntityTranslationController.php @@ -8,6 +8,7 @@ namespace Drupal\translation_entity; use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; /** * Base class for entity translation controllers. @@ -171,7 +172,7 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac '#submit' => array(array($this, 'entityFormSourceChange')), ), ); - foreach (language_list(LANGUAGE_CONFIGURABLE) as $language) { + foreach (language_list(Language::STATE_CONFIGURABLE) as $language) { if (isset($translations[$language->langcode])) { $form['source_langcode']['source']['#options'][$language->langcode] = $language->name; } @@ -184,7 +185,7 @@ public function entityFormAlter(array &$form, array &$form_state, EntityInterfac $language_widget = isset($form['langcode']) && $form['langcode']['#type'] == 'language_select'; if ($language_widget && $has_translations) { $form['langcode']['#options'] = array(); - foreach (language_list(LANGUAGE_CONFIGURABLE) as $language) { + foreach (language_list(Language::STATE_CONFIGURABLE) as $language) { if (empty($translations[$language->langcode]) || $language->langcode == $entity_langcode) { $form['langcode']['#options'][$language->langcode] = $language->name; } diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php index 41600ac..d94cd78 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationSettingsTest.php @@ -7,6 +7,7 @@ namespace Drupal\translation_entity\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -69,7 +70,7 @@ function testSettingsUI() { // language is set as default and the language selector is hidden. $edit = array( 'entity_types[comment]' => TRUE, - 'settings[comment][comment_node_article][settings][language][langcode]' => LANGUAGE_NOT_SPECIFIED, + 'settings[comment][comment_node_article][settings][language][langcode]' => Language::LANGCODE_NOT_SPECIFIED, 'settings[comment][comment_node_article][settings][language][language_show]' => FALSE, 'settings[comment][comment_node_article][translatable]' => TRUE, 'settings[comment][comment_node_article][fields][comment_body]' => TRUE, diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php index 16eb88b..06776f9 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationUITest.php @@ -223,7 +223,7 @@ protected function getNewEntityValues($langcode) { */ protected function getEditValues($values, $langcode, $new = FALSE) { $edit = $values[$langcode]; - $langcode = $new ? LANGUAGE_NOT_SPECIFIED : $langcode; + $langcode = $new ? Language::LANGCODE_NOT_SPECIFIED : $langcode; foreach ($values[$langcode] as $property => $value) { if (is_array($value)) { $edit["{$property}[$langcode][0][value]"] = $value[0]['value']; diff --git a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationWorkflowsTest.php b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationWorkflowsTest.php index 9957552..de7db85 100644 --- a/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationWorkflowsTest.php +++ b/core/modules/translation_entity/lib/Drupal/translation_entity/Tests/EntityTranslationWorkflowsTest.php @@ -7,6 +7,7 @@ namespace Drupal\translation_entity\Tests; +use Drupal\Core\Language\Language; use Drupal\user\Plugin\Core\Entity\User; /** @@ -179,7 +180,7 @@ protected function assertWorkflows(User $user, $expected_status) { * Assert that the current page does not contain shared form elements. */ protected function assertNoSharedElements() { - $language_none = LANGUAGE_NOT_SPECIFIED; + $language_none = Language::LANGCODE_NOT_SPECIFIED; return $this->assertNoFieldByXPath("//input[@name='field_test_text[$language_none][0][value]']", NULL, 'Shared elements are not available on the translation form.'); } diff --git a/core/modules/translation_entity/translation_entity.admin.inc b/core/modules/translation_entity/translation_entity.admin.inc index 2537c84..e65c1fb 100644 --- a/core/modules/translation_entity/translation_entity.admin.inc +++ b/core/modules/translation_entity/translation_entity.admin.inc @@ -6,6 +6,7 @@ */ use Drupal\Core\Entity\EntityInterface; +use Drupal\Core\Language\Language; use Drupal\field\FieldInstance; /** @@ -234,7 +235,7 @@ function translation_entity_form_language_content_settings_validate(array $form, $values = $bundle_settings['settings']['language']; if (language_is_locked($values['langcode']) && empty($values['language_show'])) { - foreach (language_list(LANGUAGE_LOCKED) as $language) { + foreach (language_list(Language::STATE_LOCKED) as $language) { $locked_languages[] = $language->name; } form_set_error($name, t('Translation is not supported if language is always one of: @locked_languages', array('@locked_languages' => implode(', ', $locked_languages)))); @@ -315,9 +316,9 @@ function _translation_entity_update_field_translatability($settings) { $field = field_info_field($field_name); if ($field['translatable'] != $translatable) { // If a field is untranslatable, it can have no data except under - // LANGUAGE_NOT_SPECIFIED. Thus we need a field to be translatable before + // Language::LANGCODE_NOT_SPECIFIED. Thus we need a field to be translatable before // we convert data to the entity language. Conversely we need to switch - // data back to LANGUAGE_NOT_SPECIFIED before making a field + // data back to Language::LANGCODE_NOT_SPECIFIED before making a field // untranslatable lest we lose information. $field_operations = array( array('translation_entity_translatable_switch', array($translatable, $field_name)), @@ -377,7 +378,7 @@ function translation_entity_translatable_form(array $form, array &$form_state, $ * This submit handler maintains consistency between the translatability of an * entity and the language under which the field data is stored. When a field is * marked as translatable, all the data in - * $entity->{field_name}[LANGUAGE_NOT_SPECIFIED] is moved to + * $entity->{field_name}[Language::LANGCODE_NOT_SPECIFIED] is moved to * $entity->{field_name}[$entity_language]. When a field is marked as * untranslatable the opposite process occurs. Note that marking a field as * untranslatable will cause all of its translations to be permanently removed, @@ -400,9 +401,9 @@ function translation_entity_translatable_form_submit(array $form, array $form_st } // If a field is untranslatable, it can have no data except under - // LANGUAGE_NOT_SPECIFIED. Thus we need a field to be translatable before we + // Language::LANGCODE_NOT_SPECIFIED. Thus we need a field to be translatable before we // convert data to the entity language. Conversely we need to switch data back - // to LANGUAGE_NOT_SPECIFIED before making a field untranslatable lest we lose + // to Language::LANGCODE_NOT_SPECIFIED before making a field untranslatable lest we lose // information. $operations = array( array('translation_entity_translatable_batch', array(!$translatable, $field_name)), @@ -443,7 +444,7 @@ function translation_entity_translatable_switch($translatable, $field_name) { } /** - * Batch callback: Converts field data to or from LANGUAGE_NOT_SPECIFIED. + * Batch callback: Converts field data to or from Language::LANGCODE_NOT_SPECIFIED. * * @param bool $translatable * Indicator of whether the field should be made translatable (TRUE) or @@ -514,7 +515,7 @@ function translation_entity_translatable_batch($translatable, $field_name, &$con $langcode = $entity->language()->langcode; // Skip process for language neutral entities. - if ($langcode == LANGUAGE_NOT_SPECIFIED) { + if ($langcode == Language::LANGCODE_NOT_SPECIFIED) { continue; } @@ -524,27 +525,27 @@ function translation_entity_translatable_batch($translatable, $field_name, &$con // we need to store the new translations and only after we can remove the // old ones. Otherwise we might have data loss, since the removal of the // old translations might occur before the new ones are stored. - if ($translatable && isset($entity->{$field_name}[LANGUAGE_NOT_SPECIFIED])) { + if ($translatable && isset($entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED])) { // If the field is being switched to translatable and has data for - // LANGUAGE_NOT_SPECIFIED then we need to move the data to the right + // Language::LANGCODE_NOT_SPECIFIED then we need to move the data to the right // language. - $entity->{$field_name}[$langcode] = $entity->{$field_name}[LANGUAGE_NOT_SPECIFIED]; + $entity->{$field_name}[$langcode] = $entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED]; // Store the original value. _translation_entity_update_field($entity_type, $entity, $field_name); - $entity->{$field_name}[LANGUAGE_NOT_SPECIFIED] = array(); + $entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED] = array(); // Remove the language neutral value. _translation_entity_update_field($entity_type, $entity, $field_name); } elseif (!$translatable && isset($entity->{$field_name}[$langcode])) { // The field has been marked untranslatable and has data in the entity - // language: we need to move it to LANGUAGE_NOT_SPECIFIED and drop the + // language: we need to move it to Language::LANGCODE_NOT_SPECIFIED and drop the // other translations. - $entity->{$field_name}[LANGUAGE_NOT_SPECIFIED] = $entity->{$field_name}[$langcode]; + $entity->{$field_name}[Language::LANGCODE_NOT_SPECIFIED] = $entity->{$field_name}[$langcode]; // Store the original value. _translation_entity_update_field($entity_type, $entity, $field_name); // Remove translations. foreach ($entity->{$field_name} as $langcode => $items) { - if ($langcode != LANGUAGE_NOT_SPECIFIED) { + if ($langcode != Language::LANGCODE_NOT_SPECIFIED) { $entity->{$field_name}[$langcode] = array(); } } diff --git a/core/modules/translation_entity/translation_entity.install b/core/modules/translation_entity/translation_entity.install index 0279b92..977d5fd 100644 --- a/core/modules/translation_entity/translation_entity.install +++ b/core/modules/translation_entity/translation_entity.install @@ -5,6 +5,8 @@ * Installation functions for Entity Translation module. */ +use Drupal\Core\Language\Language; + /** * Implements hook_schema(). */ @@ -84,7 +86,7 @@ function translation_entity_install() { // hook_module_implements_alter() is run among the last ones. module_set_weight('translation_entity', 10); language_negotiation_include(); - language_negotiation_set(LANGUAGE_TYPE_CONTENT, array(LANGUAGE_NEGOTIATION_URL => 0)); + language_negotiation_set(Language::TYPE_CONTENT, array(LANGUAGE_NEGOTIATION_URL => 0)); } /** diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module index 68eb96d..c933cf6 100644 --- a/core/modules/translation_entity/translation_entity.module +++ b/core/modules/translation_entity/translation_entity.module @@ -65,7 +65,7 @@ function translation_entity_module_implements_alter(&$implementations, $hook) { function translation_entity_language_types_info_alter(array &$language_types) { // Make content language negotiation configurable by removing its predefined // configuration. - unset($language_types[LANGUAGE_TYPE_CONTENT]['fixed']); + unset($language_types[Language::TYPE_CONTENT]['fixed']); } /** @@ -312,7 +312,7 @@ function translation_entity_view_access(EntityInterface $entity, $langcode, $acc */ function translation_entity_add_access(EntityInterface $entity, Language $source = NULL, Language $target = NULL) { $source = !empty($source) ? $source : $entity->language(); - $target = !empty($target) ? $target : language(LANGUAGE_TYPE_CONTENT); + $target = !empty($target) ? $target : language(Language::TYPE_CONTENT); $translations = $entity->getTranslationLanguages(); $languages = language_list(); return $source->langcode != $target->langcode && isset($languages[$source->langcode]) && isset($languages[$target->langcode]) && !isset($translations[$target->langcode]) && translation_entity_access($entity, 'create'); @@ -328,7 +328,7 @@ function translation_entity_add_access(EntityInterface $entity, Language $source * content language. */ function translation_entity_edit_access(EntityInterface $entity, Language $language = NULL) { - $language = !empty($language) ? $language : language(LANGUAGE_TYPE_CONTENT); + $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); $translations = $entity->getTranslationLanguages(); $languages = language_list(); return isset($languages[$language->langcode]) && $language->langcode != $entity->language()->langcode && isset($translations[$language->langcode]) && translation_entity_access($entity, 'update'); @@ -344,7 +344,7 @@ function translation_entity_edit_access(EntityInterface $entity, Language $langu * content language. */ function translation_entity_delete_access(EntityInterface $entity, Language $language = NULL) { - $language = !empty($language) ? $language : language(LANGUAGE_TYPE_CONTENT); + $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); $translations = $entity->getTranslationLanguages(); $languages = language_list(); return isset($languages[$language->langcode]) && $language->langcode != $entity->language()->langcode && isset($translations[$language->langcode]) && translation_entity_access($entity, 'delete'); @@ -649,14 +649,14 @@ function translation_entity_field_language_alter(&$display_language, $context) { foreach ($entity->translation as $langcode => $translation) { if ($langcode == $context['langcode'] || !translation_entity_view_access($entity, $langcode)) { // Unset unaccessible field translations: if the field is untranslatable - // unsetting a language different from LANGUAGE_NOT_SPECIFIED has no + // unsetting a language different from Language::LANGCODE_NOT_SPECIFIED has no // effect. foreach ($instances as $instance) { // @todo BC entities have the same value accessibile both with the - // entity language and with LANGUAGE_DEFAULT. We need need to unset + // entity language and with Language::LANGCODE_DEFAULT. We need need to unset // both until we remove the BC layer. if ($langcode == $entity_langcode) { - unset($entity->{$instance['field_name']}[LANGUAGE_DEFAULT]); + unset($entity->{$instance['field_name']}[Language::LANGCODE_DEFAULT]); } unset($entity->{$instance['field_name']}[$langcode]); } @@ -947,7 +947,7 @@ function translation_entity_language_configuration_element_validate($element, ar $key = $form_state['translation_entity']['key']; $values = $form_state['values'][$key]; if (language_is_locked($values['langcode']) && !$values['language_show'] && $values['translation_entity']) { - foreach (language_list(LANGUAGE_LOCKED) as $language) { + foreach (language_list(Language::STATE_LOCKED) as $language) { $locked_languages[] = $language->name; } // @todo Set the correct form element name as soon as the element parents diff --git a/core/modules/translation_entity/translation_entity.pages.inc b/core/modules/translation_entity/translation_entity.pages.inc index 3db479f..3f26e01 100644 --- a/core/modules/translation_entity/translation_entity.pages.inc +++ b/core/modules/translation_entity/translation_entity.pages.inc @@ -164,12 +164,12 @@ function translation_entity_overview(EntityInterface $entity) { * A renderable array of language switch links. */ function _translation_entity_get_switch_links($path) { - $links = language_negotiation_get_switch_links(LANGUAGE_TYPE_CONTENT, $path); + $links = language_negotiation_get_switch_links(Language::TYPE_CONTENT, $path); if (empty($links)) { // If content language is set up to fall back to the interface language, - // then there will be no switch links for LANGUAGE_TYPE_CONTENT, ergo we + // then there will be no switch links for Language::TYPE_CONTENT, ergo we // also need to use interface switch links. - $links = language_negotiation_get_switch_links(LANGUAGE_TYPE_INTERFACE, $path); + $links = language_negotiation_get_switch_links(Language::TYPE_INTERFACE, $path); } return $links; } @@ -191,7 +191,7 @@ function _translation_entity_get_switch_links($path) { */ function translation_entity_add_page(EntityInterface $entity, Language $source = NULL, Language $target = NULL) { $source = !empty($source) ? $source : $entity->language(); - $target = !empty($target) ? $target : language(LANGUAGE_TYPE_CONTENT); + $target = !empty($target) ? $target : language(Language::TYPE_CONTENT); // @todo Exploit the upcoming hook_entity_prepare() when available. translation_entity_prepare_translation($entity, $source, $target); $info = $entity->entityInfo(); @@ -217,7 +217,7 @@ function translation_entity_add_page(EntityInterface $entity, Language $source = * A processed form array ready to be rendered. */ function translation_entity_edit_page(EntityInterface $entity, Language $language = NULL) { - $language = !empty($language) ? $language : language(LANGUAGE_TYPE_CONTENT); + $language = !empty($language) ? $language : language(Language::TYPE_CONTENT); $info = $entity->entityInfo(); $operation = isset($info['default_operation']) ? $info['default_operation'] : 'default'; $form_state['langcode'] = $language->langcode; diff --git a/core/modules/user/lib/Drupal/user/AccountFormController.php b/core/modules/user/lib/Drupal/user/AccountFormController.php index 8f2f0c5..ac1e115 100644 --- a/core/modules/user/lib/Drupal/user/AccountFormController.php +++ b/core/modules/user/lib/Drupal/user/AccountFormController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Language\Language; /** * Form controller for the user account forms. @@ -22,7 +23,7 @@ public function form(array $form, array &$form_state, EntityInterface $account) global $user; $config = config('user.settings'); - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $register = empty($account->uid); $admin = user_access('administer users'); @@ -180,7 +181,7 @@ public function form(array $form, array &$form_state, EntityInterface $account) // Is default the interface language? include_once DRUPAL_ROOT . '/core/includes/language.inc'; - $interface_language_is_default = language_negotiation_method_get_first(LANGUAGE_TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_SELECTED; + $interface_language_is_default = language_negotiation_method_get_first(Language::TYPE_INTERFACE) != LANGUAGE_NEGOTIATION_SELECTED; $form['language'] = array( '#type' => language_multilingual() ? 'details' : 'container', '#title' => t('Language settings'), @@ -192,7 +193,7 @@ public function form(array $form, array &$form_state, EntityInterface $account) $form['language']['preferred_langcode'] = array( '#type' => 'language_select', '#title' => t('Site language'), - '#languages' => LANGUAGE_CONFIGURABLE, + '#languages' => Language::STATE_CONFIGURABLE, '#default_value' => $user_preferred_langcode, '#description' => $interface_language_is_default ? t("This account's preferred language for e-mails and site presentation.") : t("This account's preferred language for e-mails."), ); @@ -200,7 +201,7 @@ public function form(array $form, array &$form_state, EntityInterface $account) $form['language']['preferred_admin_langcode'] = array( '#type' => 'language_select', '#title' => t('Administration pages language'), - '#languages' => LANGUAGE_CONFIGURABLE, + '#languages' => Language::STATE_CONFIGURABLE, '#default_value' => $user_preferred_admin_langcode, '#access' => user_access('access administration pages', $account), ); diff --git a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php index fb7cbbb..17254cd 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Core/Entity/User.php @@ -10,6 +10,7 @@ use Drupal\Core\Entity\Entity; use Drupal\Component\Annotation\Plugin; use Drupal\Core\Annotation\Translation; +use Drupal\Core\Language\Language; /** * Defines the user entity class. @@ -138,21 +139,21 @@ class User extends Entity { * * @var string */ - public $langcode = LANGUAGE_NOT_SPECIFIED; + public $langcode = Language::LANGCODE_NOT_SPECIFIED; /** * The user's preferred langcode for receiving emails and viewing the site. * * @var string */ - public $preferred_langcode = LANGUAGE_NOT_SPECIFIED; + public $preferred_langcode = Language::LANGCODE_NOT_SPECIFIED; /** * The user's preferred langcode for viewing administration pages. * * @var string */ - public $preferred_admin_langcode = LANGUAGE_NOT_SPECIFIED; + public $preferred_admin_langcode = Language::LANGCODE_NOT_SPECIFIED; /** * The email address used for initial account creation. diff --git a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php index 70623bd..b425ac0 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserCancelTest.php @@ -7,6 +7,7 @@ namespace Drupal\user\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -287,7 +288,7 @@ function testUserDelete() { $node = $this->drupalCreateNode(array('uid' => $account->uid)); // Create comment. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array(); $edit['subject'] = $this->randomName(8); $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php index 7764699..0a0188a 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserPictureTest.php @@ -7,6 +7,7 @@ namespace Drupal\user\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -107,7 +108,7 @@ function testPictureOnNodeComment() { variable_set('theme_settings', array('toggle_comment_user_picture' => TRUE)); $edit = array( - 'comment_body[' . LANGUAGE_NOT_SPECIFIED . '][0][value]' => $this->randomString(), + 'comment_body[' . Language::LANGCODE_NOT_SPECIFIED . '][0][value]' => $this->randomString(), ); $this->drupalPost('comment/reply/' . $node->nid, $edit, t('Save')); $this->assertRaw(file_uri_target($file->uri), 'User picture found on comment.'); @@ -122,6 +123,6 @@ function saveUserPicture($image) { // Load actual user data from database. $account = user_load($this->web_user->uid, TRUE); - return file_load($account->user_picture[LANGUAGE_NOT_SPECIFIED][0]['fid'], TRUE); + return file_load($account->user_picture[Language::LANGCODE_NOT_SPECIFIED][0]['fid'], TRUE); } } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php index 38ca376..823162b 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserRegistrationTest.php @@ -7,6 +7,7 @@ namespace Drupal\user\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; class UserRegistrationTest extends WebTestBase { @@ -240,7 +241,7 @@ function testRegistrationWithUserFields() { // Check user fields. $accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail)); $new_user = reset($accounts); - $this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][0]['value'], $value, 'The field value was correclty saved.'); + $this->assertEqual($new_user->test_user_field[Language::LANGCODE_NOT_SPECIFIED][0]['value'], $value, 'The field value was correclty saved.'); // Check that the 'add more' button works. $field['cardinality'] = FIELD_CARDINALITY_UNLIMITED; @@ -268,9 +269,9 @@ function testRegistrationWithUserFields() { // Check user fields. $accounts = entity_load_multiple_by_properties('user', array('name' => $name, 'mail' => $mail)); $new_user = reset($accounts); - $this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][0]['value'], $value, format_string('@js : The field value was correclty saved.', array('@js' => $js))); - $this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][1]['value'], $value + 1, format_string('@js : The field value was correclty saved.', array('@js' => $js))); - $this->assertEqual($new_user->test_user_field[LANGUAGE_NOT_SPECIFIED][2]['value'], $value + 2, format_string('@js : The field value was correclty saved.', array('@js' => $js))); + $this->assertEqual($new_user->test_user_field[Language::LANGCODE_NOT_SPECIFIED][0]['value'], $value, format_string('@js : The field value was correclty saved.', array('@js' => $js))); + $this->assertEqual($new_user->test_user_field[Language::LANGCODE_NOT_SPECIFIED][1]['value'], $value + 1, format_string('@js : The field value was correclty saved.', array('@js' => $js))); + $this->assertEqual($new_user->test_user_field[Language::LANGCODE_NOT_SPECIFIED][2]['value'], $value + 2, format_string('@js : The field value was correclty saved.', array('@js' => $js))); } } } diff --git a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php index ab4c706..85925e7 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserSignatureTest.php @@ -7,6 +7,7 @@ namespace Drupal\user\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; /** @@ -100,7 +101,7 @@ function testUserSignature() { $this->assertFieldByName('signature[value]', $edit['signature[value]'], 'Submitted signature text found.'); // Create a comment. - $langcode = LANGUAGE_NOT_SPECIFIED; + $langcode = Language::LANGCODE_NOT_SPECIFIED; $edit = array(); $edit['subject'] = $this->randomName(8); $edit['comment_body[' . $langcode . '][0][value]'] = $this->randomName(16); diff --git a/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php b/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php index d14e826..c9de1a7 100644 --- a/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php +++ b/core/modules/user/lib/Drupal/user/Tests/UserTokenReplaceTest.php @@ -42,7 +42,7 @@ public function setUp() { * Creates a user, then tests the tokens generated from it. */ function testUserTokenReplacement() { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $url_options = array( 'absolute' => TRUE, 'language' => $language_interface, diff --git a/core/modules/user/lib/Drupal/user/UserAccessController.php b/core/modules/user/lib/Drupal/user/UserAccessController.php index 13b8c6b..db0427d 100644 --- a/core/modules/user/lib/Drupal/user/UserAccessController.php +++ b/core/modules/user/lib/Drupal/user/UserAccessController.php @@ -9,6 +9,7 @@ use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityAccessController; +use Drupal\Core\Language\Language; use Drupal\user\Plugin\Core\Entity\User; /** @@ -19,7 +20,7 @@ class UserAccessController extends EntityAccessController { /** * Implements EntityAccessControllerInterface::viewAccess(). */ - public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function viewAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { $uid = $entity->uid; if (!$account) { $account = $GLOBALS['user']; @@ -42,14 +43,14 @@ public function viewAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT /** * Implements EntityAccessControllerInterface::createAccess(). */ - public function createAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function createAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { return user_access('administer users', $account); } /** * Implements EntityAccessControllerInterface::updateAccess(). */ - public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function updateAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { if (!$account) { $account = $GLOBALS['user']; } @@ -61,7 +62,7 @@ public function updateAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAU /** * Implements EntityAccessControllerInterface::deleteAccess(). */ - public function deleteAccess(EntityInterface $entity, $langcode = LANGUAGE_DEFAULT, User $account = NULL) { + public function deleteAccess(EntityInterface $entity, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) { if (!$account) { $account = $GLOBALS['user']; } diff --git a/core/modules/user/user.install b/core/modules/user/user.install index c7fd16b..d2d21dc 100644 --- a/core/modules/user/user.install +++ b/core/modules/user/user.install @@ -6,6 +6,7 @@ */ use Drupal\Component\Uuid\Uuid; +use Drupal\Core\Language\Language; /** * Implements hook_schema(). @@ -690,7 +691,7 @@ function user_update_8011() { 'status' => FILE_STATUS_PERMANENT, 'filename' => drupal_basename($destination), 'uuid' => $uuid->generate(), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'filesize' => filesize($destination), 'filemime' => file_get_mimetype($destination), 'timestamp' => REQUEST_TIME, @@ -836,7 +837,7 @@ function user_update_8012(&$sandbox) { 'bundle' => 'user', 'entity_id' => $uid, 'revision_id' => $uid, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'delta' => 0, 'user_picture_fid' => $fid, )) @@ -847,7 +848,7 @@ function user_update_8012(&$sandbox) { 'bundle' => 'user', 'entity_id' => $uid, 'revision_id' => $uid, - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'delta' => 0, 'user_picture_fid' => $fid, )) @@ -1045,7 +1046,7 @@ function user_update_8017() { ->set('uuid', $uuid->generate()) ->set('label', $role->name) ->set('weight', $role->weight) - ->set('langcode', LANGUAGE_NOT_SPECIFIED) + ->set('langcode', Language::LANGCODE_NOT_SPECIFIED) ->save(); } diff --git a/core/modules/user/user.pages.inc b/core/modules/user/user.pages.inc index 140b767..c7ae494 100644 --- a/core/modules/user/user.pages.inc +++ b/core/modules/user/user.pages.inc @@ -5,6 +5,7 @@ * User page callback file for the user module. */ +use Drupal\Core\Language\Language; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -63,7 +64,7 @@ function user_pass_validate($form, &$form_state) { } function user_pass_submit($form, &$form_state) { - $language_interface = language(LANGUAGE_TYPE_INTERFACE); + $language_interface = language(Language::TYPE_INTERFACE); $account = $form_state['values']['account']; // Mail one time login URL and instructions using current language. diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php index 7df986e..a66b76d 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/cache/CachePluginBase.php @@ -7,6 +7,7 @@ namespace Drupal\views\Plugin\views\cache; +use Drupal\Core\Language\Language; use Drupal\views\ViewExecutable; use Drupal\Core\Cache\CacheBackendInterface; use Drupal\views\Plugin\views\PluginBase; @@ -286,7 +287,7 @@ public function generateResultsKey() { 'build_info' => $build_info, 'roles' => array_keys($user->roles), 'super-user' => $user->uid == 1, // special caching for super user. - 'langcode' => language(LANGUAGE_TYPE_INTERFACE)->langcode, + 'langcode' => language(Language::TYPE_INTERFACE)->langcode, 'base_url' => $GLOBALS['base_url'], ); foreach (array('exposed_info', 'page', 'sort', 'order', 'items_per_page', 'offset') as $key) { @@ -315,7 +316,7 @@ public function generateOutputKey() { 'roles' => array_keys($user->roles), 'super-user' => $user->uid == 1, // special caching for super user. 'theme' => $GLOBALS['theme'], - 'langcode' => language(LANGUAGE_TYPE_INTERFACE)->langcode, + 'langcode' => language(Language::TYPE_INTERFACE)->langcode, 'base_url' => $GLOBALS['base_url'], ); diff --git a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php index eb22ed2..3836263 100644 --- a/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php +++ b/core/modules/views/lib/Drupal/views/Plugin/views/display/DisplayPluginBase.php @@ -7,6 +7,7 @@ namespace Drupal\views\Plugin\views\display; +use Drupal\Core\Language; use Drupal\views\Plugin\views\area\AreaPluginBase; use Drupal\views\ViewExecutable; use \Drupal\views\Plugin\views\PluginBase; @@ -1201,7 +1202,7 @@ public function optionsSummary(&$categories, &$options) { $languages = array( '***CURRENT_LANGUAGE***' => t("Current user's language"), '***DEFAULT_LANGUAGE***' => t("Default site language"), - LANGUAGE_NOT_SPECIFIED => t('Language neutral'), + Language::LANGCODE_NOT_SPECIFIED => t('Language neutral'), ); if (\Drupal::moduleHandler()->moduleExists('language')) { $languages = array_merge($languages, language_list()); @@ -1572,7 +1573,7 @@ public function buildOptionsForm(&$form, &$form_state) { $languages = array( '***CURRENT_LANGUAGE***' => t("Current user's language"), '***DEFAULT_LANGUAGE***' => t("Default site language"), - LANGUAGE_NOT_SPECIFIED => t('Language neutral'), + Language::LANGCODE_NOT_SPECIFIED => t('Language neutral'), ); $languages = array_merge($languages, views_language_list()); diff --git a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php index c4f90b8..acae14b 100644 --- a/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/DefaultViewsTest.php @@ -7,6 +7,7 @@ namespace Drupal\views\Tests; +use Drupal\Core\Language\Language; use Drupal\simpletest\WebTestBase; use Drupal\views\ViewExecutable; @@ -51,7 +52,7 @@ protected function setUp() { 'name' => $this->randomName(), 'description' => $this->randomName(), 'vid' => drupal_strtolower($this->randomName()), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, 'help' => '', 'nodes' => array('page' => 'page'), 'weight' => mt_rand(0, 10), @@ -106,7 +107,7 @@ protected function setUp() { $node = $this->drupalCreateNode($values); - search_index($node->nid, 'node', $node->body[LANGUAGE_NOT_SPECIFIED][0]['value'], LANGUAGE_NOT_SPECIFIED); + search_index($node->nid, 'node', $node->body[Language::LANGCODE_NOT_SPECIFIED][0]['value'], Language::LANGCODE_NOT_SPECIFIED); $comment = array( 'uid' => $user->uid, @@ -161,7 +162,7 @@ function createTerm($vocabulary) { // Use the first available text format. 'format' => $format->format, 'vid' => $vocabulary->id(), - 'langcode' => LANGUAGE_NOT_SPECIFIED, + 'langcode' => Language::LANGCODE_NOT_SPECIFIED, )); taxonomy_term_save($term); return $term; diff --git a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php index 7c150dc..136465c 100644 --- a/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php +++ b/core/modules/views/lib/Drupal/views/Tests/Wizard/TaggedWithTest.php @@ -7,6 +7,8 @@ namespace Drupal\views\Tests\Wizard; +use Drupal\Core\Language\Language; + /** * Tests the ability of the views wizard to create views filtered by taxonomy. */ @@ -103,7 +105,7 @@ function testTaggedWith() { $node_add_path = 'node/add/' . $this->node_type_with_tags->type; // Create three nodes, with different tags. - $tag_field = $this->tag_field['field_name'] . '[' . LANGUAGE_NOT_SPECIFIED . ']'; + $tag_field = $this->tag_field['field_name'] . '[' . Language::LANGCODE_NOT_SPECIFIED . ']'; $edit = array(); $edit['title'] = $node_tag1_title = $this->randomName(); $edit[$tag_field] = 'tag1'; diff --git a/core/modules/views/lib/Drupal/views/ViewsDataCache.php b/core/modules/views/lib/Drupal/views/ViewsDataCache.php index bc5bd02..0d1032e 100644 --- a/core/modules/views/lib/Drupal/views/ViewsDataCache.php +++ b/core/modules/views/lib/Drupal/views/ViewsDataCache.php @@ -11,6 +11,7 @@ use Drupal\Core\Config\ConfigFactory; use Drupal\Core\Extension\ModuleHandlerInterface; use Drupal\Core\DestructableInterface; +use Drupal\Core\Language\Language; /** * Class to manage and lazy load cached views data. @@ -95,7 +96,7 @@ public function __construct(CacheBackendInterface $cache_backend, ConfigFactory $this->cacheBackend = $cache_backend; $this->moduleHandler = $module_handler; - $this->langcode = language(LANGUAGE_TYPE_INTERFACE)->langcode; + $this->langcode = language(Language::TYPE_INTERFACE)->langcode; $this->skipCache = $config->get('views.settings')->get('skip_cache'); } diff --git a/core/modules/views/views.api.php b/core/modules/views/views.api.php index 6c5532b..2be06b5 100644 --- a/core/modules/views/views.api.php +++ b/core/modules/views/views.api.php @@ -318,7 +318,7 @@ function hook_views_query_substitutions(ViewExecutable $view) { return array( '***CURRENT_VERSION***' => VERSION, '***CURRENT_TIME***' => REQUEST_TIME, - '***CURRENT_LANGUAGE***' => language(LANGUAGE_TYPE_CONTENT)->langcode, + '***CURRENT_LANGUAGE***' => language(\Drupal\Core\Language\Language::TYPE_CONTENT)->langcode, '***DEFAULT_LANGUAGE***' => language_default()->langcode, ); } diff --git a/core/modules/views/views.module b/core/modules/views/views.module index 58a7f35..6073e8f 100644 --- a/core/modules/views/views.module +++ b/core/modules/views/views.module @@ -11,6 +11,7 @@ use Drupal\Core\Cache\Cache; use Drupal\Core\Database\Query\AlterableInterface; +use Drupal\Core\Language\Language; use Drupal\views\ViewExecutable; use Drupal\Component\Plugin\Exception\PluginException; use Drupal\views\Plugin\Core\Entity\View; @@ -634,14 +635,15 @@ function views_add_contextual_links(&$render_element, $location, ViewExecutable * array. * @param int $flags * (optional) Specifies the state of the languages that have to be returned. - * It can be: LANGUAGE_CONFIGURABLE, LANGUAGE_LOCKED, LANGUAGE_ALL. + * It can be: Language::STATE_CONFIGURABLE, Language::STATE_LOCKED, + * Language::STATE_ALL. * * @return array * An array of language names (or $field) keyed by the langcode. * * @see locale_language_list() */ -function views_language_list($field = 'name', $flags = LANGUAGE_ALL) { +function views_language_list($field = 'name', $flags = Language::STATE_ALL) { $languages = language_list($flags); $list = array(); foreach ($languages as $language) { @@ -1570,7 +1572,7 @@ function views_views_query_substitutions($view) { return array( '***CURRENT_VERSION***' => VERSION, '***CURRENT_TIME***' => REQUEST_TIME, - '***CURRENT_LANGUAGE***' => language(LANGUAGE_TYPE_CONTENT)->langcode, + '***CURRENT_LANGUAGE***' => language(Language::TYPE_CONTENT)->langcode, '***DEFAULT_LANGUAGE***' => language_default()->langcode, ); } @@ -1807,7 +1809,7 @@ function views_cache_set($cid, $data, $use_language = FALSE) { return; } if ($use_language) { - $cid .= ':' . language(LANGUAGE_TYPE_INTERFACE)->langcode; + $cid .= ':' . language(Language::TYPE_INTERFACE)->langcode; } cache('views_info')->set($cid, $data); @@ -1831,7 +1833,7 @@ function views_cache_get($cid, $use_language = FALSE) { return FALSE; } if ($use_language) { - $cid .= ':' . language(LANGUAGE_TYPE_INTERFACE)->langcode; + $cid .= ':' . language(Language::TYPE_INTERFACE)->langcode; } return cache('views_info')->get($cid); diff --git a/core/modules/views/views.theme.inc b/core/modules/views/views.theme.inc index 0bae0fc..3f7be6d 100644 --- a/core/modules/views/views.theme.inc +++ b/core/modules/views/views.theme.inc @@ -5,6 +5,7 @@ * Preprocessors and helper functions to make theming easier. */ +use Drupal\Core\Language\Language; use Drupal\Core\Template\Attribute; use Drupal\views\ViewExecutable; @@ -909,7 +910,7 @@ function template_preprocess_views_view_rss(&$vars) { $vars['link'] = check_url(url($path, $url_options)); } - $vars['langcode'] = check_plain(language(LANGUAGE_TYPE_INTERFACE)->langcode); + $vars['langcode'] = check_plain(language(Language::TYPE_INTERFACE)->langcode); $vars['namespaces'] = new Attribute($style->namespaces); $vars['items'] = $items; $vars['channel_elements'] = format_xml_elements($style->channel_elements);