Currently only ISO2 is available as property and I think we should expose more schema properties. I need to be able to search by country name with search API.

Probably continent name should be added too but it would need extra code in a dedicated property getter callback.

Patch attached.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pcambra’s picture

Status: Needs review » Needs work

From a chat with webflo on IRC:

"i had some problems in rules. the field does support setter callback atm. we need to remove the setter callback for all properties except for iso2"

pcambra’s picture

Additional feedback: "countries_entity_metadata_field_property_get needs update to. because is requires a cid. we should change this to iso2"

webflo’s picture

Since we dependent on Entity API and implemented all properties we dont need countries_entity_metadata_field_property_get anymore. I tested this patch with rules and some other code.

webflo’s picture

Status: Needs work » Needs review
pcambra’s picture

Status: Needs review » Needs work

Reviewing this, I've found that the properties are not working as supposed for the schema fields, working on that atm

pcambra’s picture

Status: Needs work » Needs review
FileSize
3.91 KB

A third approach for this, I've just discovered that we can just remove most of the custom code and rely in the wonderful entity_metadata_field_default_property_callback just the same way that entityreference and OG do (those are similar modules to countries in the sense of exposing a field based in an entity).

I've added something that is not in the schema database: Continent name, by using hook_entity_property_alter in a info.inc (standard) and including a countries_get_properties() function. Both things can be used for extending and changing our property integration with entity api when needed.

Status: Needs review » Needs work

The last submitted patch, 1458938-add_schema_columns_properties.patch, failed testing.

pcambra’s picture

Category: feature » task
Status: Needs work » Needs review
FileSize
3.85 KB

Oops, wrong rebase, again.

pcambra’s picture

Gave a second test of this, entity_metadata_field_default_property_callback is great but doesn't fit because of the option list, for getting i.e. a country selector exposed in views instead of a text search.

New version attached.

pcambra’s picture

Adding the info.inc file again

Alan D.’s picture

This is one of the two issues left that I would like to push into the latest 7.x-2.x branch. After the dust settles on these two new features, I would like to push out 7.x-2.0 tag. However, I can not really help test here as this is not my area of expertise.

For the new country icon formatter I wrote the function country_property(). This would be a better place for calculating the property info. The same logic was creeping into many different areas, so it made sense to combine these into one location.

+/**
+ * Callback for getting extra country properties.
+ *
+ * @see countries_entity_property_info_alter()
+ */
+function countries_get_properties($data = FALSE, array $options, $name) {
+  return country_property($data, $name);
+}

function country_property($country, $property, $default = NULL, $sanitize = TRUE) {
  $output = NULL;
  switch ($property) {
    case 'cid':
      return $country->cid;

    case 'enabled':
      return empty($country->enabled) ? t('Disabled') : t('Enabled');

    case 'continent_code':
      if (!empty($country->continent)) {
        $output = $country->continent;
      }
      break;

    case 'continent':
+    case 'continent_name':
      $continents = countries_get_continents();

Testers?

pcambra’s picture

Status: Needs review » Needs work

Setting to needs work.

Just to point out that due to the way that the entity and field are related (by iso2 instead of cid), search api integration is kind of broken, I'll try to get an update on this in the next days.

pcambra’s picture

Status: Needs work » Needs review
FileSize
3.93 KB

I think the iso2 thing is going to be fixed in search api itself but I think it would be worthy to consider transforming the relationship between countries field an the entity to use cid (integer) instead of a varchar.

New patch attached with an improved property callback (thanks to jsacksick) and the changes suggested in #11

I think that providing what exactly is expected to be tested will ease the creating the test task.

Alan D.’s picture

@pcambra
Do you think that this is ready for pushing into production? Happy with a manual review, but I not run manual tests. The automated testing does over 40% of the module, so all go there.

pcambra’s picture

That's why I'm asking if someone has a clear idea of what needs to be tested here, not sure if functional tests are expected in this module or it's just unit testing. All this patch does is improve entity api integration, which has its very own functional tests.

Alan D.’s picture

I have to admit, I don't have any!

I have been mainly focused on a massive multi-domain project for the last 5 months and the collection of tools (Entity API, Migrate, et al) was way too unstable at the start of the development cycle to use, so we have mainly used core functionality, although we are pushing this to its limits, like with dynamic domain specific view modes, overridden entity labels [entity labels are altered during entity load, query callbacks depending on the domain], field access, multiple ctools plugins, etc.

OK, so a long story short, I want to push out a release soon, as I just discovered that I was incorrectly using hook_hook_info(). This particular bug could cause significant issues if another module decides to share the same namespace, namely complete loss of functionality in the core country element, thus the continent country widget too.

With no new features really pending, this would be the last foreseen release till the next ISO update, which could be months off. With this in mind, I'll tag it as the first stable 2.x release (7.x-2.0).

So if either yourself or jsacksick think that this is ready for committing, and that you can not think of any unforeseen issues that may arise from this, then I'll happily push this out, giving it a couple of weeks in dev to see if any one experiences any issues, before the main release.

Alan D.’s picture

Since webflo has postponed #1397762: Entity cache integration, I'm going to do the same with this issue. As he put it, something for the next release :)

Since there are no other recent additions, I going to tag up 7.x-2.0 and release tonight.

Andrew Edwards’s picture

Here's a patch against the latest version of dev (7.x-2.1+5-dev).

Created because Alan suggested the patch against this issue might solve a problem I was having getting Countries to work with Search API. And it does!
#1704716: Expose the country name to search API

There seem to be two issues dealt with in this patch

1) adding the continent name property
2) the improved property callback

The 2nd is what helps with Search API integration
Some of the work for 1 (continent name property) seemed to already be in the latest dev, so I hope I haven't broken anything. Perhaps some of the code in this patch is no longer relevant?

Status: Needs review » Needs work

The last submitted patch, 1458938-add_schema_columns_properties-18.patch, failed testing.

Andrew Edwards’s picture

Alan D.’s picture

Status: Needs work » Needs review
ptmkenny’s picture

Marked https://drupal.org/node/1975712 as a duplicate. The patch in #20 allows me to set the value of the Countries field using Rules, which is a huge help.

Alan D.’s picture

Also marked #2028745: No direct input mode with rules and the countries field as a duplicate.

Anyone really pushed the limits using this patch with full Rules integration, View contextual filters, anything else that could hang off this functionality?

Alan D.’s picture

Title: Add schema columns properties » Add schema columns properties (tests)
Status: Needs review » Fixed

Committed to dev. Hopefully this should put this puppy to sleep.

Reopen if anyone has the time to write some tests...

Alan D.’s picture

Title: Add schema columns properties (tests) » Add schema columns properties

Automatically closed -- issue fixed for 2 weeks with no activity.