Currently, you can pass a country as an argument to a view, but you can't validate it. I'm actually not that concerned with "validation", but the nice thing about validating is that you can also set the view title to be the name of the country, rather than something more arcane like the iso2 code.

This patch provides that basic validator.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Alan D.’s picture

Any reason for this? i.e. parent::init() would be called without this anyways.

+  function init(&$view, &$argument, $options) {
+    parent::init($view, $argument, $options);
+  }

And this can be a tiny bit less verbose, and for i18n, country_property() is probably better (Defaults to the sanitized name property).

+  function validate_argument($arg) {
+    if ($country = country_load($arg)) {
+      $this->argument->validated_title = country_property($country);
+      return TRUE;
+    }
+    return FALSE;
+  }
Dane Powell’s picture

FileSize
2.76 KB

Thanks for the tips. I'd never created a validator or integrated with Countries before, hence the "verbose" code :)

Here's an update.

Alan D.’s picture

Looks rtbtc to me, I just need to find the time to actually test the code. Hopefully I'll get back in and clean up the queues again in the next month and so, where this should make it's way into the module!

webflo’s picture

The validation plugin should only valide. The conversion from iso2 code to name (or other properties) is done in views_handler_argument_countries_country.

webflo’s picture

FileSize
2.07 KB