diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..34ddeea
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,7 @@
+
+# IntelliJ project files
+.idea
+*.iml
+out
+gen
+# Created by .ignore support plugin (hsz.mobi)
diff --git a/README.txt b/README.txt
index 6ab284b..3badae0 100644
--- a/README.txt
+++ b/README.txt
@@ -1,29 +1,36 @@
-README.txt
+README for contactinfo for Drupal 8
This module collects site-wide contact information and displays it in a block
that you can place anywhere on your site.
Contact information that you provide will be displayed on the site in the hCard
-microformat (http://microformats.org/wiki/hcard). An hCard is a small bundle of
+microformat ( http://microformats.org/wiki/hcard ). An hCard is a small bundle of
code that you want to put on your web site so that Google Maps (and other
mapping services) can more easily index the site's location information.
-
INSTALLATION
============
-- Once downloaded, enable the module at admin/modules
-- Enter your contact information at admin/config/system/contactinfo
-- Place the 'Contact information' block into one of your theme's regions at
- admin/structure/block
+- Download and place into /modules or /sites/all/modules
+- Enable the module at /admin/modules
+- Enter your contact information at /admin/config/system/contactinfo
+- Place the 'Contact information' block into one of your theme's regions at
+ /admin/structure/block/list/
RECOMMENDED MODULES
===================
-- Invisimail (http://drupal.org/project/invisimail)
+- Invisimail ( http://drupal.org/project/invisimail )
Email addresses within the hCard will be obfuscated if the Invisimail module
- is installed.
+ is installed. Not yet implemented for Drupal 8.
+
+FURTHER INFO
+============
+- Information about validators ( http://microformats.org/wiki/validators )
+- Other hCard implementations ( http://microformats.org/wiki/hcard-implementations )
+- Indieweb on hCard ( https://indiewebcamp.com/h-card )
+- Validator ( http://indiewebify.me/validate-h-card/ )
THANKS
======
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..602d3ca
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,6 @@
+{
+ "name": "drupal/contactinfo",
+ "description": "This is an composer.json for contactinfo module.",
+ "type": "drupal-module",
+ "license": "GPL-2.0+"
+}
\ No newline at end of file
diff --git a/config/schema/contactinfo.schema.yml b/config/schema/contactinfo.schema.yml
new file mode 100644
index 0000000..fd03d23
--- /dev/null
+++ b/config/schema/contactinfo.schema.yml
@@ -0,0 +1,68 @@
+# Schema for the configuration files of the Contact Info module.
+
+contactinfo.settings:
+ type: config_object
+ label: 'Config Info settings'
+ mapping:
+ type:
+ type: string
+ label: 'Type'
+ fn_n:
+ type: mapping
+ label: 'Full name'
+ mapping:
+ given_name:
+ type: string
+ label: 'Your first name'
+ family_name:
+ type: string
+ label: 'Your last name'
+ org:
+ type: string
+ label: 'Organization/Business Name'
+ use_site_name:
+ type: boolean
+ label: 'Use site name'
+ tagline:
+ type: string
+ label: 'Tagline'
+ use_site_slogan:
+ type: boolean
+ label: 'Use site slogan'
+ street_address:
+ type: string
+ label: 'Street Address'
+ extended_address:
+ type: string
+ label: 'Extended Address'
+ locality:
+ type: string
+ label: 'City'
+ region:
+ type: string
+ label: 'State/Province'
+ postal_code:
+ type: string
+ label: 'Postal Code'
+ country_name:
+ type: string
+ label: 'Country'
+ longitude:
+ type: string
+ label: 'Longitude'
+ latitude:
+ type: string
+ label: 'Latidude'
+ phone:
+ type: mapping
+ label: 'Phones'
+ mapping:
+ voice:
+ type: string
+ label: 'Voice Phone Number(s)'
+ fax:
+ type: string
+ label: 'Fax numbers+'
+ email:
+ type: string
+ label: 'Email'
diff --git a/contactinfo.admin.js b/contactinfo.admin.js
index a402987..a06f668 100644
--- a/contactinfo.admin.js
+++ b/contactinfo.admin.js
@@ -2,7 +2,7 @@
* @file
* JS for the Contact Information module settings form.
*/
-(function ($, Drupal) {
+(function ($) {
"use strict";
Drupal.behaviors.contactinfo = {
attach: function () {
@@ -10,12 +10,12 @@
org: {
$checkbox: $('#edit-contactinfo-use-site-name'),
$textField: $('#edit-contactinfo-org'),
- siteSettingsVal: Drupal.settings.siteName
+ siteSettingsVal: drupalSettings.contactinfo.siteName
},
tagline: {
$checkbox: $('#edit-contactinfo-use-site-slogan'),
$textField: $('#edit-contactinfo-tagline'),
- siteSettingsVal: Drupal.settings.siteSlogan
+ siteSettingsVal: drupalSettings.contactinfo.siteSlogan
}
};
@@ -38,4 +38,4 @@
});
}
};
-})(jQuery, Drupal);
+})(jQuery);
diff --git a/contactinfo.form.inc b/contactinfo.form.inc
deleted file mode 100644
index 2740640..0000000
--- a/contactinfo.form.inc
+++ /dev/null
@@ -1,188 +0,0 @@
- array(
- array(
- 'data' => $path . '/css/contactinfo.admin.css',
- 'type' => 'file',
- ),
- ),
- 'js' => array(
- $path . '/contactinfo.admin.js',
- array(
- 'data' => array(
- 'siteName' => check_plain(variable_get('site_name', '')),
- 'siteSlogan' => check_plain(variable_get('site_slogan', '')),
- ),
- 'type' => 'setting',
- ),
- ),
- );
-
- $form['contactinfo']['#tree'] = TRUE;
- $form['contactinfo']['type'] = array(
- '#type' => 'radios',
- '#title' => t('Contact information type'),
- '#description' => t('Is this for an individual or a business?'),
- '#options' => array(
- 'personal' => t('Personal'),
- 'business' => t('Organization/Business'),
- ),
- '#default_value' => $default_values['type'],
- );
- $form['contactinfo']['fn_n'] = array(
- '#type' => 'fieldset',
- '#title' => t('Full Name'),
- '#description' => t('If this site is your personal site, enter your full name here.'),
- '#states' => array(
- // Hide this fieldset if type is set to “business”.
- 'invisible' => array(
- ':input[name="contactinfo[type]"]' => array('value' => 'business'),
- ),
- ),
- '#prefix' => '
',
- '#suffix' => '
',
- );
- $form['contactinfo']['fn_n']['given-name'] = array(
- '#type' => 'textfield',
- '#title' => t('First Name'),
- '#description' => t('Your first name.'),
- '#default_value' => $default_values['fn_n']['given-name'],
- );
- $form['contactinfo']['fn_n']['family-name'] = array(
- '#type' => 'textfield',
- '#title' => t('Last Name'),
- '#description' => t('Your last name.'),
- '#default_value' => $default_values['fn_n']['family-name'],
- );
- $form['contactinfo']['org'] = array(
- '#type' => 'textfield',
- '#title' => t('Organization/Business Name'),
- '#default_value' => $default_values['org'],
- '#description' => t('The name of your organization or business.'),
- '#prefix' => '',
- );
- $form['contactinfo']['use_site_name'] = array(
- '#type' => 'checkbox',
- '#title' => t('Use site name'),
- '#default_value' => $default_values['use_site_name'],
- '#suffix' => '
',
- );
- $form['contactinfo']['tagline'] = array(
- '#type' => 'textfield',
- '#title' => t('Tagline'),
- '#default_value' => $default_values['tagline'],
- '#description' => t('A short tagline.'),
- '#prefix' => '',
- );
- $form['contactinfo']['use_site_slogan'] = array(
- '#type' => 'checkbox',
- '#title' => t('Use site slogan'),
- '#default_value' => $default_values['use_site_slogan'],
- '#suffix' => '
',
- );
- $form['contactinfo']['adr'] = array(
- '#type' => 'fieldset',
- '#title' => t('Address'),
- '#description' => t('Enter the contact address for this website.'),
- );
- $form['contactinfo']['adr']['street-address'] = array(
- '#type' => 'textfield',
- '#title' => t('Street Address'),
- '#default_value' => $default_values['adr']['street-address'],
- );
- $form['contactinfo']['adr']['extended-address'] = array(
- '#type' => 'textfield',
- '#title' => t('Extended Address'),
- '#default_value' => $default_values['adr']['extended-address'],
- );
- $form['contactinfo']['adr']['locality'] = array(
- '#type' => 'textfield',
- '#title' => t('City'),
- '#default_value' => $default_values['adr']['locality'],
- );
- $form['contactinfo']['adr']['region'] = array(
- '#type' => 'textfield',
- '#title' => t('State/Province'),
- '#default_value' => $default_values['adr']['region'],
- '#size' => 10,
- );
- $form['contactinfo']['adr']['postal-code'] = array(
- '#type' => 'textfield',
- '#title' => t('Postal Code'),
- '#default_value' => $default_values['adr']['postal-code'],
- '#size' => 10,
- );
- $form['contactinfo']['adr']['country-name'] = array(
- '#type' => 'textfield',
- '#title' => t('Country'),
- '#default_value' => $default_values['adr']['country-name'],
- );
- $form['contactinfo']['location'] = array(
- '#type' => 'fieldset',
- '#title' => t('Geographical Location'),
- '#description' => t('Enter your geographical coordinates to help people locate you.'),
- );
- $form['contactinfo']['location']['longitude'] = array(
- '#type' => 'textfield',
- '#title' => t('Longitude'),
- '#default_value' => $default_values['location']['longitude'],
- '#description' => t('Longitude, in full decimal format (like -121.629562).'),
- );
- $form['contactinfo']['location']['latitude'] = array(
- '#type' => 'textfield',
- '#title' => t('Latitude'),
- '#default_value' => $default_values['location']['latitude'],
- '#description' => t('Latitude, in full decimal format (like 38.827382).'),
- );
- $form['contactinfo']['phone'] = array(
- '#type' => 'fieldset',
- '#title' => t('Phones'),
- '#description' => t('Enter the numbers at which you would like to be reached.'),
- );
- $form['contactinfo']['phone']['voice'] = array(
- '#type' => 'textfield',
- '#title' => t('Voice Phone Number(s)'),
- '#default_value' => $default_values['phone']['voice'],
- '#description' => t('Voice phone numbers, separated by commas.'),
- );
- $form['contactinfo']['phone']['fax'] = array(
- '#type' => 'textfield',
- '#title' => t('Fax Number(s)'),
- '#default_value' => $default_values['phone']['fax'],
- '#description' => t('Fax numbers, separated by commas.'),
- );
- $form['contactinfo']['email'] = array(
- '#type' => 'textfield',
- '#title' => t('Email'),
- '#default_value' => $default_values['email'],
- '#description' => t('Enter this site’s contact email address. This address will be displayed publicly, do not enter a private address.'),
- '#element_validate' => array('contactinfo_validate_email'),
- );
-
- if (module_exists('invisimail')) {
- $form['contactinfo']['email']['#description'] .= ' ' . t('This address will be obfuscated to protect it from spammers.');
- }
- else {
- $form['contactinfo']['email']['#description'] .= ' ' . t('Install the Invisimail module to protect this address from spammers.', array('!url' => 'http://drupal.org/project/invisimail'));
- }
-
- $form = system_settings_form($form);
-
- $form['actions']['submit']['#value'] = t('Save information');
-
- return $form;
-}
diff --git a/contactinfo.info b/contactinfo.info
deleted file mode 100644
index 101373d..0000000
--- a/contactinfo.info
+++ /dev/null
@@ -1,4 +0,0 @@
-name = Contact Info
-description = Collects site-wide contact information and displays it in an hCard block.
-core = 7.x
-configure = admin/config/system/contactinfo
diff --git a/contactinfo.info.yml b/contactinfo.info.yml
new file mode 100644
index 0000000..3af220f
--- /dev/null
+++ b/contactinfo.info.yml
@@ -0,0 +1,8 @@
+name: Contact Info
+description: Collects site-wide contact information and displays it in an hCard block.
+package: Custom
+
+configure: contactinfo.configuration
+
+type: module
+core: 8.x
\ No newline at end of file
diff --git a/contactinfo.install b/contactinfo.install
index f9d5829..9ff0790 100644
--- a/contactinfo.install
+++ b/contactinfo.install
@@ -5,19 +5,14 @@
*/
/**
- * Implements hook_uninstall().
- */
-function contactinfo_uninstall() {
- variable_del('contactinfo');
-}
-
-/**
* Add a default value for Extended Address, to prevent warnings.
*/
function contactinfo_update_7100(&$sandbox) {
- $contactinfo = variable_get('contactinfo', FALSE);
+ $contactinfo = \Drupal::config('contactinfo.settings')->get();
+
if ($contactinfo && is_array($contactinfo) && !isset($contactinfo['adr']['extended-address'])) {
- $contactinfo['adr']['extended-address'] = '';
- variable_set('contactinfo', $contactinfo);
+ $contactinfo['adr']['extended-address'] = '';
+ // \Drupal::config('contactinfo.settings')->set($contactinfo)->save();
+ // Todo fix. this is not working for drupal 8
}
}
diff --git a/contactinfo.libraries.yml b/contactinfo.libraries.yml
new file mode 100644
index 0000000..a162a61
--- /dev/null
+++ b/contactinfo.libraries.yml
@@ -0,0 +1,16 @@
+contactinfo:
+ version: VERSION
+ js:
+ contactinfo.admin.js: {}
+ css:
+ component:
+ css/contactinfo.admin.css: {}
+ dependencies:
+ - core/jquery
+ - core/drupalSettings
+
+contactinfo-block:
+ version: VERSION
+ css:
+ theme:
+ css/contactinfo.css: {}
\ No newline at end of file
diff --git a/contactinfo.links.contextual.yml b/contactinfo.links.contextual.yml
new file mode 100644
index 0000000..9808dc9
--- /dev/null
+++ b/contactinfo.links.contextual.yml
@@ -0,0 +1,4 @@
+contactinfo_configure:
+ title: 'Edit information'
+ route_name: 'contactinfo.configuration'
+ group: 'block'
diff --git a/contactinfo.links.menu.yml b/contactinfo.links.menu.yml
new file mode 100644
index 0000000..11d23d7
--- /dev/null
+++ b/contactinfo.links.menu.yml
@@ -0,0 +1,6 @@
+contactinfo.admin:
+ title: 'Contact Info settings'
+ description: 'Edit your contact information'
+ parent: system.admin_config_development
+ route_name: contactinfo.configuration
+ weight: 100
\ No newline at end of file
diff --git a/contactinfo.module b/contactinfo.module
index 3d051f4..ffb5d1d 100644
--- a/contactinfo.module
+++ b/contactinfo.module
@@ -7,46 +7,19 @@
/**
* Implements hook_help().
*/
-function contactinfo_help($path, $arg) {
- switch ($path) {
- case 'admin/help#contactinfo':
+function contactinfo_help($route_name, \Drupal\Core\Routing\RouteMatchInterface $route_match) {
+ switch ($route_name) {
+ case 'help.page.contactinfo':
$output = '' . t('Contact information that you provide will be displayed on the site in the hCard microformat. An hCard is a small bundle of code that you want to put on your web site so that Google Maps (and other mapping services) can more easily index the site’s location information.') . '
';
return $output;
- case 'admin/config/system/contactinfo':
- return '' . t("Enter your site’s contact information into the appropriate fields. All fields are optional.") . '
';
+ case 'contactinfo.configuration':
+ $output = '' . t('Enter your site’s contact information into the appropriate fields. All fields are optional.') . '
';
+ return $output;
}
}
/**
- * Implements hook_permission().
- */
-function contactinfo_permission() {
- return array(
- 'administer contactinfo' => array(
- 'title' => t('Administer contact information'),
- 'description' => t('Edit contact information for this site.'),
- ),
- );
-}
-
-/**
- * Implements hook_menu().
- */
-function contactinfo_menu() {
- $items['admin/config/system/contactinfo'] = array(
- 'title' => 'Contact information',
- 'description' => 'Configure contact information that is publicly displayed on this site.',
- 'page callback' => 'drupal_get_form',
- 'page arguments' => array('contactinfo_admin_settings'),
- 'access arguments' => array('administer contactinfo'),
- 'file' => 'contactinfo.form.inc',
- 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
- );
- return $items;
-}
-
-/**
* Implements hook_theme().
*/
function contactinfo_theme($existing, $type, $theme, $path) {
@@ -74,7 +47,6 @@ function contactinfo_theme($existing, $type, $theme, $path) {
'faxes' => array(),
'email' => NULL,
),
- 'template' => 'contactinfo',
),
);
}
@@ -87,47 +59,51 @@ function contactinfo_theme($existing, $type, $theme, $path) {
* $variable['contactinfo'] is equivalent to contactinfo_get_contactinfo().
*/
function template_preprocess_contactinfo(&$variables) {
- drupal_add_css(drupal_get_path('module', 'contactinfo') . '/css/contactinfo.css');
+ $config = \Drupal::config('contactinfo.settings');
+ $site_config = \Drupal::config('system.site');
// Build $variables from scratch.
- $contactinfo = $variables['contactinfo'];
- $variables['type'] = $contactinfo['type'];
- $variables['given_name'] = check_plain($contactinfo['fn_n']['given-name']);
- $variables['family_name'] = check_plain($contactinfo['fn_n']['family-name']);
- $variables['org'] = $contactinfo['use_site_name'] ? check_plain(variable_get('site_name', '')) : check_plain($contactinfo['org']);
- $variables['street_address'] = check_plain($contactinfo['adr']['street-address']);
- $variables['extended_address'] = check_plain($contactinfo['adr']['extended-address']);
- $variables['locality'] = check_plain($contactinfo['adr']['locality']);
- $variables['region'] = check_plain($contactinfo['adr']['region']);
- $variables['postal_code'] = check_plain($contactinfo['adr']['postal-code']);
- $variables['country'] = check_plain($contactinfo['adr']['country-name']);
- $variables['longitude'] = check_plain($contactinfo['location']['longitude']);
- $variables['latitude'] = check_plain($contactinfo['location']['latitude']);
- $variables['tagline'] = $contactinfo['use_site_slogan'] ? check_plain(variable_get('site_slogan', '')) : check_plain($contactinfo['tagline']);
+ $variables['type'] = $config->get('type');
+ $variables['given_name'] = $config->get('fn_n.given_name');
+ $variables['family_name'] = $config->get('fn_n.family_name');
+ $variables['org'] = $config->get('use_site_name') ? $site_config->get('name') : $config->get('org');
+ $variables['street_address'] = $config->get('street_address');
+ $variables['extended_address'] = $config->get('extended_address');
+ $variables['locality'] = $config->get('locality');
+ $variables['region'] = $config->get('region');
+ $variables['postal_code'] = $config->get('postal_code');
+ $variables['country'] = $config->get('country');
+ $variables['longitude'] = $config->get('longitude');
+ $variables['latitude'] = $config->get('latitude');
+ $variables['tagline'] = $config->get('use_site_slogan') ? $site_config->get('slogan') : $config->get('tagline');
// Generate formatted longitude and latitude.
$variables['longitude_formatted'] = contactinfo_coord_convert($variables['longitude'], 'longitude');
$variables['latitude_formatted'] = contactinfo_coord_convert($variables['latitude'], 'latitude');
+ $voice = $config->get('phone.voice');
// Generates the output for the 'phones' variable.
- if ($contactinfo['phone']['voice']) {
- $phone_text = check_plain($contactinfo['phone']['voice']);
+ if ($voice) {
+ $phone_text = $voice;
$phones = explode(',', $phone_text);
$variables['phones'] = array_map('trim', $phones);
}
+ $fax = $config->get('phone.fax');
// Generates the output for the 'faxes' variable.
- if ($contactinfo['phone']['fax']) {
- $fax_text = check_plain($contactinfo['phone']['fax']);
+ if ($fax) {
+ $fax_text = $fax;
$faxes = explode(',', $fax_text);
$variables['faxes'] = array_map('trim', $faxes);
}
+ $email = $config->get('email');
// Generate the output for the 'email' variable.
- if ($contactinfo['email']) {
- $email = check_plain($contactinfo['email']);
+ if ($email) {
// Use obfuscation provided by invisimail module.
if (function_exists('invisimail_encode_html')) {
+
+ // Todo invisimail is NOT available on drupal 8.
$variables['email'] = invisimail_encode_html($email);
$variables['email_url'] = INVISIMAIL_MAILTO_ASCII . $variables['email'];
}
@@ -139,55 +115,16 @@ function template_preprocess_contactinfo(&$variables) {
// Generate ID.
$id = 'contactinfo';
- if ($contactinfo['type'] == 'personal') {
- $id .= !empty($contactinfo['fn_n']['given-name']) ? '-' . check_plain($contactinfo['fn_n']['given-name']) : '';
- $id .= !empty($contactinfo['fn_n']['family-name']) ? '-' . check_plain($contactinfo['fn_n']['family-name']) : '';
+ if ($config->get('type') === 'personal') {
+ $id .= !empty($config->get('fn_n.given_name')) ? '-' . $config->get('fn_n.given_name') : '';
+ $id .= !empty($config->get('fn_n.family_name')) ? '-' . $config->get('fn_n.family_name') : '';
}
else {
- $id .= !empty($contactinfo['org']) ? '-' . check_plain($contactinfo['org']) : '';
+ $id .= !empty($config->get('org')) ? '-' . $config->get('org') : '';
}
- $variables['id'] = drupal_html_id($id);
+ $variables['id'] = \Drupal\Component\Utility\Html::getUniqueId($id);
}
-/**
- * Validate an email address.
- */
-function contactinfo_validate_email($element, &$form_state) {
- if (!empty($element['#value']) && !valid_email_address($element['#value'])) {
- form_error($element, t('You must enter a valid e-mail address.'));
- }
-}
-
-/**
- * Implements hook_block_info().
- */
-function contactinfo_block_info() {
- $blocks['hcard'] = array(
- 'info' => 'Contact information',
- 'weight' => 10,
- 'status' => 1,
- 'region' => 'footer',
- );
- return $blocks;
-}
-
-/**
- * Implements hook_block_view().
- */
-function contactinfo_block_view($delta) {
- $block = array();
- switch ($delta) {
- case 'hcard':
- $contactinfo = contactinfo_get_contactinfo();
- if ($contactinfo) {
- $block = array(
- 'subject' => '',
- 'content' => theme('contactinfo', array('contactinfo' => $contactinfo)),
- );
- }
- return $block;
- }
-}
/**
* Theme function for the Contact Info settings form.
@@ -197,30 +134,7 @@ function contactinfo_block_view($delta) {
function theme_contactinfo_admin_settings($variables) {
$form = $variables['form'];
return drupal_render_children($form);
-}
-
-/**
- * Implements hook_contextual_links_view_alter().
- *
- * @param array $element
- * A renderable array representing the contextual links.
- * @param array $items
- * An associative array containing the original contextual link items, as
- * generated by menu_contextual_links(), which were used to build
- * $element['#links'].
- */
-function contactinfo_contextual_links_view_alter(&$element, $items) {
- $block = isset($element['#element']['#block']) ? $element['#element']['#block'] : NULL;
- if (is_object($block) && $block->module == 'contactinfo' && user_access('administer contactinfo')) {
- $element['#links']['contactinfo-edit'] = array(
- 'title' => t('Edit information'),
- 'href' => 'admin/config/system/contactinfo',
- 'query' => drupal_get_destination(),
- 'attributes' => array(
- 'title' => t('Edit your contact information'),
- ),
- );
- }
+ // Todo this is deprecated in drupal 8.1.
}
/**
@@ -239,7 +153,7 @@ function contactinfo_contextual_links_view_alter(&$element, $items) {
* whole number, and minutes as a decimal value.
*/
function contactinfo_coord_convert($decimal, $direction) {
- $decimal = floatval($decimal);
+ $decimal = (float) $decimal;
if (!$decimal) {
return FALSE;
}
@@ -256,62 +170,8 @@ function contactinfo_coord_convert($decimal, $direction) {
return FALSE;
}
- $coord_degrees = intval($decimal);
+ $coord_degrees = (int) $decimal;
$coord_minutes = abs(fmod($decimal, 1) * 60);
return $coord_direction . ' ' . $coord_degrees . '° ' . $coord_minutes . '"';
}
-
-/**
- * Helper function to return saved contact information.
- *
- * @return array
- * All contact information saved from the settings form.
- */
-function contactinfo_get_contactinfo() {
- // Get variable defaults.
- $default = contactinfo_defaults();
-
- // Get saved contact information.
- $contactinfo = variable_get('contactinfo', $default);
-
- // Merge default values and saved data to ensure all array keys are present.
- return array_merge($default, $contactinfo);
-}
-
-/**
- * Returns the default values for the site contact information.
- *
- * @return array
- * Default values for all contact info keys.
- */
-function contactinfo_defaults() {
- return array(
- 'type' => 'personal',
- 'fn_n' => array(
- 'given-name' => '',
- 'family-name' => '',
- ),
- 'org' => '',
- 'use_site_name' => 0,
- 'tagline' => '',
- 'use_site_slogan' => 0,
- 'adr' => array(
- 'street-address' => '',
- 'extended-address' => '',
- 'locality' => '',
- 'region' => '',
- 'postal-code' => '',
- 'country-name' => '',
- ),
- 'location' => array(
- 'longitude' => '',
- 'latitude' => '',
- ),
- 'phone' => array(
- 'voice' => '',
- 'fax' => '',
- ),
- 'email' => '',
- );
-}
diff --git a/contactinfo.permissions.yml b/contactinfo.permissions.yml
new file mode 100644
index 0000000..8b0eb60
--- /dev/null
+++ b/contactinfo.permissions.yml
@@ -0,0 +1,3 @@
+administer contactinfo:
+ title: 'Administer contact information'
+ description: 'Edit contact information for this site.'
\ No newline at end of file
diff --git a/contactinfo.routing.yml b/contactinfo.routing.yml
new file mode 100644
index 0000000..28cadec
--- /dev/null
+++ b/contactinfo.routing.yml
@@ -0,0 +1,7 @@
+contactinfo.configuration:
+ path: '/admin/config/system/contactinfo'
+ defaults:
+ _form: '\Drupal\contactinfo\Form\AdminForm'
+ _title: 'Contact information'
+ requirements:
+ _permission: 'administer contactinfo'
\ No newline at end of file
diff --git a/contactinfo.tokens.inc b/contactinfo.tokens.inc
index 088da50..0516909 100644
--- a/contactinfo.tokens.inc
+++ b/contactinfo.tokens.inc
@@ -9,7 +9,7 @@
*/
function contactinfo_token_info() {
$type = array(
- 'name' => t('Contact information'),
+ 'name' => t('Contact information'),
'description' => t('Tokens for this site\'s contact information.'),
);
@@ -95,73 +95,75 @@ function contactinfo_tokens($type, $tokens, array $data = array(), array $option
$replacements = array();
$sanitize = !empty($options['sanitize']);
- if ($type == 'contactinfo') {
- $contactinfo = contactinfo_get_contactinfo();
+ if ($type === 'contactinfo') {
+ $config = \Drupal::config('contactinfo.settings');
+ $site_config = \Drupal::config('system.site');
+
foreach ($tokens as $name => $original) {
$value = FALSE;
switch ($name) {
case 'type':
- $value = $contactinfo['type'];
+ $value = $config->get('type');
break;
case 'given-name':
- $value = $contactinfo['fn_n']['given-name'];
+ $value = $config->get('fn_n.given_name');
break;
case 'family-name':
- $value = $contactinfo['fn_n']['family-name'];
+ $value = $config->get('fn_n.family_name');
break;
case 'org':
- $value = $contactinfo['use_site_name'] ? variable_get('site_name', '') : $contactinfo['org'];
+ $value = $config->get('use_site_name') ? $site_config->get('name') : $config->get('org');
break;
case 'tagline':
- $value = $contactinfo['use_site_slogan'] ? variable_get('site_slogan', '') : $contactinfo['tagline'];
+ $value = $config->get('use_site_slogan') ? $site_config->get('slogan') : $config->get('tagline');
break;
case 'adr-street-address':
- $value = $contactinfo['adr']['street-address'];
+ $value = $config->get('street_address');
break;
case 'adr-extended-address':
- $value = $contactinfo['adr']['extended-address'];
+ $value = $config->get('extended_address');
break;
case 'adr-locality':
- $value = $contactinfo['adr']['locality'];
+ $value = $config->get('locality');
break;
case 'adr-region':
- $value = $contactinfo['adr']['region'];
+ $value = $config->get('region');
break;
case 'adr-postal-code':
- $value = $contactinfo['adr']['postal-code'];
+ $value = $config->get('postal_code');
break;
case 'adr-country-name':
- $value = $contactinfo['adr']['country-name'];
+ $value = $config->get('country_name');
break;
case 'location-latitude':
- $value = $contactinfo['location']['latitude'];
+ $value = $config->get('latitude');
break;
case 'location-longitude':
- $value = $contactinfo['location']['longitude'];
+ $value = $config->get('longitude');
break;
case 'phone-voice':
- $value = $contactinfo['phone']['voice'];
+ $value = $config->get('phone.voice');
break;
case 'phone-fax':
- $value = $contactinfo['phone']['fax'];
+ $value = $config->get('phone.fax');
break;
case 'email':
- $value = $contactinfo['email'];
+ $value = $config->get('email');
break;
}
diff --git a/contactinfo.tpl.php b/contactinfo.tpl.php
deleted file mode 100644
index 5ca363f..0000000
--- a/contactinfo.tpl.php
+++ /dev/null
@@ -1,114 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/contactinfo.variable.inc b/contactinfo.variable.inc
deleted file mode 100644
index 1e9e871..0000000
--- a/contactinfo.variable.inc
+++ /dev/null
@@ -1,34 +0,0 @@
- t('Contact information'),
- 'description' => t('Contact information for this website.'),
- 'type' => 'array',
- 'default callback' => 'contactinfo_defaults',
- 'group' => 'contactinfo',
- 'localize' => TRUE,
- );
-
- return $variable;
-}
-
-/**
- * Implements hook_variable_group_info().
- */
-function contactinfo_variable_group_info() {
- $groups['contactinfo'] = array(
- 'title' => t('Contact information'),
- 'description' => t('Contact Information'),
- 'access' => 'administer contactinfo',
- 'path' => 'admin/config/system/contactinfo',
- );
- return $groups;
-}
diff --git a/css/contactinfo.admin.css b/css/contactinfo.admin.css
index ace29ca..06a8ff9 100644
--- a/css/contactinfo.admin.css
+++ b/css/contactinfo.admin.css
@@ -9,6 +9,11 @@
width: 16em;
}
+#edit-contactinfo-fn-n--description,
+#edit-contactinfo-adr--description {
+ clear: both;
+}
+
#edit-contactinfo-fn-n .form-item .form-text {
width: 100%;
}
diff --git a/css/contactinfo.css b/css/contactinfo.css
index 0df36c2..cdab91f 100644
--- a/css/contactinfo.css
+++ b/css/contactinfo.css
@@ -3,10 +3,10 @@
* Contact Information CSS rules.
*/
-#contactinfo .geo {
+.block-contactinfo .geo {
display: none;
}
-#contactinfo .phone abbr {
+.block-contactinfo .phone abbr {
border-bottom: none;
}
diff --git a/src/Form/AdminForm.php b/src/Form/AdminForm.php
new file mode 100644
index 0000000..398bd42
--- /dev/null
+++ b/src/Form/AdminForm.php
@@ -0,0 +1,232 @@
+config('contactinfo.settings');
+ $site_config = $this->config('system.site');
+
+ $form['#attached']['library'][] = 'contactinfo/contactinfo';
+ $form['#attached']['drupalSettings']['contactinfo']['siteName'] = Html::escape($site_config->get('name'));
+ $form['#attached']['drupalSettings']['contactinfo']['siteSlogan'] = Html::escape($site_config->get('slogan'));
+
+ $form['#tree'] = TRUE;
+ $form['contactinfo']['#tree'] = TRUE;
+ $form['contactinfo']['type'] = array(
+ '#type' => 'radios',
+ '#title' => t('Contact information type'),
+ '#description' => t('Is this for an individual or a business?'),
+ '#options' => array(
+ 'personal' => t('Personal'),
+ 'business' => t('Organization/Business'),
+ ),
+ '#default_value' => $config->get('type'),
+ );
+ $form['contactinfo']['fn_n'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Full Name'),
+ '#description' => t('If this site is your personal site, enter your full name here.'),
+ '#states' => array(
+ // Hide this fieldset if type is set to “business”.
+ 'invisible' => array(
+ ':input[name="contactinfo[type]"]' => array('value' => 'business'),
+ ),
+ ),
+ '#prefix' => '',
+ '#suffix' => '
',
+ );
+ $form['contactinfo']['fn_n']['given-name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('First Name'),
+ '#description' => t('Your first name.'),
+ '#default_value' => $config->get('fn_n.given_name'),
+ );
+ $form['contactinfo']['fn_n']['family-name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Last Name'),
+ '#description' => t('Your last name.'),
+ '#default_value' => $config->get('fn_n.family_name'),
+ );
+ $form['contactinfo']['org'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Organization/Business Name'),
+ '#default_value' => $config->get('org'),
+ '#description' => t('The name of your organization or business.'),
+ '#prefix' => '',
+ );
+ $form['contactinfo']['use_site_name'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Use site name'),
+ '#default_value' => $config->get('use_site_name'),
+ '#suffix' => '
',
+ );
+ $form['contactinfo']['tagline'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Tagline'),
+ '#default_value' => $config->get('tagline'),
+ '#description' => t('A short tagline.'),
+ '#prefix' => '',
+ );
+ $form['contactinfo']['use_site_slogan'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Use site slogan'),
+ '#default_value' => $config->get('use_site_slogan'),
+ '#suffix' => '
',
+ );
+ $form['contactinfo']['adr'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Address'),
+ '#description' => t('Enter the contact address for this website.'),
+ );
+ $form['contactinfo']['adr']['street-address'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Street Address'),
+ '#default_value' => $config->get('street_address'),
+ );
+ $form['contactinfo']['adr']['extended-address'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Extended Address'),
+ '#default_value' => $config->get('extended_address'),
+ );
+ $form['contactinfo']['adr']['locality'] = array(
+ '#type' => 'textfield',
+ '#title' => t('City'),
+ '#default_value' => $config->get('locality'),
+ );
+ $form['contactinfo']['adr']['region'] = array(
+ '#type' => 'textfield',
+ '#title' => t('State/Province'),
+ '#default_value' => $config->get('region'),
+ '#size' => 10,
+ );
+ $form['contactinfo']['adr']['postal-code'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Postal Code'),
+ '#default_value' => $config->get('postal_code'),
+ '#size' => 10,
+ );
+ $form['contactinfo']['adr']['country-name'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Country'),
+ '#default_value' => $config->get('country_name'),
+ );
+ $form['contactinfo']['location'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Geographical Location'),
+ '#description' => t('Enter your geographical coordinates to help people locate you.'),
+ );
+ $form['contactinfo']['location']['longitude'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Longitude'),
+ '#default_value' => $config->get('longitude'),
+ '#description' => t('Longitude, in full decimal format (like -121.629562).'),
+ );
+ $form['contactinfo']['location']['latitude'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Latitude'),
+ '#default_value' => $config->get('latitude'),
+ '#description' => t('Latitude, in full decimal format (like 38.827382).'),
+ );
+ $form['contactinfo']['phone'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Phones'),
+ '#description' => t('Enter the numbers at which you would like to be reached.'),
+ );
+ $form['contactinfo']['phone']['voice'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Voice Phone Number(s)'),
+ '#default_value' => $config->get('phone.voice'),
+ '#description' => t('Voice phone numbers, separated by commas.'),
+ );
+ $form['contactinfo']['phone']['fax'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Fax Number(s)'),
+ '#default_value' => $config->get('phone.fax'),
+ '#description' => t('Fax numbers, separated by commas.'),
+ );
+ $form['contactinfo']['email'] = array(
+ '#type' => 'textfield',
+ '#title' => t('Email'),
+ '#default_value' => $config->get('email'),
+ '#description' => t('Enter this site’s contact email address. This address will be displayed publicly, do not enter a private address.'),
+ '#element_validate' => array(
+ array($this, 'validate_email'),
+ ),
+ );
+
+ $form['actions']['submit']['#value'] = t('Save information');
+
+ return parent::buildForm($form, $form_state);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function validate_email(array &$element, FormStateInterface $form_state) {
+ $validate = \Drupal::service('email.validator');
+
+ if (!empty($element['#value']) && !$validate->isValid($element['#value'])) {
+ $form_state->setError($element, t('You must enter a valid e-mail address.'));
+ }
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function submitForm(array &$form, FormStateInterface $form_state) {
+ parent::submitForm($form, $form_state);
+
+ $this->config('contactinfo.settings')
+ ->set('type', $form_state->getValue(array('contactinfo', 'type')))
+ ->set('fn_n.given_name', $form_state->getValue(array('contactinfo', 'fn_n', 'given-name')))
+ ->set('fn_n.family_name', $form_state->getValue(array('contactinfo', 'fn_n', 'family-name')))
+ ->set('org', $form_state->getValue(array('contactinfo', 'org')))
+ ->set('use_site_name', $form_state->getValue(array('contactinfo', 'use_site_name')))
+ ->set('tagline', $form_state->getValue(array('contactinfo', 'tagline')))
+ ->set('use_site_slogan', $form_state->getValue(array('contactinfo', 'use_site_slogan')))
+ ->set('street_address', $form_state->getValue(array('contactinfo', 'adr', 'street-address')))
+ ->set('extended_address', $form_state->getValue(array('contactinfo', 'adr', 'extended-address')))
+ ->set('locality', $form_state->getValue(array('contactinfo', 'adr', 'locality')))
+ ->set('region', $form_state->getValue(array('contactinfo', 'adr', 'region')))
+ ->set('postal_code', $form_state->getValue(array('contactinfo', 'adr', 'postal-code')))
+ ->set('country_name', $form_state->getValue(array('contactinfo', 'adr', 'country-name')))
+ ->set('longitude', $form_state->getValue(array('contactinfo', 'location', 'longitude')))
+ ->set('latitude', $form_state->getValue(array('contactinfo', 'location', 'latitude')))
+ ->set('phone.voice', $form_state->getValue(array('contactinfo', 'phone', 'voice')))
+ ->set('phone.fax', $form_state->getValue(array('contactinfo', 'phone', 'fax')))
+ ->set('email', $form_state->getValue(array('contactinfo', 'email')))
+ ->save();
+ }
+
+}
diff --git a/src/Plugin/Block/ContactInfoBlock.php b/src/Plugin/Block/ContactInfoBlock.php
new file mode 100644
index 0000000..230fc3c
--- /dev/null
+++ b/src/Plugin/Block/ContactInfoBlock.php
@@ -0,0 +1,55 @@
+ 'contactinfo',
+ '#contextual_links' => array(
+ 'block' => array(
+ 'route_parameters' => array('contactinfo' => 'contactinfo_configure'),
+ ),
+ ),
+ '#contactinfo' => NULL,
+ '#type' => 'personal',
+ '#given_name' => NULL,
+ '#family_name' => NULL,
+ '#org' => NULL,
+ '#tagline' => NULL,
+ '#street_address' => NULL,
+ '#extended_address' => NULL,
+ '#locality' => NULL,
+ '#region' => NULL,
+ '#postal_code' => NULL,
+ '#country' => NULL,
+ '#longitude' => NULL,
+ '#latitude' => NULL,
+ '#phones' => array(),
+ '#faxes' => array(),
+ '#email' => NULL,
+ '#attached' => array(
+ 'library' => array('contactinfo/contactinfo-block'),
+ ),
+ );
+ }
+
+}
diff --git a/templates/contactinfo.html.twig b/templates/contactinfo.html.twig
new file mode 100644
index 0000000..d8a246c
--- /dev/null
+++ b/templates/contactinfo.html.twig
@@ -0,0 +1,106 @@
+{#
+/**
+ * @file
+ * Default theme implementation to display the hcard in a block.
+ *
+ * Available variables:
+ *
+ * - $contactinfo: variable_get('contactinfo', array()).
+ *
+ * - $type: Either 'personal' or 'business'.
+ *
+ * - $given_name: The given-name value.
+ * - $family_name: The family-name value.
+ * - $org: The name of the business or organization.
+ *
+ * - $tagline: The tagline.
+ *
+ * - $street_address: The street-address value.
+ * - $extended_address: The extended-address value.
+ * - $locality: The locality value. In USA, this is the city.
+ * - $region: The region value. In the USA, this is the state.
+ * - $postal_code: The postal-code value.
+ * - $country: The country-name value.
+ *
+ * - $longitude: The longitude value in decimal degrees format.
+ * - $latitude: The latitude value in decimal degrees format.
+ * - $longitude_formatted: The longitude value in decimal degrees and decimal
+ * minutes format.
+ * - $latitude_formatted: The latitude value in decimal degrees and decimal
+ * minutes format.
+ *
+ * - $phones: An array of phone numbers.
+ * - $faxes: An array of fax numbers.
+ *
+ * - $email_url: The href for the mailto link.
+ * - $email: The email address value.
+ */
+#}
+
+
+{% if type == "personal" %}
+
+{% if given_name %}
+
{{ given_name }}
+{% endif %}
+{% if family_name %}
+
{{ family_name }}
+{% endif %}
+{% if org %}
+
{{ org }}
+{% endif %}
+
+{% else %}
+{% if org %}
+
{{ org }}
+{% endif %}
+{% endif %}
+{% if tagline %}
+
{{ tagline }}
+{% endif %}
+{% if street_address or locality or region or postal_code or country %}
+
+{% if street_address %}
+
{{ street_address }}
+{% endif %}
+{% if extended_address %}
+
{{ extended_address }}
+{% endif %}
+{% if locality %}
+
{{ locality }}{% if region %},{% endif %}
+{% endif %}
+{% if region %}
+
{{ region }}
+{% endif %}
+{% if postal_code %}
+
{{ postal_code }}
+{% endif %}
+{% if country %}
+
{{ country }}
+{% endif %}
+
+{% endif %}
+{% if longitude or latitude %}
+
+
{{ longitude_formatted }}
+
{{ latitude_formatted }}
+
+{% endif %}
+{% if phones or faxes %}
+
+{% for phone in phones %}
+{% if phone %}
+
{{ 'Telephone'|t }}: {{ phone }}
+{% endif %}
+{% endfor %}
+{% for fax in faxes %}
+{% if fax %}
+
+{% endif %}
+{% endfor %}
+
+{% endif %}
+{% if email %}
+
{{ email }}
+{% endif %}
+