Skip to content

Commit 74bb2a3

Browse files
ceastwoodbojanz
ceastwood
authored andcommitted
Issue #1468658 by bojanz, drclaw: 'Modify entity values' stores field data using the wrong langcode.
1 parent f792ef3 commit 74bb2a3

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

Diff for: actions/modify.action.inc

+15-8
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,19 @@ function views_bulk_operations_modify_action_info() {
2929
*/
3030
function views_bulk_operations_modify_action($entity, $context) {
3131
list(,,$bundle_name) = entity_extract_ids($context['entity_type'], $entity);
32-
3332
// Handle Field API fields.
3433
if (!empty($context['selected']['bundle_' . $bundle_name])) {
3534
// The pseudo entity is cloned so that changes to it don't get carried
3635
// over to the next execution.
3736
$pseudo_entity = clone $context['entities'][$bundle_name];
3837
foreach ($context['selected']['bundle_' . $bundle_name] as $key) {
38+
// Get this field's language. We can just pull it from the pseudo entity
39+
// as it was created using field_attach_form and entity_language so it's
40+
// already been figured out if this field is translatable or not and
41+
// applied the appropriate language code to the field
42+
$language = key($pseudo_entity->{$key});
3943
// Replace any tokens that might exist in the field columns.
40-
foreach ($pseudo_entity->{$key}[LANGUAGE_NONE] as $delta => &$item) {
44+
foreach ($pseudo_entity->{$key}[$language] as $delta => &$item) {
4145
foreach ($item as $column => $value) {
4246
if (is_string($value)) {
4347
$item[$column] = token_replace($value, array($context['entity_type'] => $entity), array('sanitize' => FALSE));
@@ -46,11 +50,11 @@ function views_bulk_operations_modify_action($entity, $context) {
4650
}
4751

4852
if (in_array($key, $context['append']['bundle_' . $bundle_name]) && !empty($entity->$key)) {
49-
$entity->{$key}[LANGUAGE_NONE] = array_merge($entity->{$key}[LANGUAGE_NONE], $pseudo_entity->{$key}[LANGUAGE_NONE]);
53+
$entity->{$key}[$language] = array_merge($entity->{$key}[$language], $pseudo_entity->{$key}[$language]);
5054

5155
// Check if we breached cardinality, and notify the user.
5256
$field_info = field_info_field($key);
53-
$field_count = count($entity->{$key}[LANGUAGE_NONE]);
57+
$field_count = count($entity->{$key}[$language]);
5458
if ($field_info['cardinality'] != FIELD_CARDINALITY_UNLIMITED && $field_count > $field_info['cardinality']) {
5559
$entity_label = entity_label($context['entity_type'], $entity);
5660
$warning = t('Tried to set !field_count values for field !field_name that supports a maximum of !cardinality.',
@@ -61,7 +65,7 @@ function views_bulk_operations_modify_action($entity, $context) {
6165
}
6266
}
6367
else {
64-
$entity->$key = $pseudo_entity->$key;
68+
$entity->{$key}[$language] = $pseudo_entity->{$key}[$language];
6569
}
6670
}
6771
}
@@ -175,13 +179,16 @@ function views_bulk_operations_modify_action_form($context, &$form_state) {
175179
}
176180
}
177181

182+
// Going to need this for multilingual nodes
183+
global $language;
178184
foreach ($bundles as $bundle_name => $bundle) {
179185
$bundle_key = $info['entity keys']['bundle'];
180186
$default_values = array();
181187
// If the bundle key exists, it must always be set on an entity.
182188
if (!empty($bundle_key)) {
183189
$default_values[$bundle_key] = $bundle_name;
184190
}
191+
$default_values['language'] = $language->language;
185192
$entity = entity_create($context['entity_type'], $default_values);
186193
$form_state['entities'][$bundle_name] = $entity;
187194

@@ -200,7 +207,7 @@ function views_bulk_operations_modify_action_form($context, &$form_state) {
200207
'#title' => $label,
201208
'#parents' => array($form_key),
202209
);
203-
field_attach_form($context['entity_type'], $entity, $form[$form_key], $form_state, LANGUAGE_NONE);
210+
field_attach_form($context['entity_type'], $entity, $form[$form_key], $form_state, entity_language($context['entity_type'], $entity));
204211
// Now that all the widgets have been added, sort them by #weight.
205212
// This ensures that they will stay in the correct order when they get
206213
// assigned new weights.
@@ -212,8 +219,8 @@ function views_bulk_operations_modify_action_form($context, &$form_state) {
212219
foreach (element_get_visible_children($form[$form_key]) as $field_name) {
213220
// For our use case it makes no sense for any field widget to be required.
214221
if (isset($form[$form_key][$field_name]['#language'])) {
215-
$language = $form[$form_key][$field_name]['#language'];
216-
_views_bulk_operations_modify_action_unset_required($form[$form_key][$field_name][$language]);
222+
$field_language = $form[$form_key][$field_name]['#language'];
223+
_views_bulk_operations_modify_action_unset_required($form[$form_key][$field_name][$field_language]);
217224
}
218225

219226
// The admin has specified which fields to display, but this field didn't

0 commit comments

Comments
 (0)