Download & Extend

Location views plugin for province validation

Project:Location
Version:6.x-3.x-dev
Component:Location_views
Category:feature request
Priority:normal
Assigned:Unassigned
Status:reviewed & tested by the community

Issue Summary

The attached patch adds a views plugin for argument validation for provinces. It works now, but only for the US...it would probably be beneficial to add a form that allowed a user to pick countries to validate against.

AttachmentSize
location.views_.patch1.71 KB

Comments

#1

Hi, This would be great to have for the selected country and not only for the US, would that be possible please?
Thanks a lot in advance for considering.
greetings,
Martijn

#2

<?php
// $Id$

/**
* @file
* Views plugin to validate province arguments for the location
* module.
*/
class views_plugin_argument_validate_province extends views_plugin_argument_validate {

  function
validate_argument($argument) {
    if (isset(
$this->view->argument['country'])) {
     
$country = $this->view->argument['country']->argument;
    } else {
     
$country = variable_get('location_default_country', 'us');
    }
   
// Validate that province exists.
   
$provinces = location_get_provinces($country);
    if (
$argument) {
      if (!
in_array(strtoupper($argument), array_keys($provinces)) && !in_array($argument, array_values($provinces))) {
        return
FALSE;
      }
    }
    return
TRUE;
  }

}
?>

Add this to your views_plugin_argument_validate_province.inc

#3

Status:needs review» reviewed & tested by the community