diff --git a/core/lib/Drupal/Core/Config/StorableConfigBase.php b/core/lib/Drupal/Core/Config/StorableConfigBase.php index 5c6e8b3..b9de0b6 100644 --- a/core/lib/Drupal/Core/Config/StorableConfigBase.php +++ b/core/lib/Drupal/Core/Config/StorableConfigBase.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\String; use Drupal\Core\Config\Schema\Ignore; +use Drupal\Core\StringTranslation\TranslationWrapper; use Drupal\Core\TypedData\PrimitiveInterface; use Drupal\Core\TypedData\Type\FloatInterface; use Drupal\Core\TypedData\Type\IntegerInterface; @@ -184,6 +185,10 @@ protected function castValue($key, $value) { $this->validateValue($key, $value); return $value; } + // Support translation wrappers. + if ($value instanceof TranslationWrapper) { + $value = (string) $value; + } if (is_scalar($value) || $value === NULL) { if ($element && $element instanceof PrimitiveInterface) { // Special handling for integers and floats since the configuration diff --git a/core/lib/Drupal/Core/DrupalKernel.php b/core/lib/Drupal/Core/DrupalKernel.php index 8514448..5dd1340 100644 --- a/core/lib/Drupal/Core/DrupalKernel.php +++ b/core/lib/Drupal/Core/DrupalKernel.php @@ -636,6 +636,9 @@ public function updateModules(array $module_list, array $module_filenames = arra // and container. if ($this->booted) { $this->initializeContainer(TRUE); + if ($this->containerNeedsDumping && !$this->dumpDrupalContainer($this->container, static::CONTAINER_BASE_CLASS)) { + $this->container->get('logger.factory')->get('DrupalKernel')->notice('Container cannot be written to disk'); + } } } diff --git a/core/lib/Drupal/Core/Entity/EntityManager.php b/core/lib/Drupal/Core/Entity/EntityManager.php index 94fe169..c794d93 100644 --- a/core/lib/Drupal/Core/Entity/EntityManager.php +++ b/core/lib/Drupal/Core/Entity/EntityManager.php @@ -698,7 +698,7 @@ public function getAllBundleInfo() { foreach ($this->getDefinitions() as $type => $entity_type) { // If no bundles are provided, use the entity type name and label. if (!isset($this->bundleInfo[$type])) { - $this->bundleInfo[$type][$type]['label'] = $entity_type->getLabel(); + $this->bundleInfo[$type][$type]['label'] = $entity_type->get('label'); } } $this->moduleHandler->alter('entity_bundle_info', $this->bundleInfo); diff --git a/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php b/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php index dc54e75..89a42ab 100644 --- a/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php +++ b/core/lib/Drupal/Core/Entity/Plugin/DataType/Deriver/EntityDeriver.php @@ -82,7 +82,8 @@ public function getDerivativeDefinitions($base_plugin_definition) { // Add definitions for each entity type and bundle. foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) { $this->derivatives[$entity_type_id] = array( - 'label' => $entity_type->getLabel(), + // Use get('label') to not get the already translated wrapper. + 'label' => $entity_type->get('label'), 'class' => $entity_type->getClass(), 'constraints' => array('EntityType' => $entity_type_id), ) + $base_plugin_definition; diff --git a/core/lib/Drupal/Core/Extension/ModuleHandler.php b/core/lib/Drupal/Core/Extension/ModuleHandler.php index f0b06dd..3583dea 100644 --- a/core/lib/Drupal/Core/Extension/ModuleHandler.php +++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php @@ -880,6 +880,8 @@ public function install(array $module_list, $enable_dependencies = TRUE) { $this->invokeAll('modules_installed', array($modules_installed)); } + \Drupal::service('router.builder')->setRebuildNeeded(); + return TRUE; } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php index 2fb8242..d421d21 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/BooleanItem.php @@ -7,11 +7,13 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; +use Drupal\Core\Annotation\Translation; use Drupal\Core\Field\FieldDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Session\AccountInterface; +use Drupal\Core\StringTranslation\TranslationWrapper; use Drupal\Core\TypedData\OptionsProviderInterface; use Drupal\Core\TypedData\DataDefinition; @@ -33,8 +35,8 @@ class BooleanItem extends FieldItemBase implements OptionsProviderInterface { */ public static function defaultStorageSettings() { return array( - 'on_label' => t('On'), - 'off_label' => t('Off'), + 'on_label' => new TranslationWrapper('On'), + 'off_label' => new TranslationWrapper('Off'), ) + parent::defaultStorageSettings(); } @@ -42,8 +44,10 @@ public static function defaultStorageSettings() { * {@inheritdoc} */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { + // Use TranslationWrapper as those can be called during early bootstrap, + // before the translation system is ready. $properties['value'] = DataDefinition::create('boolean') - ->setLabel(t('Boolean value')); + ->setLabel(new TranslationWrapper('Boolean value')); return $properties; } diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php index 961eb67..9c81c10 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/LanguageItem.php @@ -7,9 +7,11 @@ namespace Drupal\Core\Field\Plugin\Field\FieldType; +use Drupal\Core\Annotation\Translation; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\Field\FieldItemBase; use Drupal\Core\Language\LanguageInterface; +use Drupal\Core\StringTranslation\TranslationWrapper; use Drupal\Core\TypedData\DataDefinition; use Drupal\Core\TypedData\DataReferenceDefinition; @@ -34,12 +36,14 @@ class LanguageItem extends FieldItemBase { * {@inheritdoc} */ public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) { + // Use TranslationWrapper as those can be called during early bootstrap, + // before the translation system is ready. $properties['value'] = DataDefinition::create('string') - ->setLabel(t('Language code')); + ->setLabel(new TranslationWrapper('Language code')); $properties['language'] = DataReferenceDefinition::create('language') - ->setLabel(t('Language object')) - ->setDescription(t('The referenced language')) + ->setLabel(new TranslationWrapper('Language object')) + ->setDescription(new TranslationWrapper('The referenced language')) // The language object is retrieved via the language code. ->setComputed(TRUE) ->setReadOnly(FALSE); diff --git a/core/lib/Drupal/Core/Session/SessionHandler.php b/core/lib/Drupal/Core/Session/SessionHandler.php index c8d69fb..e4dc829 100644 --- a/core/lib/Drupal/Core/Session/SessionHandler.php +++ b/core/lib/Drupal/Core/Session/SessionHandler.php @@ -81,7 +81,7 @@ public function read($sid) { $insecure_session_name = $this->sessionManager->getInsecureName(); $cookies = $this->requestStack->getCurrentRequest()->cookies; if (!$cookies->has($this->getName()) && !$cookies->has($insecure_session_name)) { - $user = new UserSession(); + $user = new AnonymousUserSession(); return ''; } @@ -94,7 +94,7 @@ public function read($sid) { // database. if ($this->requestStack->getCurrentRequest()->isSecure()) { // Try to load a session using the HTTPS-only secure session id. - $values = $this->connection->query("SELECT u.*, s.* FROM {users_field_data} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE u.default_langcode = 1 AND s.ssid = :ssid", array( + $values = $this->connection->query("SELECT s.* FROM {sessions} s WHERE s.ssid = :ssid", array( ':ssid' => Crypt::hashBase64($sid), ))->fetchAssoc(); if (!$values) { @@ -103,7 +103,7 @@ public function read($sid) { if ($cookies->has($insecure_session_name)) { $insecure_session_id = $cookies->get($insecure_session_name); $args = array(':sid' => Crypt::hashBase64($insecure_session_id)); - $values = $this->connection->query("SELECT u.*, s.* FROM {users_field_data} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE u.default_langcode = 1 AND s.sid = :sid AND s.uid = 0", $args)->fetchAssoc(); + $values = $this->connection->query("SELECT s.* FROM {sessions} s WHERE s.sid = :sid AND s.uid = 0", $args)->fetchAssoc(); if ($values) { $this->sessionSetObsolete($insecure_session_id); } @@ -112,35 +112,34 @@ public function read($sid) { } else { // Try to load a session using the non-HTTPS session id. - $values = $this->connection->query("SELECT u.*, s.* FROM {users_field_data} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE u.default_langcode = 1 AND s.sid = :sid", array( + $values = $this->connection->query("SELECT s.* FROM {sessions} s WHERE s.sid = :sid", array( ':sid' => Crypt::hashBase64($sid), ))->fetchAssoc(); } // We found the client's session record and they are an authenticated, // active user. - if ($values && $values['uid'] > 0 && $values['status'] == 1) { - // Add roles element to $user. - $rids = $this->connection->query("SELECT ur.rid FROM {users_roles} ur WHERE ur.uid = :uid", array( - ':uid' => $values['uid'], - ))->fetchCol(); - $values['roles'] = array_merge(array(DRUPAL_AUTHENTICATED_RID), $rids); - $user = new UserSession($values); + $user = NULL; + if ($values && $values['uid'] > 0) { + $user = \Drupal::entityManager()->getStorage('user')->load($values['uid']); + if ($user->isBlocked()) { + $user = NULL; + } } - elseif ($values) { - // The user is anonymous or blocked. Only preserve two fields from the + + if (!$user && $values) { + // The user is anonymous or blocked. Only preserve the timestamp from the // {sessions} table. $user = new UserSession(array( - 'session' => $values['session'], - 'access' => $values['access'], + 'access' => $values['timestamp'], )); } - else { + elseif (!$user) { // The session has expired. - $user = new UserSession(); + $user = new AnonymousUserSession(); } - return $user->session; + return isset($values['session']) ? $values['session'] : ''; } /** diff --git a/core/modules/user/src/Entity/User.php b/core/modules/user/src/Entity/User.php index ee75930..1d494f0 100644 --- a/core/modules/user/src/Entity/User.php +++ b/core/modules/user/src/Entity/User.php @@ -12,6 +12,7 @@ use Drupal\Core\Entity\EntityStorageInterface; use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Field\BaseFieldDefinition; +use Drupal\Core\StringTranslation\TranslationWrapper; use Drupal\user\UserInterface; /** @@ -443,34 +444,34 @@ public function getChangedTime() { */ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['uid'] = BaseFieldDefinition::create('integer') - ->setLabel(t('User ID')) - ->setDescription(t('The user ID.')) + ->setLabel(new TranslationWrapper('User ID')) + ->setDescription(new TranslationWrapper('The user ID.')) ->setReadOnly(TRUE) ->setSetting('unsigned', TRUE); $fields['uuid'] = BaseFieldDefinition::create('uuid') - ->setLabel(t('UUID')) - ->setDescription(t('The user UUID.')) + ->setLabel(new TranslationWrapper('UUID')) + ->setDescription(new TranslationWrapper('The user UUID.')) ->setReadOnly(TRUE); $fields['langcode'] = BaseFieldDefinition::create('language') - ->setLabel(t('Language code')) - ->setDescription(t('The user language code.')); + ->setLabel(new TranslationWrapper('Language code')) + ->setDescription(new TranslationWrapper('The user language code.')); $fields['preferred_langcode'] = BaseFieldDefinition::create('language') - ->setLabel(t('Preferred admin language code')) - ->setDescription(t("The user's preferred language code for receiving emails and viewing the site.")); + ->setLabel(new TranslationWrapper('Preferred admin language code')) + ->setDescription(new TranslationWrapper("The user's preferred language code for receiving emails and viewing the site.")); $fields['preferred_admin_langcode'] = BaseFieldDefinition::create('language') - ->setLabel(t('Preferred language code')) - ->setDescription(t("The user's preferred language code for viewing administration pages.")) + ->setLabel(new TranslationWrapper('Preferred language code')) + ->setDescription(new TranslationWrapper("The user's preferred language code for viewing administration pages.")) ->setDefaultValue(''); // The name should not vary per language. The username is the visual // identifier for a user and needs to be consistent in all languages. $fields['name'] = BaseFieldDefinition::create('string') - ->setLabel(t('Name')) - ->setDescription(t('The name of this user.')) + ->setLabel(new TranslationWrapper('Name')) + ->setDescription(new TranslationWrapper('The name of this user.')) ->setDefaultValue('') ->setConstraints(array( // No Length constraint here because the UserName constraint also covers @@ -480,62 +481,62 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { )); $fields['pass'] = BaseFieldDefinition::create('string') - ->setLabel(t('Password')) - ->setDescription(t('The password of this user (hashed).')); + ->setLabel(new TranslationWrapper('Password')) + ->setDescription(new TranslationWrapper('The password of this user (hashed).')); $fields['mail'] = BaseFieldDefinition::create('email') - ->setLabel(t('Email')) - ->setDescription(t('The email of this user.')) + ->setLabel(new TranslationWrapper('Email')) + ->setDescription(new TranslationWrapper('The email of this user.')) ->setDefaultValue('') ->setConstraints(array('UserMailUnique' => array())); // @todo Convert to a text field in https://drupal.org/node/1548204. $fields['signature'] = BaseFieldDefinition::create('string') - ->setLabel(t('Signature')) - ->setDescription(t('The signature of this user.')) + ->setLabel(new TranslationWrapper('Signature')) + ->setDescription(new TranslationWrapper('The signature of this user.')) ->setTranslatable(TRUE); $fields['signature_format'] = BaseFieldDefinition::create('string') - ->setLabel(t('Signature format')) - ->setDescription(t('The signature format of this user.')); + ->setLabel(new TranslationWrapper('Signature format')) + ->setDescription(new TranslationWrapper('The signature format of this user.')); $fields['timezone'] = BaseFieldDefinition::create('string') - ->setLabel(t('Timezone')) - ->setDescription(t('The timezone of this user.')) + ->setLabel(new TranslationWrapper('Timezone')) + ->setDescription(new TranslationWrapper('The timezone of this user.')) ->setSetting('max_length', 32); $fields['status'] = BaseFieldDefinition::create('boolean') - ->setLabel(t('User status')) - ->setDescription(t('Whether the user is active or blocked.')) + ->setLabel(new TranslationWrapper('User status')) + ->setDescription(new TranslationWrapper('Whether the user is active or blocked.')) ->setDefaultValue(FALSE); $fields['created'] = BaseFieldDefinition::create('created') - ->setLabel(t('Created')) - ->setDescription(t('The time that the user was created.')); + ->setLabel(new TranslationWrapper('Created')) + ->setDescription(new TranslationWrapper('The time that the user was created.')); $fields['changed'] = BaseFieldDefinition::create('changed') - ->setLabel(t('Changed')) - ->setDescription(t('The time that the user was last edited.')); + ->setLabel(new TranslationWrapper('Changed')) + ->setDescription(new TranslationWrapper('The time that the user was last edited.')); $fields['access'] = BaseFieldDefinition::create('timestamp') - ->setLabel(t('Last access')) - ->setDescription(t('The time that the user last accessed the site.')) + ->setLabel(new TranslationWrapper('Last access')) + ->setDescription(new TranslationWrapper('The time that the user last accessed the site.')) ->setDefaultValue(0); $fields['login'] = BaseFieldDefinition::create('timestamp') - ->setLabel(t('Last login')) - ->setDescription(t('The time that the user last logged in.')) + ->setLabel(new TranslationWrapper('Last login')) + ->setDescription(new TranslationWrapper('The time that the user last logged in.')) ->setDefaultValue(0); $fields['init'] = BaseFieldDefinition::create('email') - ->setLabel(t('Initial email')) - ->setDescription(t('The email address used for initial account creation.')) + ->setLabel(new TranslationWrapper('Initial email')) + ->setDescription(new TranslationWrapper('The email address used for initial account creation.')) ->setDefaultValue(''); $fields['roles'] = BaseFieldDefinition::create('entity_reference') ->setCustomStorage(TRUE) - ->setLabel(t('Roles')) + ->setLabel(new TranslationWrapper('Roles')) ->setCardinality(BaseFieldDefinition::CARDINALITY_UNLIMITED) - ->setDescription(t('The roles the user has.')) + ->setDescription(new TranslationWrapper('The roles the user has.')) ->setSetting('target_type', 'user_role'); return $fields; diff --git a/core/modules/views/src/Plugin/views/display/Page.php b/core/modules/views/src/Plugin/views/display/Page.php index 08da0a2..cd54540 100644 --- a/core/modules/views/src/Plugin/views/display/Page.php +++ b/core/modules/views/src/Plugin/views/display/Page.php @@ -46,9 +46,8 @@ protected function defineOptions() { $options['menu'] = array( 'contains' => array( 'type' => array('default' => 'none'), - // Do not translate menu and title as menu system will. - 'title' => array('default' => '', 'translatable' => FALSE), - 'description' => array('default' => '', 'translatable' => FALSE), + 'title' => array('default' => ''), + 'description' => array('default' => ''), 'weight' => array('default' => 0), 'menu_name' => array('default' => 'navigation'), 'parent' => array('default' => ''), @@ -58,11 +57,9 @@ protected function defineOptions() { $options['tab_options'] = array( 'contains' => array( 'type' => array('default' => 'none'), - // Do not translate menu and title as menu system will. - 'title' => array('default' => '', 'translatable' => FALSE), - 'description' => array('default' => '', 'translatable' => FALSE), + 'title' => array('default' => ''), + 'description' => array('default' => ''), 'weight' => array('default' => 0), - 'menu_name' => array('default' => 'navigation'), ), ); @@ -336,30 +333,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) { ), ), ); - // Only display the menu selector if Menu UI module is enabled. - if (\Drupal::moduleHandler()->moduleExists('menu_ui')) { - $form['tab_options']['name'] = array( - '#title' => $this->t('Menu'), - '#type' => 'select', - '#options' => menu_ui_get_menus(), - '#default_value' => $tab_options['name'], - '#description' => $this->t('Insert item into an available menu.'), - '#states' => array( - 'visible' => array( - ':input[name="tab_options[type]"]' => array('value' => 'normal'), - ), - ), - ); - } - else { - $form['tab_options']['menu_name'] = array( - '#type' => 'value', - '#value' => $tab_options['menu_name'], - ); - $form['tab_options']['markup'] = array( - '#markup' => $this->t('Menu selection requires the activation of Menu UI module.'), - ); - } + $form['tab_options']['weight'] = array( '#suffix' => '', '#title' => $this->t('Tab weight'),