Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
drupal
Commits
73c28090
Commit
73c28090
authored
Feb 07, 2010
by
Angie Byron
Browse files
#668386
by yched: Handle unavailable entity types or bundles.
parent
3729441a
Changes
3
Hide whitespace changes
Inline
Side-by-side
includes/common.inc
View file @
73c28090
...
...
@@ -6396,7 +6396,12 @@ function entity_get_info($entity_type = NULL) {
}
}
return empty($entity_type) ? $entity_info : $entity_info[$entity_type];
if (empty($entity_type)) {
return $entity_info;
}
elseif (isset($entity_info[$entity_type])) {
return $entity_info[$entity_type];
}
}
/**
...
...
modules/field/field.crud.inc
View file @
73c28090
...
...
@@ -823,6 +823,9 @@ function field_read_instance($obj_type, $field_name, $bundle, $include_additiona
* An array of instances matching the arguments.
*/
function
field_read_instances
(
$params
=
array
(),
$include_additional
=
array
())
{
$include_inactive
=
isset
(
$include_additional
[
'include_inactive'
])
&&
$include_additional
[
'include_inactive'
];
$include_deleted
=
isset
(
$include_additional
[
'include_deleted'
])
&&
$include_additional
[
'include_deleted'
];
$query
=
db_select
(
'field_config_instance'
,
'fci'
,
array
(
'fetch'
=>
PDO
::
FETCH_ASSOC
));
$query
->
join
(
'field_config'
,
'fc'
,
'fc.id = fci.field_id'
);
$query
->
fields
(
'fci'
);
...
...
@@ -831,12 +834,12 @@ function field_read_instances($params = array(), $include_additional = array())
foreach
(
$params
as
$key
=>
$value
)
{
$query
->
condition
(
'fci.'
.
$key
,
$value
);
}
if
(
!
isset
(
$include_
additional
[
'include_inactive'
])
||
!
$include_additional
[
'include_inactive'
]
)
{
if
(
!
$include_
inactive
)
{
$query
->
condition
(
'fc.active'
,
1
)
->
condition
(
'fc.storage_active'
,
1
);
}
if
(
!
isset
(
$include_
additional
[
'include_deleted'
])
||
!
$include_additional
[
'include_deleted'
]
)
{
if
(
!
$include_
deleted
)
{
$query
->
condition
(
'fc.deleted'
,
0
);
$query
->
condition
(
'fci.deleted'
,
0
);
}
...
...
@@ -845,16 +848,21 @@ function field_read_instances($params = array(), $include_additional = array())
$results
=
$query
->
execute
();
foreach
(
$results
as
$record
)
{
$instance
=
unserialize
(
$record
[
'data'
]);
$instance
[
'id'
]
=
$record
[
'id'
];
$instance
[
'field_id'
]
=
$record
[
'field_id'
];
$instance
[
'field_name'
]
=
$record
[
'field_name'
];
$instance
[
'object_type'
]
=
$record
[
'object_type'
];
$instance
[
'bundle'
]
=
$record
[
'bundle'
];
$instance
[
'deleted'
]
=
$record
[
'deleted'
];
module_invoke_all
(
'field_read_instance'
,
$instance
);
$instances
[]
=
$instance
;
// Filter out instances on unknown object types (for instance because the
// module exposing them was disabled).
$entity_info
=
entity_get_info
(
$record
[
'object_type'
]);
if
(
$include_inactive
||
$entity_info
)
{
$instance
=
unserialize
(
$record
[
'data'
]);
$instance
[
'id'
]
=
$record
[
'id'
];
$instance
[
'field_id'
]
=
$record
[
'field_id'
];
$instance
[
'field_name'
]
=
$record
[
'field_name'
];
$instance
[
'object_type'
]
=
$record
[
'object_type'
];
$instance
[
'bundle'
]
=
$record
[
'bundle'
];
$instance
[
'deleted'
]
=
$record
[
'deleted'
];
module_invoke_all
(
'field_read_instance'
,
$instance
);
$instances
[]
=
$instance
;
}
}
return
$instances
;
}
...
...
modules/field/tests/field.test
View file @
73c28090
...
...
@@ -1347,6 +1347,29 @@ class FieldInfoTestCase extends FieldTestCase {
}
}
/**
* Test that instances on disabled object types are filtered out.
*/
function testInstanceDisabledObjectType() {
// For this test the field type and the object type must be exposed by
// different modules.
$field_definition = array(
'field_name' => 'field',
'type' => 'test_field',
);
field_create_field($field_definition);
$instance_definition = array(
'field_name' => 'field',
'object_type' => 'comment',
'bundle' => 'comment_node_article',
);
field_create_instance($instance_definition);
// Disable coment module. This clears field_info cache.
module_disable(array('comment'));
$this->assertNull(field_info_instance('comment', 'field', 'comment_node_article'), t('No instances are returned on disabled object types.'));
}
/**
* Test that the field_info settings convenience functions work.
*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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