Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
drupal.org
field_collection
Commits
89dcbb25
Commit
89dcbb25
authored
Mar 29, 2019
by
Ra Mänd
Browse files
Fix nested positive ifs.
parent
7ca870e7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
32 deletions
+27
-32
field_collection.entity.inc
field_collection.entity.inc
+7
-8
field_collection.module
field_collection.module
+15
-18
field_collection.test
field_collection.test
+5
-6
No files found.
field_collection.entity.inc
View file @
89dcbb25
...
...
@@ -526,14 +526,13 @@ class FieldCollectionItemEntity extends Entity {
foreach
(
$fields_instances
as
$translatable_field
)
{
if
(
$fields
[
$translatable_field
][
'translatable'
]
==
1
)
{
foreach
(
$target_languages
as
$langcode
)
{
if
(
isset
(
$this
->
{
$translatable_field
}[
$source_language
]))
{
// Source (translatable_field) is set, therefore continue
// processing.
if
(
!
isset
(
$this
->
{
$translatable_field
}[
$langcode
]))
{
// Destination (translatable_field) is not set, therefore safe to
// copy the translation.
$this
->
{
$translatable_field
}[
$langcode
]
=
$this
->
{
$translatable_field
}[
$source_language
];
}
// Source (translatable_field) is set, therefore continue
// processing.
if
(
isset
(
$this
->
{
$translatable_field
}[
$source_language
])
&&
!
isset
(
$this
->
{
$translatable_field
}[
$langcode
]))
{
// Destination (translatable_field) is not set, therefore safe to
// copy the translation.
$this
->
{
$translatable_field
}[
$langcode
]
=
$this
->
{
$translatable_field
}[
$source_language
];
}
}
if
(
$source_language
==
LANGUAGE_NONE
&&
count
(
$this
->
{
$translatable_field
})
>
1
)
{
...
...
field_collection.module
View file @
89dcbb25
...
...
@@ -707,10 +707,9 @@ function field_collection_field_load($entity_type, $entities, $field, $instances
*/
function
field_collection_field_delete_revision
(
$entity_type
,
$entity
,
$field
,
$instance
,
$langcode
,
&
$items
)
{
foreach
(
$items
as
$item
)
{
if
(
!
empty
(
$item
[
'revision_id'
]))
{
if
(
$entity
=
field_collection_item_revision_load
(
$item
[
'revision_id'
]))
{
$entity
->
deleteRevision
(
TRUE
);
}
if
(
!
empty
(
$item
[
'revision_id'
])
&&
$entity
=
field_collection_item_revision_load
(
$item
[
'revision_id'
]))
{
$entity
->
deleteRevision
(
TRUE
);
}
}
}
...
...
@@ -2070,20 +2069,18 @@ function field_collection_entity_translation_insert($entity_type, $entity, $tran
if
(
!
empty
(
$value
[
$language
]))
{
$source_items
=
!
empty
(
$entity
->
{
$field_name
}[
$source_language
])
?
field_collection_field_item_to_ids
(
$entity
->
{
$field_name
}[
$source_language
])
:
array
();
foreach
(
$value
[
$language
]
as
$delta
=>
$field_value
)
{
if
(
!
isset
(
$field_value
[
'entity'
]))
{
if
(
$fc_entity
=
field_collection_field_get_entity
(
$field_value
))
{
// Check if this field collection item belongs to the source language
if
(
in_array
(
$fc_entity
->
item_id
,
$source_items
))
{
// Clone the field collection item
$new_fc_entity
=
clone
$fc_entity
;
$new_fc_entity
->
item_id
=
NULL
;
$new_fc_entity
->
revision_id
=
NULL
;
$new_fc_entity
->
is_new
=
TRUE
;
// Set the new entity for saving it later
$entity
->
{
$field_name
}[
$language
][
$delta
][
'entity'
]
=
$new_fc_entity
;
}
}
// Check if this field collection item belongs to the source language
if
(
!
isset
(
$field_value
[
'entity'
])
&&
(
$fc_entity
=
field_collection_field_get_entity
(
$field_value
))
&&
in_array
(
$fc_entity
->
item_id
,
$source_items
))
{
// Clone the field collection item
$new_fc_entity
=
clone
$fc_entity
;
$new_fc_entity
->
item_id
=
NULL
;
$new_fc_entity
->
revision_id
=
NULL
;
$new_fc_entity
->
is_new
=
TRUE
;
// Set the new entity for saving it later
$entity
->
{
$field_name
}[
$language
][
$delta
][
'entity'
]
=
$new_fc_entity
;
}
}
}
...
...
field_collection.test
View file @
89dcbb25
...
...
@@ -1013,12 +1013,11 @@ class FieldCollectionEntityTranslationTestCase extends DrupalWebTestCase {
$field
=
field_info_field
(
$field_name
);
$field_value
=
array
();
// Copy the value of the translated field if it's translatable.
if
(
$field
[
'translatable'
])
{
if
(
isset
(
$node
->
{
$field_name
}[
$node
->
language
]))
{
$field_value
=
$node
->
{
$field_name
}[
$source_langcode
];
$values
[
$field_name
][
$langcode
]
=
$field_value
;
$node
->
{
$field_name
}[
$langcode
]
=
$field_value
;
}
if
(
$field
[
'translatable'
]
&&
isset
(
$node
->
{
$field_name
}[
$node
->
language
]))
{
$field_value
=
$node
->
{
$field_name
}[
$source_langcode
];
$values
[
$field_name
][
$langcode
]
=
$field_value
;
$node
->
{
$field_name
}[
$langcode
]
=
$field_value
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment