Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create content in language with field translation. #11

Merged
merged 3 commits into from
Feb 24, 2015

Conversation

dutchiexl
Copy link

You can add a language in the table hash

 | title        | News feature: News item 1 |
 | body         | This is a news item       |
 | field_date   | 2018-02-25 07:45:45       |
 | language     | en                        |

Every field that is translatable, will be set in this language

jhedstrom added a commit that referenced this pull request Feb 24, 2015
Create content in language with field translation.
@jhedstrom jhedstrom merged commit b53189a into jhedstrom:master Feb 24, 2015
@jhedstrom
Copy link
Owner

Awesome, thanks!

jhedstrom added a commit that referenced this pull request Feb 25, 2015
Create content in language with field translation.

Signed-off-by: Jonathan Hedstrom <[email protected]>
@ademarco
Copy link
Contributor

@jhedstrom @dutchiexl : I'm afraid the proposed solution breaks in Drupal 8 since \Drupal\Driver\Cores\AbstractCore is supposed to be Drupal core agnostic, so in there we cannot refer to Drupal 7 specifics like the LANGUAGE_NONE constant, which is not available in Drupal 8.

With current master branch of both drupal extension and drupal driver, when running D8 tests, I get:

...
@d8
  Scenario: Create many nodes                                  # features/api.feature:49
    Given "page" content:                                      # Drupal\DrupalExtension\Context\DrupalContext::createNodes()
      | title    |
      | Page one |
      | Page two |
      Notice: Use of undefined constant LANGUAGE_NONE - assumed 'LANGUAGE_NONE' in vendor/drupal/drupal-driver/src/Drupal/Driver/Cores/AbstractCore.php line 42
    And "article" content:       
...

@ademarco
Copy link
Contributor

We could actually add the $entity object to the field handler constructor, so we delegate all core specific logic the handler implementations, so from:

public function getFieldHandler($entity_type, $field_name, $language);

We would have:

public function getFieldHandler($entity, $entity_type, $field_name);

$this->field_info = field_info_field($field_name);
$this->language = field_is_translatable('node', $this->field_info) ? $language : LANGUAGE_NONE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Field handlers are actually supposed to work with all type of entities, so any specific entity type reference (i.w. 'node' in this case) should be removed, $entity_type should be used instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could actually use something similar to what core does for comments:

$langcode = field_is_translatable('comment', $field) ? entity_language('comment', $comment) : LANGUAGE_NONE;

So:

$langcode = field_is_translatable($entity_type, $this->field_info) ? entity_language($entity_type, $entity) : LANGUAGE_NONE;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, comments is where I got my mustard from. I can check out the entity_language if you like and refactor the update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants