diff --git a/core/lib/Drupal/Core/Entity/EntityFormController.php b/core/lib/Drupal/Core/Entity/EntityFormController.php index 6d2c9fb..f3e01f4 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormController.php +++ b/core/lib/Drupal/Core/Entity/EntityFormController.php @@ -65,7 +65,7 @@ protected function init(array &$form_state, EntityInterface $entity) { // module-provided form handlers there. $form_state['controller'] = $this; $this->setEntity($entity, $form_state); - $this->prepareEntity($entity); + $this->prepareEntity($entity, $form_state); } /** @@ -337,7 +337,7 @@ public function setEntity(EntityInterface $entity, array &$form_state) { /** * Prepares the entity object before the form is built first. */ - protected function prepareEntity(EntityInterface $entity) { + protected function prepareEntity(EntityInterface $entity, array &$form_state) { // @todo Perform common prepare operations and add a hook. } diff --git a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php index ef9bc89..c6e3119 100644 --- a/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php +++ b/core/lib/Drupal/Core/Entity/EntityFormControllerNG.php @@ -52,16 +52,6 @@ public function validate(array $form, array &$form_state) { } /** - * Overrides EntityFormController::submitEntityLanguage(). - */ - protected function submitEntityLanguage(array $form, array &$form_state) { - // Nothing to do here, as original field values are always stored with - // LANGUAGE_DEFAULT language. - // @todo Delete this method when merging EntityFormControllerNG with - // EntityFormController. - } - - /** * Overrides EntityFormController::buildEntity(). */ public function buildEntity(array $form, array &$form_state) { diff --git a/core/lib/Drupal/Core/Entity/EntityNG.php b/core/lib/Drupal/Core/Entity/EntityNG.php index e7b629a..f0fe0ac 100644 --- a/core/lib/Drupal/Core/Entity/EntityNG.php +++ b/core/lib/Drupal/Core/Entity/EntityNG.php @@ -526,7 +526,8 @@ public function label($langcode = NULL) { $label = $entity_info['label_callback']($this->entityType, $this, $langcode); } elseif (!empty($entity_info['entity_keys']['label']) && isset($this->{$entity_info['entity_keys']['label']})) { - $label = $this->{$entity_info['entity_keys']['label']}->value; + $object = $langcode ? $this->getTranslation($langcode) : $this; + $label = $object->{$entity_info['entity_keys']['label']}->value; } return $label; } diff --git a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php index 2c9845e..c2098b9 100644 --- a/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php +++ b/core/modules/block/custom_block/lib/Drupal/custom_block/CustomBlockFormController.php @@ -24,7 +24,7 @@ class CustomBlockFormController extends EntityFormControllerNG { * Fills in a few default values, and then invokes hook_custom_block_prepare() * on all modules. */ - protected function prepareEntity(EntityInterface $block) { + protected function prepareEntity(EntityInterface $block, array &$form_state) { // Set up default values, if required. $block_type = entity_load('custom_block_type', $block->type->value); // If this is a new custom block, fill in the default values. diff --git a/core/modules/node/lib/Drupal/node/NodeFormController.php b/core/modules/node/lib/Drupal/node/NodeFormController.php index 63b4189..5283986 100644 --- a/core/modules/node/lib/Drupal/node/NodeFormController.php +++ b/core/modules/node/lib/Drupal/node/NodeFormController.php @@ -10,12 +10,12 @@ use Drupal\Component\Utility\NestedArray; use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityFormController; +use Drupal\Core\Entity\EntityFormControllerNG; /** * Form controller for the node edit forms. */ -class NodeFormController extends EntityFormController { +class NodeFormController extends EntityFormControllerNG { /** * Prepares the node object. @@ -25,25 +25,27 @@ class NodeFormController extends EntityFormController { * * Overrides Drupal\Core\Entity\EntityFormController::prepareEntity(). */ - protected function prepareEntity(EntityInterface $node) { + protected function prepareEntity(EntityInterface $node, array &$form_state) { + $translation = $node->getTranslation($this->getFormLangcode($form_state), FALSE); + // Set up default values, if required. $node_options = variable_get('node_options_' . $node->type, array('status', 'promote')); // If this is a new node, fill in the default values. if (!isset($node->nid) || isset($node->is_new)) { foreach (array('status', 'promote', 'sticky') as $key) { // Multistep node forms might have filled in something already. - if (!isset($node->$key)) { - $node->$key = (int) in_array($key, $node_options); + if (!isset($translation->$key->value)) { + $translation->$key->value = (int) in_array($key, $node_options); } } global $user; - $node->uid = $user->uid; - $node->created = REQUEST_TIME; + $translation->uid->target_id = $user->uid; + $translation->created->value = REQUEST_TIME; } else { - $node->date = new DrupalDateTime($node->created); + $node->date = new DrupalDateTime($translation->created->value); // Remove the log message from the original node entity. - $node->log = NULL; + $translation->log->value = NULL; } // Always use the default revision setting. $node->setNewRevision(in_array('revision', $node_options)); @@ -56,6 +58,7 @@ protected function prepareEntity(EntityInterface $node) { * Overrides Drupal\Core\Entity\EntityFormController::form(). */ public function form(array $form, array &$form_state, EntityInterface $node) { + $translation = $node->getTranslation($this->getFormLangcode($form_state), FALSE); $user_config = config('user.settings'); // Some special stuff when previewing a node. @@ -77,14 +80,14 @@ public function form(array $form, array &$form_state, EntityInterface $node) { foreach (array('nid', 'vid', 'uid', 'created', 'type') as $key) { $form[$key] = array( '#type' => 'value', - '#value' => isset($node->$key) ? $node->$key : NULL, + '#value' => isset($translation->$key->value) ? $translation->$key->value : NULL, ); } // Changed must be sent to the client, for later overwrite error checking. $form['changed'] = array( '#type' => 'hidden', - '#default_value' => isset($node->changed) ? $node->changed : NULL, + '#default_value' => isset($translation->changed->value) ? $translation->changed->value : NULL, ); // Invoke hook_form() to get the node-specific bits. Can't use node_invoke() @@ -145,7 +148,7 @@ public function form(array $form, array &$form_state, EntityInterface $node) { '#type' => 'textarea', '#title' => t('Revision log message'), '#rows' => 4, - '#default_value' => !empty($node->log) ? $node->log : '', + '#default_value' => !empty($translation->log->value) ? $translation->log->value : '', '#description' => t('Briefly describe the changes you have made.'), '#states' => array( 'visible' => array( @@ -212,13 +215,13 @@ public function form(array $form, array &$form_state, EntityInterface $node) { $form['options']['promote'] = array( '#type' => 'checkbox', '#title' => t('Promoted to front page'), - '#default_value' => $node->promote, + '#default_value' => $translation->promote->value, ); $form['options']['sticky'] = array( '#type' => 'checkbox', '#title' => t('Sticky at top of lists'), - '#default_value' => $node->sticky, + '#default_value' => $translation->sticky->value, ); // This form uses a button-level #submit handler for the form's main submit diff --git a/core/modules/node/lib/Drupal/node/NodeTranslationController.php b/core/modules/node/lib/Drupal/node/NodeTranslationController.php index a9e6b7c..d1f74c1 100644 --- a/core/modules/node/lib/Drupal/node/NodeTranslationController.php +++ b/core/modules/node/lib/Drupal/node/NodeTranslationController.php @@ -8,12 +8,12 @@ namespace Drupal\node; use Drupal\Core\Entity\EntityInterface; -use Drupal\translation_entity\EntityTranslationController; +use Drupal\translation_entity\EntityTranslationControllerNG; /** * Defines the translation controller class for nodes. */ -class NodeTranslationController extends EntityTranslationController { +class NodeTranslationController extends EntityTranslationControllerNG { /** * Overrides EntityTranslationController::getAccess(). diff --git a/core/modules/node/node.module b/core/modules/node/node.module index 0db8026..c84c769 100644 --- a/core/modules/node/node.module +++ b/core/modules/node/node.module @@ -1853,7 +1853,8 @@ function node_type_page_title($type) { * @see node_menu() */ function node_page_title(EntityInterface $node) { - return $node->label(); + $langcode = language(LANGUAGE_TYPE_CONTENT)->langcode; + return $node->label($langcode); } /** @@ -2212,7 +2213,8 @@ function node_page_view(EntityInterface $node) { // If there is a menu link to this node, the link becomes the last part // of the active trail, and the link name becomes the page title. // Thus, we must explicitly set the page title to be the node title. - drupal_set_title($node->label()); + $langcode = language(LANGUAGE_TYPE_CONTENT)->langcode; + drupal_set_title($node->label($langcode)); $uri = $node->uri(); // Set the node path as the canonical URL to prevent duplicate content. drupal_add_html_head_link(array('rel' => 'canonical', 'href' => url($uri['path'], $uri['options'])), TRUE); @@ -3161,13 +3163,14 @@ function node_content_form(EntityInterface $node, $form_state) { // hook_form(). Remove this requirement. $form = array(); $type = node_type_load($node->type); + $langcode = $form_state['controller']->getFormLangcode($form_state); if ($type->has_title) { $form['title'] = array( '#type' => 'textfield', '#title' => check_plain($type->title_label), '#required' => TRUE, - '#default_value' => $node->title, + '#default_value' => $node->label($langcode), '#maxlength' => 255, '#weight' => -5, ); diff --git a/core/modules/translation_entity/translation_entity.module b/core/modules/translation_entity/translation_entity.module index cb75cb2..6b24f48 100644 --- a/core/modules/translation_entity/translation_entity.module +++ b/core/modules/translation_entity/translation_entity.module @@ -124,6 +124,22 @@ function translation_entity_entity_bundle_info_alter(&$bundles) { } /** + * Implements hook_entity_field_info_alter(). + */ +function translation_entity_entity_field_info_alter(&$info, $entity_type) { + // TODO Make this configurable. + $entity_info = entity_get_info($entity_type); + if (isset($entity_info['data_table'])) { + $data_fields = array_flip($entity_info['schema_fields_sql']['data_table']); + foreach ($info['definitions'] as $name => &$definition) { + if (isset($data_fields[$name])) { + $definition['translatable'] = TRUE; + } + } + } +} + +/** * Implements hook_menu(). */ function translation_entity_menu() { diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewAddFormController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewAddFormController.php index 38a1099..66c3af3 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewAddFormController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewAddFormController.php @@ -20,7 +20,7 @@ class ViewAddFormController extends ViewFormControllerBase { /** * Overrides Drupal\Core\Entity\EntityFormController::prepareForm(). */ - protected function prepareEntity(EntityInterface $view) { + protected function prepareEntity(EntityInterface $view, array &$form_state) { // Do not prepare the entity while it is being added. } diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php index d78f89b..9735c63 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewCloneFormController.php @@ -17,7 +17,7 @@ class ViewCloneFormController extends ViewFormControllerBase { /** * Overrides \Drupal\Core\Entity\EntityFormController::prepareForm(). */ - protected function prepareEntity(EntityInterface $entity) { + protected function prepareEntity(EntityInterface $entity, array &$form_state) { // Do not prepare the entity while it is being added. } diff --git a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php index edeb3c0..b111ca9 100644 --- a/core/modules/views/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php +++ b/core/modules/views/views_ui/lib/Drupal/views_ui/ViewFormControllerBase.php @@ -41,7 +41,7 @@ public function build(array $form, array &$form_state, EntityInterface $entity) /** * Overrides Drupal\Core\Entity\EntityFormController::prepareForm(). */ - protected function prepareEntity(EntityInterface $view) { + protected function prepareEntity(EntityInterface $view, array &$form_state) { // Determine the displays available for editing. if ($tabs = $this->getDisplayTabs($view)) { // If a display isn't specified, use the first one.