API page: http://api.drupal.org/api/drupal/modules%21field%21field.crud.inc/functi...
Problem
In the documentation for field_read_fields, the first Parameter $params says the following:
array $params: An array of conditions to match against. Keys are columns from the 'field_config' table, values are conditions to match. Additionally, conditions on the 'entity_type' and 'bundle' columns from the 'field_config_instance' table are supported (select fields having an instance on a given bundle).
When I pass columns from the 'field_config_instance' table as conditions, I get an error.
Consider the following example:
<?php
$p = array("module"=> "image", "storage_type"=> "field_sql_storage", "entity_type"=> "node");
$pa = array("include_deleted"=> TRUE);
$f = field_read_fields($p);
?>
When executed, the code above generates an Exception.
Steps To Reproduce
Actual Behaviour
To reproduce, execute the following drush command at the command-line, containing an 'entity_type' condition:
# drush eval '$p=array("module" => "image", "storage_type" => "field_sql_storage", "entity_type" => "node"); $pa=array("include_deleted" => TRUE); $f=field_read_fields($p); if (is_array($f)) var_dump(array_keys($f));'
The result is as follows:
WD php: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column [error]
'entity_type' in 'where clause': SELECT fc.*
FROM
{field_config} fc
WHERE (module = :db_condition_placeholder_0) AND (storage_type =
:db_condition_placeholder_1) AND (entity_type = :db_condition_placeholder_2) AND
(fc.active = :db_condition_placeholder_3) AND (fc.storage_active =
:db_condition_placeholder_4) AND (fc.deleted = :db_condition_placeholder_5) ; Array
(
[:db_condition_placeholder_0] => image
[:db_condition_placeholder_1] => field_sql_storage
[:db_condition_placeholder_2] => node
[:db_condition_placeholder_3] => 1
[:db_condition_placeholder_4] => 1
[:db_condition_placeholder_5] => 0
)
in field_read_fields() (line 353 of
/mnt/apachedata/www/vhosts/drupalvm/modules/field/field.crud.inc).
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'entity_type' in 'where clause': SELECT fc.*
FROM
{field_config} fc
WHERE (module = :db_condition_placeholder_0) AND (storage_type = :db_condition_placeholder_1) AND (entity_type = :db_condition_placeholder_2) AND (fc.active = :db_condition_placeholder_3) AND (fc.storage_active = :db_condition_placeholder_4) AND (fc.deleted = :db_condition_placeholder_5) ; Array
(
[:db_condition_placeholder_0] => image
[:db_condition_placeholder_1] => field_sql_storage
[:db_condition_placeholder_2] => node
[:db_condition_placeholder_3] => 1
[:db_condition_placeholder_4] => 1
[:db_condition_placeholder_5] => 0
)
in field_read_fields() (line 353 of /mnt/apachedata/www/vhosts/drupalvm/modules/field/field.crud.inc).
Change this instead to a 'bundle' condition by executing the following drush command at the command-line:
# drush eval '$p=array("module" => "image", "storage_type" => "field_sql_storage", "bundle" => "page"); $pa=array("include_deleted" => TRUE); $f=field_read_fields($p); if (is_array($f)) var_dump(array_keys($f));'
The result is as follows:
WD php: PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column [error]
'bundle' in 'where clause': SELECT fc.*
FROM
{field_config} fc
WHERE (module = :db_condition_placeholder_0) AND (storage_type =
:db_condition_placeholder_1) AND (bundle = :db_condition_placeholder_2) AND
(fc.active = :db_condition_placeholder_3) AND (fc.storage_active =
:db_condition_placeholder_4) AND (fc.deleted = :db_condition_placeholder_5) ; Array
(
[:db_condition_placeholder_0] => image
[:db_condition_placeholder_1] => field_sql_storage
[:db_condition_placeholder_2] => page
[:db_condition_placeholder_3] => 1
[:db_condition_placeholder_4] => 1
[:db_condition_placeholder_5] => 0
)
in field_read_fields() (line 353 of
/mnt/apachedata/www/vhosts/drupalvm/modules/field/field.crud.inc).
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bundle' in 'where clause': SELECT fc.*
FROM
{field_config} fc
WHERE (module = :db_condition_placeholder_0) AND (storage_type = :db_condition_placeholder_1) AND (bundle = :db_condition_placeholder_2) AND (fc.active = :db_condition_placeholder_3) AND (fc.storage_active = :db_condition_placeholder_4) AND (fc.deleted = :db_condition_placeholder_5) ; Array
(
[:db_condition_placeholder_0] => image
[:db_condition_placeholder_1] => field_sql_storage
[:db_condition_placeholder_2] => page
[:db_condition_placeholder_3] => 1
[:db_condition_placeholder_4] => 1
[:db_condition_placeholder_5] => 0
)
in field_read_fields() (line 353 of /mnt/apachedata/www/vhosts/drupalvm/modules/field/field.crud.inc).
Expected Behaviour
When you remove the "entity_type" condition from the parameter $params, it works. Execute the following drush command at the command-line to reproduce:
drush eval '$p=array("module" => "image", "storage_type" => "field_sql_storage"); $pa=array("include_deleted" => TRUE); $f=field_read_fields($p); if (is_array($f)) var_dump(array_keys($f));'
The result, when run on a Drupal site, should resemble the following:
array(5) {
[0] =>
string(17) "field_style_image"
[1] =>
string(16) "field_page_image"
[2] =>
string(16) "field_blog_image"
[3] =>
string(16) "field_image_logo"
[4] =>
string(11) "field_image"
}
Suggested Solution
Remove the sentence from the Parameters description for $params
like this:
array $params: An array of conditions to match against. Keys are columns from the 'field_config' table, values are conditions to match.
Additionally, conditions on the 'entity_type' and 'bundle' columns from the 'field_config_instance' table are supported (select fields having an instance on a given bundle).
Else, fix the implementation of this method so that the columns from the 'field_config_instance' table are supported as conditions in the $params
array.