Issue #1620010 by dawehner, ParisLiakos, plach, jibran: Move LANGUAGE constants to the Language class.

8.0.x
Alex Pott 2013-05-25 13:12:45 -07:00
parent 8cc75202e7
commit f2d710c607
265 changed files with 1117 additions and 829 deletions

View File

@ -187,90 +187,6 @@ const DRUPAL_AUTHENTICATED_RID = 'authenticated';
*/
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;
/**
* Time of the current request in seconds elapsed since the Unix Epoch.
*
@ -1465,7 +1381,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'] = '';
@ -1483,7 +1399,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)) {
@ -2571,7 +2487,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();
@ -2606,9 +2522,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,
);
}
@ -2630,13 +2546,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__);
@ -2672,7 +2589,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));
@ -2680,7 +2597,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;
@ -2707,13 +2624,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);
@ -2730,7 +2647,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;
}
@ -2744,7 +2661,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');
}

View File

@ -2,6 +2,7 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\Language;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\Yaml\Parser;
use Drupal\Component\PhpStorage\PhpStorageFactory;
@ -1261,7 +1262,7 @@ function filter_xss_bad_protocol($string, $decode = TRUE) {
* Arbitrary elements may be added using the $args associative array.
*/
function format_rss_channel($title, $link, $description, $items, $langcode = NULL, $args = array()) {
$langcode = $langcode ? $langcode : language(LANGUAGE_TYPE_CONTENT)->langcode;
$langcode = $langcode ? $langcode : language(Language::TYPE_CONTENT)->langcode;
$output = "<channel>\n";
$output .= ' <title>' . check_plain($title) . "</title>\n";
@ -1563,7 +1564,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.
@ -1711,7 +1712,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
@ -1946,7 +1947,7 @@ function l($text, $path, array $options = array()) {
$active = array(
'path' => current_path(),
'front_page' => drupal_is_front_page(),
'language' => language(LANGUAGE_TYPE_URL)->langcode,
'language' => language(Language::TYPE_URL)->langcode,
'query' => Drupal::service('request')->query->all(),
);
}

View File

@ -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;
}

View File

@ -10,6 +10,7 @@ use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\Form\BaseFormIdInterface;
use Drupal\Core\Database\Database;
use Drupal\Core\Language\Language;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Utility\Color;
@ -3761,7 +3762,7 @@ function form_validate_table($element, &$form_state) {
*/
function form_process_machine_name($element, &$form_state) {
// We need to pass the langcode to the client.
$language = language(LANGUAGE_TYPE_INTERFACE);
$language = language(Language::TYPE_INTERFACE);
// Apply default form element properties.
$element += array(

View File

@ -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 @@ const LANGUAGE_NEGOTIATION_SELECTED = 'language-selected';
* 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,18 @@ 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);

View File

@ -7,6 +7,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;
@ -1109,7 +1110,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;
@ -1220,7 +1221,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);
@ -1371,7 +1372,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.

View File

@ -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', '简体中文'),

View File

@ -10,6 +10,7 @@
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Config\Config;
use Drupal\Core\Language\Language;
use Drupal\Core\Template\Attribute;
use Drupal\Core\Utility\ThemeRegistry;
use Drupal\Core\Theme\ThemeSettings;
@ -1790,7 +1791,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'];
@ -2736,7 +2737,7 @@ function _template_preprocess_default_variables() {
* @see system_elements()
*/
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.).
@ -2870,7 +2871,7 @@ function template_preprocess_html(&$variables) {
* @see template_process_page()
*/
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.
@ -3085,7 +3086,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'];

View File

@ -12,6 +12,7 @@ use Drupal\Core\Executable\ExecutableManagerInterface;
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;
@ -32,7 +33,7 @@ class ConditionManager extends PluginManagerBase implements ExecutableManagerInt
$this->discovery = new AnnotatedClassDiscovery('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);
}

View File

@ -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.

View File

@ -7,6 +7,7 @@
namespace Drupal\Core\Entity;
use Drupal\Core\Language\Language;
use PDO;
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Entity\Query\QueryInterface;
@ -680,7 +681,7 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
public function getFieldDefinitions(array $constraints) {
if (!isset($this->entityFieldInfo)) {
// First, try to load from cache.
$cid = 'entity_field_definitions:' . $this->entityType . ':' . language(LANGUAGE_TYPE_INTERFACE)->langcode;
$cid = 'entity_field_definitions:' . $this->entityType . ':' . language(Language::TYPE_INTERFACE)->langcode;
if ($cache = cache()->get($cid)) {
$this->entityFieldInfo = $cache->data;
}

View File

@ -7,6 +7,7 @@
namespace Drupal\Core\Entity;
use Drupal\Core\Language\Language;
use PDO;
use Drupal\Core\Entity\Query\QueryInterface;
@ -202,7 +203,7 @@ class DatabaseStorageControllerNG extends DatabaseStorageController {
// 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.
@ -242,9 +243,9 @@ class DatabaseStorageControllerNG extends DatabaseStorageController {
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) {

View File

@ -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 @@ class Entity implements IteratorAggregate, EntityInterface {
public function access($operation = 'view', \Drupal\user\Plugin\Core\Entity\User $account = NULL) {
return \Drupal::entityManager()
->getAccessController($this->entityType)
->access($this, $operation, LANGUAGE_DEFAULT, $account);
->access($this, $operation, Language::LANGCODE_DEFAULT, $account);
}
/**
@ -272,7 +272,7 @@ class Entity implements IteratorAggregate, EntityInterface {
$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 @@ class Entity implements IteratorAggregate, EntityInterface {
}
}
}
$languages = array_intersect_key(language_list(LANGUAGE_ALL), $languages);
$languages = array_intersect_key(language_list(Language::STATE_ALL), $languages);
}
if (empty($include_default)) {

View File

@ -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 {
/**
* {@inheritdoc}
*/
public function access(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL) {
public function access(EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL) {
// @todo Remove this once we can rely on $account.
if (!$account) {

View File

@ -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;
@ -25,7 +26,7 @@ interface EntityAccessControllerInterface {
* Usually one of "view", "create", "update" or "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.
@ -33,7 +34,7 @@ interface EntityAccessControllerInterface {
* @return bool
* TRUE if access was granted, FALSE otherwise.
*/
public function access(EntityInterface $entity, $operation, $langcode = LANGUAGE_DEFAULT, User $account = NULL);
public function access(EntityInterface $entity, $operation, $langcode = Language::LANGCODE_DEFAULT, User $account = NULL);
/**
* Clears all cached access checks.

View File

@ -7,6 +7,7 @@
namespace Drupal\Core\Entity;
use Drupal\Core\Language\Language;
use IteratorAggregate;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\TypedData\TypedDataInterface;
@ -118,28 +119,29 @@ class EntityBCDecorator implements IteratorAggregate, EntityInterface {
// 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 @@ class EntityBCDecorator implements IteratorAggregate, EntityInterface {
// 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]);
}
}

View File

@ -9,6 +9,8 @@ namespace Drupal\Core\Entity;
use Drupal\entity\EntityFormDisplayInterface;
use Drupal\Core\Language\Language;
/**
* Base class for entity form controllers.
*/
@ -316,7 +318,7 @@ class EntityFormController implements EntityFormControllerInterface {
// 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);

View File

@ -65,7 +65,7 @@ class EntityFormControllerNG extends EntityFormController {
*/
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.
}

View File

@ -9,6 +9,7 @@ namespace Drupal\Core\Entity;
use Drupal\Component\Plugin\PluginManagerBase;
use Drupal\Component\Plugin\Factory\DefaultFactory;
use Drupal\Core\Language\Language;
use Drupal\Core\Plugin\Discovery\AlterDecorator;
use Drupal\Core\Plugin\Discovery\CacheDecorator;
use Drupal\Core\Plugin\Discovery\AnnotatedClassDiscovery;
@ -53,7 +54,7 @@ class EntityManager extends PluginManagerBase {
$this->discovery = new AnnotatedClassDiscovery('Core/Entity', $namespaces, $annotation_namespaces, 'Drupal\Core\Entity\Annotation\EntityType');
$this->discovery = new InfoHookDecorator($this->discovery, 'entity_info');
$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);
}

View File

@ -37,8 +37,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.
@ -47,7 +47,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))),
);
/**
@ -82,8 +82,8 @@ class EntityNG extends Entity {
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;
}
@ -139,12 +139,12 @@ class EntityNG extends Entity {
* 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];
}
/**
@ -160,9 +160,10 @@ class EntityNG extends Entity {
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 @@ class EntityNG extends Entity {
}
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 @@ class EntityNG extends Entity {
* @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'.");
}
@ -345,15 +346,15 @@ class EntityNG extends Entity {
}
}
}
// 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);
}
/**
@ -403,15 +404,15 @@ class EntityNG extends Entity {
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.
@ -439,11 +440,11 @@ class EntityNG extends Entity {
}
// 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.

View File

@ -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 @@ class EntityRenderController implements EntityRenderControllerInterface {
*/
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.

View File

@ -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 @@ class FinishResponseSubscriber implements EventSubscriberInterface {
// 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.

View File

@ -20,12 +20,96 @@ 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.
*

View File

@ -76,7 +76,7 @@ class LanguageManager {
* 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 @@ class LanguageManager {
*
* @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)) {

View File

@ -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 @@ class AliasManager implements AliasManagerInterface {
// 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 @@ class AliasManager implements AliasManagerInterface {
// 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 @@ class AliasManager implements AliasManagerInterface {
$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 @@ class AliasManager implements AliasManagerInterface {
// 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 @@ class AliasManager implements AliasManagerInterface {
$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 @@ class AliasManager implements AliasManagerInterface {
$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 {

View File

@ -9,6 +9,7 @@ namespace Drupal\Core\Path;
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 @@ class Path {
* - 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,

View File

@ -40,8 +40,8 @@ interface TranslatableInterface {
* 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

View File

@ -12,6 +12,7 @@ use Drupal\Component\Plugin\PluginManagerBase;
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;
@ -49,7 +50,7 @@ class ConstraintManager extends PluginManagerBase {
$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);
}

View File

@ -7,6 +7,7 @@
namespace Drupal\Core\Validation;
use Drupal\Core\Language\Language;
use Symfony\Component\Translation\TranslatorInterface;
/**
@ -55,7 +56,7 @@ class DrupalTranslator implements TranslatorInterface {
* 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;
}
/**

View File

@ -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,
));
}

View File

@ -8,6 +8,7 @@
namespace Drupal\aggregator;
use Drupal\Core\Entity\EntityFormControllerNG;
use Drupal\Core\Language\Language;
/**
* Form controller for the aggregator feed edit forms.
@ -35,7 +36,7 @@ class FeedFormController extends EntityFormControllerNG {
'#title' => t('Language'),
'#type' => 'language_select',
'#default_value' => $feed->language()->langcode,
'#languages' => LANGUAGE_ALL,
'#languages' => Language::STATE_ALL,
);
$form['url'] = array(

View File

@ -9,6 +9,7 @@ namespace Drupal\aggregator\Plugin;
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;
@ -38,7 +39,7 @@ class AggregatorPluginManager extends PluginManagerBase {
);
$this->discovery = new AnnotatedClassDiscovery("aggregator/$type", $namespaces, $annotation_namespaces, $type_annotations[$type]);
$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);
}
}

View File

@ -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 @@ EOF;
* (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();

View File

@ -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_install().
@ -215,7 +216,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(
@ -301,7 +302,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

View File

@ -9,6 +9,7 @@ namespace Drupal\custom_block;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\EntityFormControllerNG;
use Drupal\Core\Language\Language;
/**
* Form controller for the custom block edit forms.
@ -77,7 +78,7 @@ class CustomBlockFormController extends EntityFormControllerNG {
'#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'],
);

View File

@ -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 @@ class CustomBlockCreationTest extends CustomBlockTestBase {
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'));

View File

@ -7,6 +7,8 @@
namespace Drupal\custom_block\Tests;
use Drupal\Core\Language\Language;
/**
* Tests block save related functionality.
*/
@ -49,7 +51,7 @@ class CustomBlockSaveTest extends CustomBlockTestBase {
$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
);

View File

@ -7,6 +7,8 @@
namespace Drupal\custom_block\Tests;
use Drupal\Core\Language\Language;
/**
* Tests the block edit functionality.
*/
@ -29,7 +31,7 @@ class PageEditTest extends CustomBlockTestBase {
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.

View File

@ -8,6 +8,7 @@
namespace Drupal\block;
use Drupal\Core\Entity\EntityFormController;
use Drupal\Core\Language\Language;
/**
* Provides form controller for block instance forms.
@ -111,7 +112,7 @@ class BlockFormController extends EntityFormController {
$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.

View File

@ -9,6 +9,7 @@ namespace Drupal\block\Plugin\Type;
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 @@ class BlockManager extends PluginManagerBase {
$this->discovery = new AnnotatedClassDiscovery('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'));
$this->factory = new DefaultFactory($this->discovery);
}

View File

@ -7,6 +7,7 @@
namespace Drupal\block\Tests;
use Drupal\Core\Language\Language;
use Drupal\simpletest\DrupalUnitTestBase;
use Drupal\block_test\Plugin\Block\TestHtmlIdBlock;
use Drupal\Component\Plugin\Exception\PluginException;

View File

@ -7,6 +7,7 @@
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
/**
* Form constructor for administering a single book's hierarchy.
@ -78,7 +79,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();

View File

@ -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;
@ -1115,12 +1116,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.

View File

@ -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 @@ class BookTest extends WebTestBase {
// 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 @@ class BookTest extends WebTestBase {
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 @@ class BookTest extends WebTestBase {
// 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.

View File

@ -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 @@ use Drupal\Core\Template\Attribute;
*/
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.

View File

@ -7,6 +7,7 @@
namespace Drupal\ckeditor\Plugin\Editor;
use Drupal\Core\Language\Language;
use Drupal\editor\Plugin\EditorBase;
use Drupal\editor\Annotation\Editor;
use Drupal\Core\Annotation\Translation;
@ -107,7 +108,7 @@ class CKEditor extends EditorBase {
* Implements \Drupal\editor\Plugin\EditPluginInterface::getJSSettings().
*/
public function getJSSettings(EditorEntity $editor) {
$language_interface = language(LANGUAGE_TYPE_INTERFACE);
$language_interface = language(Language::TYPE_INTERFACE);
$settings = array();
$manager = drupal_container()->get('plugin.manager.ckeditor.plugin');

View File

@ -9,6 +9,7 @@ namespace Drupal\comment;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\EntityFormControllerNG;
use Drupal\Core\Language\Language;
/**
* Base for controller for comment forms.
@ -152,7 +153,7 @@ class CommentFormController extends EntityFormControllerNG {
// 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;
}

View File

@ -11,6 +11,7 @@ use Drupal\Core\Entity\EntityNG;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\comment\CommentInterface;
use Drupal\Core\Language\Language;
/**
* Defines the comment entity class.
@ -183,9 +184,9 @@ class Comment extends EntityNG implements CommentInterface {
* @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))),
);
/**

View File

@ -7,6 +7,8 @@
namespace Drupal\comment\Tests;
use Drupal\Core\Language\Language;
/**
* Tests anonymous commenting.
*/
@ -66,7 +68,7 @@ class CommentAnonymousTest extends CommentTestBase {
$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',

View File

@ -7,6 +7,8 @@
namespace Drupal\comment\Tests;
use Drupal\Core\Language\Language;
/**
* Tests comment CSS classes.
*/
@ -54,8 +56,8 @@ class CommentCSSTest extends CommentTestBase {
'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);

View File

@ -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 @@ class CommentInterfaceTest extends CommentTestBase {
* 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);

View File

@ -7,6 +7,7 @@
namespace Drupal\comment\Tests;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
/**
@ -89,7 +90,7 @@ class CommentLanguageTest extends WebTestBase {
// 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();

View File

@ -7,6 +7,8 @@
namespace Drupal\comment\Tests;
use Drupal\Core\Language\Language;
/**
* Tests comment links based on environment configurations.
*/
@ -146,8 +148,8 @@ class CommentLinksTest extends CommentTestBase {
'status' => COMMENT_PUBLISHED,
'subject' => $this->randomName(),
'hostname' => '127.0.0.1',
'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;

View File

@ -7,6 +7,8 @@
namespace Drupal\comment\Tests;
use Drupal\Core\Language\Language;
/**
* Tests the 'new' marker on comments.
*/
@ -53,8 +55,8 @@ class CommentNewIndicatorTest extends CommentTestBase {
'status' => COMMENT_PUBLISHED,
'subject' => $this->randomName(),
'hostname' => '127.0.0.1',
'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();

View File

@ -9,6 +9,8 @@ namespace Drupal\comment\Tests;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Language\Language;
/**
* Tests previewing comments.
*/
@ -33,7 +35,7 @@ class CommentPreviewTest extends CommentTestBase {
* 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 @@ class CommentPreviewTest extends CommentTestBase {
* 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);

View File

@ -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 @@ abstract class CommentTestBase extends WebTestBase {
* 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;

View File

@ -7,6 +7,8 @@
namespace Drupal\comment\Tests;
use Drupal\Core\Language\Language;
/**
* Tests comment threading.
*/
@ -23,7 +25,7 @@ class CommentThreadingTest extends CommentTestBase {
* 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);

View File

@ -7,6 +7,8 @@
namespace Drupal\comment\Tests;
use Drupal\Core\Language\Language;
/**
* Tests comment token replacement in strings.
*/
@ -24,7 +26,7 @@ class CommentTokenReplaceTest extends CommentTestBase {
*/
function testCommentTokenReplacement() {
$token_service = \Drupal::token();
$language_interface = language(LANGUAGE_TYPE_INTERFACE);
$language_interface = language(Language::TYPE_INTERFACE);
$url_options = array(
'absolute' => TRUE,
'language' => $language_interface,

View File

@ -8,6 +8,7 @@
namespace Drupal\config\Tests;
use Drupal\Core\Entity\EntityMalformedException;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
/**

View File

@ -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();
}

View File

@ -8,6 +8,7 @@
namespace Drupal\contact;
use Drupal\Core\Entity\EntityFormController;
use Drupal\Core\Language\Language;
use Drupal\user\Plugin\Core\Entity\User;
/**
@ -139,7 +140,7 @@ class MessageFormController extends EntityFormController {
public function save(array $form, array &$form_state) {
global $user;
$language_interface = language(LANGUAGE_TYPE_INTERFACE);
$language_interface = language(Language::TYPE_INTERFACE);
$message = $this->entity;
$sender = clone user_load($user->uid);

View File

@ -7,6 +7,7 @@
namespace Drupal\datetime\Tests;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
use Drupal\Core\Datetime\DrupalDateTime;
@ -85,7 +86,7 @@ class DatetimeFieldTest extends WebTestBase {
// 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.');
@ -154,7 +155,7 @@ class DatetimeFieldTest extends WebTestBase {
// 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 @@ class DatetimeFieldTest extends WebTestBase {
// 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 @@ class DatetimeFieldTest extends WebTestBase {
$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
@ -327,7 +328,7 @@ class DatetimeFieldTest extends WebTestBase {
// 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.');

View File

@ -7,6 +7,7 @@
namespace Drupal\dblog\Tests;
use Drupal\Core\Language\Language;
use Drupal\dblog\Controller\DbLogController;
use Drupal\simpletest\WebTestBase;
use SimpleXMLElement;
@ -310,7 +311,7 @@ class DbLogTest extends WebTestBase {
// 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);
@ -368,7 +369,7 @@ class DbLogTest extends WebTestBase {
* 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(
@ -398,7 +399,7 @@ class DbLogTest extends WebTestBase {
* 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),
);

View File

@ -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,7 +104,7 @@ class MetadataGeneratorTest extends EditTestBase {
// 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,
'label' => 'Simple text field',
@ -114,7 +115,7 @@ class MetadataGeneratorTest extends EditTestBase {
// 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',
@ -166,7 +167,7 @@ class MetadataGeneratorTest extends EditTestBase {
// 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',

View File

@ -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 @@ class EditIntegrationTest extends EditTestBase {
// 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 @@ class EditIntegrationTest extends EditTestBase {
// 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',

View File

@ -7,6 +7,7 @@
namespace Drupal\email\Tests;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
/**
@ -75,7 +76,7 @@ class EmailFieldTest extends WebTestBase {
// 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"');

View File

@ -7,6 +7,7 @@
namespace Drupal\entity_reference\Tests;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
/**
@ -112,6 +113,6 @@ class EntityReferenceAutoCreateTest extends WebTestBase {
$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.');
}
}

View File

@ -9,6 +9,7 @@ namespace Drupal\entity_reference\Tests;
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 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$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 @@ class EntityReferenceItemTest extends FieldUnitTestBase {
$term2 = entity_create('taxonomy_term', array(
'name' => $this->randomName(),
'vid' => $this->term->bundle(),
'langcode' => LANGUAGE_NOT_SPECIFIED,
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
));
$term2->save();

View File

@ -7,6 +7,7 @@
namespace Drupal\entity_reference\Tests;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
/**
@ -385,7 +386,7 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'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 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'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 @@ class EntityReferenceSelectionAccessTest extends WebTestBase {
'pid' => 0,
'status' => COMMENT_NOT_PUBLISHED,
'subject' => 'Comment Published on Unpublished node <&>',
'language' => LANGUAGE_NOT_SPECIFIED,
'language' => Language::LANGCODE_NOT_SPECIFIED,
),
);

View File

@ -12,6 +12,8 @@ use Drupal\Core\Entity\EntityInterface;
* 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];

View File

@ -6,6 +6,7 @@
*/
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Language\Language;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\field\Field;
@ -58,7 +59,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;

View File

@ -5,6 +5,7 @@
*/
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
use Drupal\Core\Template\Attribute;
/*
@ -272,7 +273,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);

View File

@ -7,6 +7,8 @@ use Drupal\Core\Entity\EntityInterface;
* Functions implementing Field API multilingual support.
*/
use Drupal\Core\Language\Language;
/**
* @defgroup field_language Field Language API
* @{
@ -19,10 +21,10 @@ use Drupal\Core\Entity\EntityInterface;
* @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
* installed languages with the addition of Language::LANGCODE_NOT_SPECIFIED. This
* default can be altered by modules implementing
* hook_field_available_languages_alter().
*
@ -67,7 +69,7 @@ use Drupal\Core\Entity\EntityInterface;
* 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
* 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.
@ -90,7 +92,7 @@ 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.
@ -99,7 +101,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);
}
}
@ -147,7 +149,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));
}
/**
@ -219,7 +221,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;
}
/**
@ -230,7 +232,7 @@ 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
* 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
@ -271,9 +273,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;

View File

@ -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;
@ -185,11 +186,11 @@ class Field extends FieldPluginBase {
$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);
@ -198,7 +199,7 @@ class Field extends FieldPluginBase {
$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));
}
@ -830,11 +831,11 @@ class Field extends FieldPluginBase {
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.
// (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);
@ -842,7 +843,7 @@ class Field extends FieldPluginBase {
return $langcode;
}
else {
return LANGUAGE_NOT_SPECIFIED;
return Language::LANGCODE_NOT_SPECIFIED;
}
}

View File

@ -9,6 +9,8 @@ namespace Drupal\field\Tests;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\Core\Language\Language;
/**
* Unit test class for field bulk delete and batch purge functionality.
*/
@ -124,7 +126,7 @@ class BulkDeleteTest extends FieldUnitTestBase {
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++;

View File

@ -7,6 +7,7 @@
namespace Drupal\field\Tests;
use Drupal\Core\Language\Language;
use Drupal\field\FieldException;
class CrudTest extends FieldUnitTestBase {
@ -329,7 +330,7 @@ class CrudTest extends FieldUnitTestBase {
// 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';
@ -383,17 +384,17 @@ class CrudTest extends FieldUnitTestBase {
$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['cardinality'], 'Cardinality is kept');
$this->assertEqual(count($entity->field_update[Language::LANGCODE_NOT_SPECIFIED]), $field['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['cardinality'] = ++$cardinality;

View File

@ -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 @@ class DisplayApiTest extends FieldUnitTestBase {
$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);
}
@ -99,7 +101,7 @@ class DisplayApiTest extends FieldUnitTestBase {
$setting = $display['settings']['test_formatter_setting_multiple'];
$this->assertNoText($this->label, 'Label was not displayed.');
$this->assertText('field_test_field_attach_view_alter', 'Alter fired, display passed.');
$this->assertText('field language is ' . LANGUAGE_NOT_SPECIFIED, 'Language is placed onto the context.');
$this->assertText('field language is ' . Language::LANGCODE_NOT_SPECIFIED, 'Language is placed onto the context.');
$array = array();
foreach ($this->values as $delta => $value) {
$array[] = $delta . ':' . $value['value'];
@ -153,7 +155,7 @@ class DisplayApiTest extends FieldUnitTestBase {
$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)));
@ -169,7 +171,7 @@ class DisplayApiTest extends FieldUnitTestBase {
$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)));
@ -185,7 +187,7 @@ class DisplayApiTest extends FieldUnitTestBase {
$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)));
@ -195,7 +197,7 @@ class DisplayApiTest extends FieldUnitTestBase {
// 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)));
@ -205,7 +207,7 @@ class DisplayApiTest extends FieldUnitTestBase {
// 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)));
@ -234,7 +236,7 @@ class DisplayApiTest extends FieldUnitTestBase {
$this->assertNoText($display['settings']['test_empty_string']);
// Now remove the values from the test field and retest.
$this->entity->{$this->field_name}[LANGUAGE_NOT_SPECIFIED] = array();
$this->entity->{$this->field_name}[Language::LANGCODE_NOT_SPECIFIED] = array();
field_test_entity_save($this->entity);
$output = field_view_field($this->entity, $this->field_name, $display);
$view = drupal_render($output);

View File

@ -7,6 +7,7 @@
namespace Drupal\field\Tests;
use Drupal\Core\Language\Language;
use Drupal\field\FieldValidationException;
/**
@ -34,7 +35,7 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
$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 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
*/
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 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
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 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
$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 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
$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();
@ -474,7 +475,7 @@ class FieldAttachOtherTest extends FieldUnitTestBase {
$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();

View File

@ -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 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
// 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 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
*/
function testFieldAttachLoadMultiple() {
$entity_type = 'test_entity';
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Define 2 bundles.
$bundles = array(
@ -171,7 +173,7 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
*/
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 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
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 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
// 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 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
*/
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 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
// 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';
@ -500,7 +502,7 @@ class FieldAttachStorageTest extends FieldUnitTestBase {
// 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);

View File

@ -7,6 +7,8 @@
namespace Drupal\field\Tests;
use Drupal\Core\Language\Language;
class FormTest extends FieldTestBase {
/**
@ -55,7 +57,7 @@ class FormTest extends FieldTestBase {
entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default')
->setComponent($this->field_name)
->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
@ -124,7 +126,7 @@ class FormTest extends FieldTestBase {
entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default')
->setComponent($this->field_name)
->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
@ -151,7 +153,7 @@ class FormTest extends FieldTestBase {
entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default')
->setComponent($this->field_name)
->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Submit with missing required value.
$edit = array();
@ -192,7 +194,7 @@ class FormTest extends FieldTestBase {
entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default')
->setComponent($this->field_name)
->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Display creation form -> 1 widget.
$this->drupalGet('test-entity/add/test_bundle');
@ -275,7 +277,7 @@ class FormTest extends FieldTestBase {
entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default')
->setComponent($this->field_name)
->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Add a required radio field.
field_create_field(array(
@ -322,7 +324,7 @@ class FormTest extends FieldTestBase {
entity_get_form_display($this->instance['entity_type'], $this->instance['bundle'], 'default')
->setComponent($this->field_name)
->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Display creation form -> 1 widget.
$this->drupalGet('test-entity/add/test_bundle');
@ -386,7 +388,7 @@ class FormTest extends FieldTestBase {
'type' => 'test_field_widget_multiple',
))
->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
@ -447,7 +449,7 @@ class FormTest extends FieldTestBase {
->setComponent($field_name_no_access)
->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Test that the form structure includes full information for each delta
// apart from #access.
@ -516,14 +518,14 @@ class FormTest extends FieldTestBase {
// 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'.
@ -546,10 +548,10 @@ class FormTest extends FieldTestBase {
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.
@ -577,8 +579,8 @@ class FormTest extends FieldTestBase {
);
$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,
@ -604,8 +606,8 @@ class FormTest extends FieldTestBase {
// 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));
}
/**
@ -623,7 +625,7 @@ class FormTest extends FieldTestBase {
'type' => 'hidden',
))
->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// Display the entity creation form.
$this->drupalGet('test-entity/add/test_bundle');

View File

@ -97,7 +97,7 @@ class TranslationTest extends FieldUnitTestBase {
$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.');
}
/**
@ -343,12 +343,12 @@ class TranslationTest extends FieldUnitTestBase {
$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;
}
}

View File

@ -78,7 +78,7 @@ class TranslationWebTest extends FieldTestBase {
$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.

View File

@ -7,6 +7,7 @@
namespace Drupal\field\Tests\Views;
use Drupal\Core\Language\Language;
use Drupal\views\ViewExecutable;
/**
@ -104,7 +105,7 @@ class HandlerFieldFieldTest extends FieldTestBase {
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 @@ class HandlerFieldFieldTest extends FieldTestBase {
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 @@ class HandlerFieldFieldTest extends FieldTestBase {
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 @@ class HandlerFieldFieldTest extends FieldTestBase {
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 @@ class HandlerFieldFieldTest extends FieldTestBase {
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 @@ class HandlerFieldFieldTest extends FieldTestBase {
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'];

View File

@ -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 PDO;
@ -60,7 +61,7 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
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');
@ -129,7 +130,7 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
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();
@ -210,7 +211,7 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
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);
@ -309,7 +310,7 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
$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.
@ -369,7 +370,7 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
// 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
@ -390,7 +391,7 @@ class FieldSqlStorageTest extends EntityUnitTestBase {
// 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"));
}
/**

View File

@ -9,6 +9,7 @@ namespace Drupal\field_ui\Form;
use Drupal\Core\Form\FormInterface;
use Drupal\Core\ControllerInterface;
use Drupal\Core\Language\Language;
use Drupal\field\Plugin\Core\Entity\FieldInstance;
use Drupal\field\Plugin\Type\Widget\WidgetPluginManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
@ -178,27 +179,27 @@ class FieldInstanceEditForm implements FormInterface, ControllerInterface {
// Extract the 'default value'.
$items = array();
$entity_form_display->getWidget($this->instance->getField()->id)->extractFormValues($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
$entity_form_display->getWidget($this->instance->getField()->id)->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, $this->instance, LANGUAGE_NOT_SPECIFIED, $items, $errors);
$function(NULL, $field, $this->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.
$entity_form_display->getWidget($this->instance->getField()->id)->flagErrors($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
$entity_form_display->getWidget($this->instance->getField()->id)->flagErrors($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state);
}
}
}
@ -217,7 +218,7 @@ class FieldInstanceEditForm implements FormInterface, ControllerInterface {
// Extract field values.
$items = array();
$entity_form_display->getWidget($this->instance->getField()->id)->extractFormValues($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
$entity_form_display->getWidget($this->instance->getField()->id)->extractFormValues($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state);
$this->instance['default_value'] = $items ? $items : NULL;
}
@ -297,7 +298,7 @@ class FieldInstanceEditForm implements FormInterface, ControllerInterface {
if (!empty($this->instance['default_value'])) {
$items = (array) $this->instance['default_value'];
}
$element += $entity_form_display->getWidget($this->instance->getField()->id)->form($entity, LANGUAGE_NOT_SPECIFIED, $items, $element, $form_state);
$element += $entity_form_display->getWidget($this->instance->getField()->id)->form($entity, Language::LANGCODE_NOT_SPECIFIED, $items, $element, $form_state);
return $element;
}

View File

@ -7,6 +7,7 @@
namespace Drupal\field_ui\Tests;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
/**
@ -38,7 +39,7 @@ abstract class FieldUiTestBase extends WebTestBase {
'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),

View File

@ -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 @@ class ManageFieldsTest extends FieldUiTestBase {
$vocabulary = entity_create('taxonomy_vocabulary', array(
'name' => 'Tags',
'vid' => 'tags',
'langcode' => LANGUAGE_NOT_SPECIFIED,
'langcode' => Language::LANGCODE_NOT_SPECIFIED,
));
$vocabulary->save();
@ -264,7 +266,7 @@ class ManageFieldsTest extends FieldUiTestBase {
->setComponent($field_name)
->save();
$langcode = LANGUAGE_NOT_SPECIFIED;
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$admin_path = 'admin/structure/types/manage/' . $this->type . '/fields/' . $instance->id();
$element_id = "edit-$field_name-$langcode-0-value";
$element_name = "{$field_name}[$langcode][0][value]";

View File

@ -9,6 +9,7 @@ namespace Drupal\file;
use Drupal\Core\Entity\DatabaseStorageController;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
/**
* File storage controller for files.
@ -42,7 +43,7 @@ class FileStorageController extends DatabaseStorageController {
// 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;
}
}

View File

@ -10,6 +10,7 @@ namespace Drupal\file\Plugin\Core\Entity;
use Drupal\Core\Entity\Entity;
use Drupal\Core\Entity\Annotation\EntityType;
use Drupal\Core\Annotation\Translation;
use Drupal\Core\Language\Language;
use Drupal\file\FileInterface;
/**
@ -52,7 +53,7 @@ class File extends Entity implements FileInterface {
*
* @var string
*/
public $langcode = LANGUAGE_NOT_SPECIFIED;
public $langcode = Language::LANGCODE_NOT_SPECIFIED;
/**
* The uid of the user who is associated with the file.

View File

@ -7,6 +7,8 @@
namespace Drupal\file\Tests;
use Drupal\Core\Language\Language;
/**
* Tests that formatters are working properly.
*/
@ -58,12 +60,12 @@ class FileFieldDisplayTest extends FileFieldTestBase {
// 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.'));
@ -71,8 +73,8 @@ class FileFieldDisplayTest extends FileFieldTestBase {
// 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);

View File

@ -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 @@ class FileFieldPathTest extends FileFieldTestBase {
// 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 @@ class FileFieldPathTest extends FileFieldTestBase {
// 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 @@ class FileFieldPathTest extends FileFieldTestBase {
// 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);

View File

@ -7,6 +7,8 @@
namespace Drupal\file\Tests;
use Drupal\Core\Language\Language;
/**
* Tests that formatters are working properly.
*/
@ -65,7 +67,7 @@ class FileFieldRSSContentTest extends FileFieldTestBase {
// 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');

View File

@ -7,6 +7,8 @@
namespace Drupal\file\Tests;
use Drupal\Core\Language\Language;
/**
* Tests file handling with node revisions.
*/
@ -45,7 +47,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
// 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.'));
@ -54,7 +56,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
// 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.'));
@ -62,7 +64,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
// 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.'));
@ -71,7 +73,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
// 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.'));
@ -79,7 +81,7 @@ class FileFieldRevisionTest extends FileFieldTestBase {
// 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.'));
@ -93,8 +95,8 @@ class FileFieldRevisionTest extends FileFieldTestBase {
// 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');

View File

@ -7,6 +7,7 @@
namespace Drupal\file\Tests;
use Drupal\Core\Language\Language;
use Drupal\simpletest\WebTestBase;
/**
@ -134,7 +135,7 @@ abstract class FileFieldTestBase extends WebTestBase {
* 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,
@ -186,7 +187,7 @@ abstract class FileFieldTestBase extends WebTestBase {
*/
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,
);

View File

@ -7,6 +7,8 @@
namespace Drupal\file\Tests;
use Drupal\Core\Language\Language;
/**
* Tests various validations.
*/
@ -34,7 +36,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
$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.'));
@ -45,7 +47,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
$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.'));
@ -61,7 +63,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
// 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.'));
}
@ -91,7 +93,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
// 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)));
@ -107,7 +109,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
// 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))));
}
@ -129,7 +131,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
// 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.'));
@ -147,7 +149,7 @@ class FileFieldValidateTest extends FileFieldTestBase {
// 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.'));
}

View File

@ -7,6 +7,8 @@
namespace Drupal\file\Tests;
use Drupal\Core\Language\Language;
/**
* Tests file field widget.
*/
@ -44,7 +46,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
// 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.
@ -71,13 +73,13 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$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.'));
}
}
@ -111,7 +113,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$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'));
@ -142,11 +144,11 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$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
@ -174,7 +176,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
// 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)));
@ -194,7 +196,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
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.'));
}
}
@ -214,7 +216,7 @@ class FileFieldWidgetTest extends FileFieldTestBase {
$this->drupalPost("admin/structure/types/manage/$type_name/fields/$instance->id/field", $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 @@ class FileFieldWidgetTest extends FileFieldTestBase {
// 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'));

View File

@ -7,6 +7,8 @@
namespace Drupal\file\Tests;
use Drupal\Core\Language\Language;
/**
* Tests file access on private nodes.
*/
@ -48,7 +50,7 @@ class FilePrivateTest extends FileFieldTestBase {
$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 @@ class FilePrivateTest extends FileFieldTestBase {
$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.'));

View File

@ -7,6 +7,8 @@
namespace Drupal\file\Tests;
use Drupal\Core\Language\Language;
/**
* Tests the file token replacement in strings.
*/
@ -24,7 +26,7 @@ class FileTokenReplaceTest extends FileFieldTestBase {
*/
function testFileTokenReplacement() {
$token_service = \Drupal::token();
$language_interface = language(LANGUAGE_TYPE_INTERFACE);
$language_interface = language(Language::TYPE_INTERFACE);
$url_options = array(
'absolute' => TRUE,
'language' => $language_interface,
@ -45,7 +47,7 @@ class FileTokenReplaceTest extends FileFieldTestBase {
// 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();

View File

@ -7,6 +7,8 @@
namespace Drupal\file\Tests;
use Drupal\Core\Language\Language;
/**
* Tests saving files.
*/
@ -43,7 +45,7 @@ class SaveTest extends FileManagedTestBase {
$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();

View File

@ -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;
@ -275,7 +276,7 @@ function filter_permission_name($format) {
* @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.

Some files were not shown because too many files have changed in this diff Show More