Skip to content

Commit

Permalink
fix issues to the webform cac
Browse files Browse the repository at this point in the history
  • Loading branch information
saltonmassally committed Aug 1, 2017
1 parent b32e527 commit 217cd98
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 26 deletions.
63 changes: 51 additions & 12 deletions webform_cac/src/Element/ContactCac.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,69 @@

namespace Drupal\webform_cac\Element;

use Drupal\webform\Element\WebformContact;
use Drupal\webform\Element\WebformCompositeBase;

/**
* Provides a form element for a contact element
*
* @FormElement("webform_contact_cac")
*/
class ContactCac extends WebformContact {
class ContactCac extends WebformCompositeBase {

/**
* {@inheritdoc}
*/
public function getInfo() {
return parent::getInfo() + ['#theme' => 'webform_composite_contact_cac'];
}

/**
* {@inheritdoc}
*/
public static function getCompositeElements() {
$elements = [];
$elements += parent::getCompositeElements();
$elements['name'] = [
'#type' => 'textfield',
'#title' => t('Name'),
];
$elements['company'] = [
'#type' => 'textfield',
'#title' => t('Company'),
];
$elements['email'] = [
'#type' => 'email',
'#title' => t('Email'),
];
$elements['phone'] = [
'#type' => 'tel',
'#title' => t('Phone'),
];
$elements['address'] = [
'#type' => 'textfield',
'#title' => t('Address'),
];
$elements['address_2'] = [
'#type' => 'textfield',
'#title' => t('Address 2'),
];
$elements['city'] = [
'#type' => 'textfield',
'#title' => t('City/Town'),
];
$elements['state_province'] = [
'#type' => 'select',
'#title' => t('District'),
'#options' => 'state_province_names',
];
$elements['postal_code'] = [
'#type' => 'textfield',
'#title' => t('Zip/Postal Code'),
];
$elements['country'] = [
'#type' => 'select',
'#title' => t('Country'),
'#options' => 'country_names',
];
$elements['dob'] = [
'#type' => 'date',
'#title' => t('Date of Birth'),
Expand Down Expand Up @@ -47,15 +95,6 @@ public static function getCompositeElements() {
'#type' => 'date',
'#title' => t('Date of Appointment'),
];









return $elements;
}

Expand Down
77 changes: 63 additions & 14 deletions webform_cac/src/Plugin/WebformElement/WebformContactCaC.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,56 @@ class WebformContactCac extends WebformCompositeBase {
/**
* {@inheritdoc}
*/
// public function getCompositeElements() {
// $elements = ContactCac::getCompositeElements();
// return $elements;
// }

// /**
// * {@inheritdoc}
// */
// public function getInitializedCompositeElement(array &$element) {
// $form_state = new FormState();
// $form_completed = [];
// return ContactCac::processWebformComposite($element, $form_state, $form_completed);
// }
protected function formatHtmlItemValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$lines = $this->formatTextItemValue($element, $webform_submission, $options);
if (!empty($lines['email'])) {
$lines['email'] = [
'#type' => 'link',
'#title' => $lines['email'],
'#url' => \Drupal::pathValidator()->getUrlIfValid('mailto:' . $lines['email']),
];
}
return $lines;
}

/**
* {@inheritdoc}
*/
protected function formatTextItemValue(array $element, WebformSubmissionInterface $webform_submission, array $options = []) {
$value = $this->getValue($element, $webform_submission, $options);

$location = '';
if (!empty($value['city'])) {
$location .= $value['city'];
}
if (!empty($value['state_province'])) {
$location .= ($location) ? ', ' : '';
$location .= $value['state_province'];
}
if (!empty($value['postal_code'])) {
$location .= ($location) ? '. ' : '';
$location .= $value['postal_code'];
}

$lines = [];
if (!empty($value['name'])) {
$lines['name'] = $value['name'];
}
if (!empty($value['company'])) {
$lines['company'] = $value['company'];
}
$lines += parent::formatTextItemValue($element, $webform_submission, $options);
if (!empty($value['address'])) {
$lines['address'] = $value['address'];
}
if (!empty($value['address_2'])) {
$lines['address_2'] = $value['address_2'];
}
if ($location) {
$lines['location'] = $location;
}
if (!empty($value['country'])) {
$lines['country'] = $value['country'];
}
if (!empty($value['email'])) {
$lines['email'] = $value['email'];
}
Expand All @@ -65,6 +88,32 @@ protected function formatTextItemValue(array $element, WebformSubmissionInterfac
if (!empty($value['other_directorship'])) {
$lines['other_directorship'] = $value['other_directorship'];
}
if (!empty($value['dob'])) {
$lines['dob'] = $value['dob'];
}
if (!empty($value['gender'])) {
$lines['gender'] = $value['gender'];
}

if (!empty($value['nationality'])) {
$lines['nationality'] = $value['nationality'];
}

if (!empty($value['shares'])) {
$lines['shares'] = $value['shares'];
}

if (!empty($value['occupation'])) {
$lines['occupation'] = $value['occupation'];
}

if (!empty($value['other_directorship'])) {
$lines['other_directorship'] = $value['other_directorship'];
}

if (!empty($value['appointment_date'])) {
$lines['appointment_date'] = $value['appointment_date'];
}
return $lines;
}

Expand Down

0 comments on commit 217cd98

Please sign in to comment.