dependent_country_state-1.0.6/dependent_country_state.module
dependent_country_state.module
<?php
use Drupal\Core\Database\Database;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Url;
/**
* @file
* Primary module hooks for Dependent Country State Module.
*/
function dependent_country_state_install() {
$conn = Database::getConnection();
$default_config = \Drupal::config('dependent_country_state.settings');
$country_details = $default_config->get('country_details');
if(!empty($country_details)) {
$conn = $conn->insert('dependent_country')->fields(['country_name', 'country_code','created']);
foreach ($country_details as $key => $value) {
if(!empty($value['name'])) {
$conn = $conn->values([$value['name'], $value['code'], \Drupal::time()->getRequestTime()]);
}
}
$conn->execute();
}
$states = $default_config->get('state');
if(!empty($states)) {
$conn = Database::getConnection();
$conn = $conn->insert('dependent_state')
->fields(['countryId','state_name','created']);
foreach ($states as $key => $value) {
if(!empty($value)) {
$conn = $conn->values([103, $value, \Drupal::time()->getRequestTime()]);
}
}
$conn->execute();
}
}
function dependent_country_state_uninstall(){
\Drupal::database()->schema()->dropTable('dependent_country');
\Drupal::database()->schema()->dropTable('dependent_state');
\Drupal::database()->schema()->dropTable('dependent_city');
\Drupal::database()->schema()->dropTable('dependent_pincode');
}
/**
* Implements hook_help().
*/
function dependent_country_state_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the dependent_country_state module.
case 'help.page.dependent_country_state':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The Dependent Country, State, City and Pincode module provides a feature to add/edit/delete these all 4 components, also provide feature to bulk upload state, city and pincode/area. For more information, see the <a href=":online">online documentation for the Country State and City module</a>.', [':online' => 'https://www.drupal.org/project/dependent_country_state']) . '</p>';
$output .= '<h3>' . t('Uses') . '</h3>';
$output .= '<dt>' . t('Country') . '</dt>';
$output .= '<dd>' . t('By Default all country added by module or you can add/edit/delete as per your need. Also provide API to fetch the data in json format. Below are the API details.
<br/>
End Point: admin/city-state-city/api/get-country<br/>
query parameter with id : admin/city-state-city/api/get-country?id=103<br/>
query parameter with name : admin/city-state-city/api/get-country?country_name=India') . '</dd>';
$output .= '<dt>' . t('State') . '</dt>';
$output .= '<dd>' . t('By Default all india states added by module or you can add/edit/delete as per your need. Also provide API to fetch the data in json format. Below are the API details.
<br/>
End Point: /admin/city-state-city/api/get-state/103<br/>
here 103 mean country ID<br/>
query parameter with name : /admin/city-state-city/api/get-state/103?state_name=Delhi') . '</dd>';
$output .= '<dt>' . t('City') . '</dt>';
$output .= '<dd>' . t('There is no default data added by module but you can add/edit/delete as per your need. Also provide API to fetch the data in json format. Below are the API details.
<br/>
End Point: /admin/city-state-city/api/get-city/32<br/>
here 32 mean state ID<br/>
query parameter with name : /admin/city-state-city/api/get-city/32?city_name=Delhi') . '</dd>';
$output .= '<dt>' . t('Pincode/Area') . '</dt>';
$output .= '<dd>' . t('There is no default data added by module but you can add/edit/delete as per your need. Also provide API to fetch the data in json format. Below are the API details.
<br/>
End Point: /admin/city-state-city/api/get-areapincode/2<br/>
here 2 mean city ID<br/>
query parameter with name : /admin/city-state-city/api/get-areapincode/2?pincode_area=11') . '</dd>';
return $output;
break;
}
}
