Needs work
Project:
Countries
Version:
7.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
29 Jul 2012 at 18:25 UTC
Updated:
19 May 2015 at 07:16 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
alan d. commentedIt looks like you were testing 2 hours prior to #1609150: Support entity label (and callback) being pushed through. Without testing this, I think this will allow the Entity API understand the country entities label (aka, the country name) and use this when relevant, that should then show up in the Search API too. Well at least that's what should happen!
Can you let me know if this seemingly unrelated issue has resolved this? Thanks
Comment #2
alan d. commentedScrape that; you were testing in July 29, that fix was committed June 29.
Comment #3
Andrew Edwards commentedHello. I too would like to have country name exposed to Search API. At the moment, like Alan D, I see only 'Country » ISO2 country code'. I'm using 7.x-2.0+10-dev
Cheers!
Andrew
Comment #4
Anonymous (not verified) commentedLooking for the same thing.
I found that making a change in countries_field_info_property_callback() can expose all country fields.
Although there is a warning not to do it, if you comment out line 38, that changes $property['type'], the entity will be used to set which fields will be available, compared to just the iso2 field that is defined.
I realize the comment is there, but what was the reasoning for saying do not use the entity type? Are there issues that crop up elsewhere because of that? And if so, could more fields be added to the $property['property info'] array to expose more fields manually?
Comment #5
Andrew Edwards commentedI'm wondering if the issue has to do with iso2 (as opposed to cid) being used as the primary key in the table countries_country.
I used cid (wrongly I now realise) as a foreign key in a custom entity. As a result I can see all country fields when I index on my custom entity using search api.
Perhaps Search API does not recognise the 'name' key in hook_entity_info()?
Comment #6
Andrew Edwards commentedI've created a feature request in the search api issue queue to try and get the name key on hook_entity_info supported #1998924: Why does the Countries module not work with the Search API?.
Also see #1142536: How to integrate the countries module with the entity api for more details.
Comment #7
Andrew Edwards commentedAfter discussion with the module maintainer for Search API it looks like the problem isn't at that end.
#1998924: Why does the Countries module not work with the Search API?
As r_smylski pointed out it looks like the problem is with countries_field_info_property_callback(). I think that as a work around 'countries' has been used for $property['type'] instead of 'country' (the entity type). As a result when Search API tries to grab the properties for the country entity type it can't because it's looking for countries.
Could it be that the way the entity type and bundle for country is set up needs to be changed? It looks as though 'countries' has been used for $property['type'] because 'country' is used for both the entity type and the bundle ... and the code author didn't want to reference the entity type. All a bit confusing!
I tried changing property['type'] to 'country' and that works to an extent. Search API then picks up the properties. Unfortunately though the values for the properties were not indexed.
I'm going to change this issue to a bug report as it looks to me as though the way the entity type and bundle have been set up needs a bit of work to work with Search API.
I'd like to write a patch but, after a lot of head scratching, I don't understand the way things have been set up.
Cheers,
Andrew
Comment #8
Andrew Edwards commentedComment #9
alan d. commentedDoes #1458938: Add schema columns properties help?
As an aside, this seems to be wrong imho, but I have never really investigated but I think it is the root cause for a lot of issues.
From some reading done months back, I thought that this should be the entity type name
i.e.
Comment #10
Andrew Edwards commentedInteresting! Yes #1458938: Add schema columns properties does help. I've adjusted the patch on that issue to work with the latest dev and now Countries seems to be working with Search API. Excellent!
The code you mention:
has actually been removed in the patch, which seems a better approach to me.
I'll post a new patch on the other issue after I've done a bit more testing.
Comment #11
alan d. commentedTentatively marking a duplicate of #1458938: Add schema columns properties.
Reopen if this does not solve this issue.
Comment #13
stone_d commentedSorry to re-open this but ...
... this is still not working for me. I Get the ISO2-code-names as facets. I can't find a way to change the display name to the full located country name anywhere.
Are there any hints on this issue?
Thanks and best regards
Comment #14
alan d. commented@stone_d
Are you using the latest dev release? And does that have the patch from the other issues?
Comment #15
stone_d commentedHi Alan,
thanks for the quick reply! I actually run the latest dev release 7.x-2.1+24-dev with NO additional patchings.
I attached how my dropdown looks like in the country-facet of search-api.
Comment #16
alan d. commentedlatest dev has this... reopening :(
Comment #17
stone_d commentedWouldn't it be perfect to have an additional setting in the Facet-Display-Settings where u can choose how you want the country to be outputted and maybe also offer the custom fields of the country-entity to be selected for display? Then you could also use flags, or any image you like.
... just as an idea - for me the language-dependent country name would be totally enough!
Comment #18
stone_d commentedWithout stressing: Is there any progress on this?
I just wanna know since if not - i have to switch for another solution.
Thanks
Comment #19
alan d. commentedI don't use the search api, so personally can not test, debug, resolve....
If you want to try things, I can make suggestions.
a) Workaround: A form alter on that form and repopulate from the countries list (reloop through the options and set the values as the country label)
function aaa_form_bbbbbb_alter(&$form, $form_state) {
$enabled_countries = countries_get_countries('name', array('enabled' => COUNTRIES_ENABLED));
// This would nuke empty options potentially, depending on if the #empty_option is used or if part of the #options itself.
$form['xxx']['zzzz']['#options'] = array_intersect_keys($enabled_countries, $form['xxx']['zzzz']['#options']);
}
b) Fix internally
...??
Comment #20
johnvJust for inspiration: this is how the Workflow module solves this issue using hook_entity_property_info_alter().
But probably you need to use hook_field_info() or hook_field_info_alter().
https://api.drupal.org/api/drupal/modules%21field%21field.api.php/functi...
https://drupal.org/node/1156554
Comment #21
alan d. commentedYuks, we don't need to define something like this?
http://drupalcode.org/project/entity.git/blob/refs/heads/7.x-1.x:/module...
:?
Comment #22
muschpusch commentedHave at the patch and comments here: #1803930: Making Node Weight expose it's data to entity API I'm working on something similar for the weight module.
Comment #23
mrded commentedYou can also rewrite facet items with facetapi_bonus module.
Comment #24
stone_d commentedoh - well ... i gotta try this! Thanks!
Comment #25
ptmkenny commentedI'm not sure if I should open a new issue, but has anyone had success getting the country displayed in Views when indexed by search API? When I add the country as a field, I can choose from
* Show entity label
* Show entity ID
* Show complete entity (View modes: Country, Revision comparison, Tokens)
But none of these actually show me anything in my View. Any ideas would be much appreciated.
Comment #26
ptmkenny commentedOk, to get this in a View, I made a template. I wanted the country icon so I added this in the relevant template file:
For whatever reason, the views UI does not work as is, but the two-letter country code can be pulled in by template.
Comment #27
alan d. commentedYes, it is much better to open a new thread, but since you are here already...
Do you have the option to create a relationship from the Entity to the country (Addvanced > Relationships)? If so, then you get all of the field settings for free :)
If not, create a new issue and I will try and tack down a snippet of sample code that may work.