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
ebe72902
Commit
ebe72902
authored
Mar 29, 2019
by
Ra Mänd
Browse files
Remove redundant 'else' conditions.
parent
2cfd57dc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
35 deletions
+39
-35
field_collection.entity.inc
field_collection.entity.inc
+27
-25
field_collection.migrate.inc
field_collection.migrate.inc
+4
-4
field_collection.module
field_collection.module
+8
-6
No files found.
field_collection.entity.inc
View file @
ebe72902
...
...
@@ -145,7 +145,8 @@ class FieldCollectionItemEntity extends Entity {
if
(
$new_label
=
module_invoke_all
(
'field_collection_item_label'
,
$this
,
$host
,
$field
,
$label
))
{
return
array_pop
(
$new_label
);
}
elseif
(
$field
[
'cardinality'
]
==
1
)
{
if
(
$field
[
'cardinality'
]
==
1
)
{
return
$label
;
}
elseif
(
$this
->
item_id
)
{
...
...
@@ -369,7 +370,8 @@ class FieldCollectionItemEntity extends Entity {
$this
->
langcode
=
$langcode
;
return
$delta
;
}
elseif
(
isset
(
$item
[
'entity'
])
&&
$item
[
'entity'
]
===
$this
)
{
if
(
isset
(
$item
[
'entity'
])
&&
$item
[
'entity'
]
===
$this
)
{
$this
->
langcode
=
$langcode
;
return
$delta
;
}
...
...
@@ -386,7 +388,8 @@ class FieldCollectionItemEntity extends Entity {
$this
->
langcode
=
$langcode
;
return
$delta
;
}
elseif
(
isset
(
$item
[
'entity'
])
&&
$item
[
'entity'
]
===
$this
)
{
if
(
isset
(
$item
[
'entity'
])
&&
$item
[
'entity'
]
===
$this
)
{
$this
->
langcode
=
$langcode
;
return
$delta
;
}
...
...
@@ -462,30 +465,29 @@ class FieldCollectionItemEntity extends Entity {
if
(
$skip_host_save
)
{
return
entity_get_controller
(
$this
->
entityType
)
->
save
(
$this
);
}
else
{
$host_entity
=
$this
->
hostEntity
();
if
(
!
$host_entity
)
{
throw
new
Exception
(
'Unable to save a field collection item without a valid reference to a host entity.'
);
}
// If this is creating a new revision, also do so for the host entity.
if
(
!
empty
(
$this
->
revision
)
||
!
empty
(
$this
->
is_new_revision
))
{
$host_entity
->
revision
=
TRUE
;
if
(
!
empty
(
$this
->
default_revision
))
{
entity_revision_set_default
(
$this
->
hostEntityType
,
$host_entity
);
}
}
// Set the host entity reference, so the item will be saved with the host.
// @see field_collection_field_presave()
$delta
=
$this
->
delta
();
if
(
isset
(
$delta
))
{
$host_entity
->
{
$this
->
field_name
}[
$this
->
langcode
()][
$delta
]
=
array
(
'entity'
=>
$this
);
}
else
{
$host_entity
->
{
$this
->
field_name
}[
$this
->
langcode
()][]
=
array
(
'entity'
=>
$this
);
}
return
entity_save
(
$this
->
hostEntityType
,
$host_entity
);
$host_entity
=
$this
->
hostEntity
();
if
(
!
$host_entity
)
{
throw
new
Exception
(
'Unable to save a field collection item without a valid reference to a host entity.'
);
}
// If this is creating a new revision, also do so for the host entity.
if
(
!
empty
(
$this
->
revision
)
||
!
empty
(
$this
->
is_new_revision
))
{
$host_entity
->
revision
=
TRUE
;
if
(
!
empty
(
$this
->
default_revision
))
{
entity_revision_set_default
(
$this
->
hostEntityType
,
$host_entity
);
}
}
// Set the host entity reference, so the item will be saved with the host.
// @see field_collection_field_presave()
$delta
=
$this
->
delta
();
if
(
isset
(
$delta
))
{
$host_entity
->
{
$this
->
field_name
}[
$this
->
langcode
()][
$delta
]
=
array
(
'entity'
=>
$this
);
}
else
{
$host_entity
->
{
$this
->
field_name
}[
$this
->
langcode
()][]
=
array
(
'entity'
=>
$this
);
}
return
entity_save
(
$this
->
hostEntityType
,
$host_entity
);
}
/**
...
...
field_collection.migrate.inc
View file @
ebe72902
...
...
@@ -139,7 +139,8 @@ class MigrateDestinationFieldCollection extends MigrateDestinationEntity {
if
(
'field_'
!=
substr
(
$field
,
0
,
6
))
{
continue
;
}
elseif
(
property_exists
(
$entity_old
,
$field
)
&&
!
property_exists
(
$collection
,
$field
))
{
if
(
property_exists
(
$entity_old
,
$field
)
&&
!
property_exists
(
$collection
,
$field
))
{
$entity
->
$field
=
$entity_old
->
$field
;
}
}
...
...
@@ -159,9 +160,8 @@ class MigrateDestinationFieldCollection extends MigrateDestinationEntity {
}
return
array
(
$entity
->
item_id
);
}
else
{
return
FALSE
;
}
return
FALSE
;
}
/**
...
...
field_collection.module
View file @
ebe72902
...
...
@@ -734,7 +734,8 @@ function field_collection_field_is_empty($item, $field) {
if
(
!
empty
(
$item
[
'value'
]))
{
return
FALSE
;
}
elseif
(
isset
(
$item
[
'entity'
]))
{
if
(
isset
(
$item
[
'entity'
]))
{
return
field_collection_item_is_empty
(
$item
[
'entity'
]);
}
return
TRUE
;
...
...
@@ -1213,7 +1214,8 @@ function field_collection_field_widget_form(&$form, &$form_state, $field, $insta
$recursion
--
;
return
FALSE
;
}
elseif
(
field_collection_hide_blank_items
(
$field
)
&&
$field_state
[
'items_count'
]
==
0
)
{
if
(
field_collection_hide_blank_items
(
$field
)
&&
$field_state
[
'items_count'
]
==
0
)
{
// We show one item, so also specify that as item count. So when the
// add button is pressed the item count will be 2 and we show two items.
$field_state
[
'items_count'
]
=
1
;
...
...
@@ -1557,7 +1559,8 @@ function field_collection_field_get_entity(&$item, $field_name = NULL) {
}
return
$item
[
'entity'
];
}
elseif
(
isset
(
$item
[
'value'
]))
{
if
(
isset
(
$item
[
'value'
]))
{
// By default always load the default revision, so caches get used.
$entity
=
field_collection_item_load
(
$item
[
'value'
]);
if
(
$entity
&&
$entity
->
revision_id
!=
$item
[
'revision_id'
])
{
...
...
@@ -1962,9 +1965,8 @@ function field_collection_devel_generate($object, $field, $instance, $bundle) {
if
(
field_behaviors_widget
(
'multiple values'
,
$instance
)
==
FIELD_BEHAVIOR_CUSTOM
)
{
return
devel_generate_multiple
(
'_field_collection_devel_generate'
,
$object
,
$field
,
$instance
,
$bundle
);
}
else
{
return
_field_collection_devel_generate
(
$object
,
$field
,
$instance
,
$bundle
);
}
return
_field_collection_devel_generate
(
$object
,
$field
,
$instance
,
$bundle
);
}
function
_field_collection_devel_generate
(
$object
,
$field
,
$instance
,
$bundle
)
{
...
...
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