Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: MCP Sentinel 2.28.2 — Minor update available for module mcp_sentinel (2.28.2). Release: Rightup theme 1.0.2 — Minor update available for theme vartheme_bs5_rightup (1.0.2). Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage. Module Revived: Liquid Voting 2.0.1 — Module liquid_voting updated after 6 months of inactivity (2.0.1).

Zipcodebase

No security coverage
View on drupal.org

This module integrates Drupal with https://zipcodebase.com/. Zipcodebase is a third-party service that will allow you free access to Worldwide Postal Code Data.

As per the Zipcodebase website:

Zipcodebase.com is the perfect tool to perform postal code validation, lookups and other calculative tasks, such as postal code distance calculations. Zipcodebase offers a wide range of endpoints that give you access to any type of data you might need.

Read the zipcodebase documentation for more detail.

This is a simple wrapper for the Zipcodebase API. This module exposes a Drupal service that can be used to query the API.

Dependencies

This module uses the msankhala/zipcodebase-php composer package.

Installation

composer require drupal/zipcodebase

Uses

This module doesn't provide any functionality on its own. It is meant to be used by other modules.

See available methods that can be called on zipcodebase client.

Example: Using the ZipCodeBaseService in a controller

<?php

namespace Drupal\zipcodebase\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\zipcodebase\ZipCodeBaseService;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 * Class TestController controller.
 */
class TestController extends ControllerBase {

  /**
   * Logger factory.
   *
   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
   */
  protected $loggerFactory;

  /**
   * The ZipCodeBaseService.
   *
   * @var \Drupal\zipcodebase\ZipCodeBaseService
   */
  protected $zipCodeBaseService;

  /**
   * TestController constructor.
   *
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory
   *   The logger factory.
   * @param \Drupal\zipcodebase\ZipCodeBaseService $zipCodeBaseService
   *   The ZipCodeBaseService.
   */
  public function __construct(LoggerChannelFactoryInterface $loggerFactory, ZipCodeBaseService $zipCodeBaseService) {
    $this->loggerFactory = $loggerFactory;
    $this->zipCodeBaseService = $zipCodeBaseService;
  }

  /**
   * {@inheritdoc}
   *
   * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
   *   The Drupal service container.
   *
   * @return static
   */
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('logger.factory'),
      $container->get('zipcodebase.zipcodebase')
    );
  }

  /**
   * Test.
   *
   * @return string
   *   Return Hello string.
   */
  public function test() {
    $this->loggerFactory->get('zipcodebase')->notice('TestController::test() called');
    $zipCodeBaseClient = $this->zipCodeBaseService->getClient();
    $credits = $zipCodeBaseClient->getCredits();
    return [
      '#type' => 'markup',
      '#markup' => "Credits: " . print_r($credits, TRUE),
    ];
  }

}

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
May 2023
Latest release
3 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
1.0.0 Stable May 19, 2023
1.0.x-dev Dev May 18, 2023