Skip to content
Snippets Groups Projects
Commit 24a1a35d authored by Gabriel Carleton-Barnes's avatar Gabriel Carleton-Barnes Committed by Aaron Bauman
Browse files

Issue #3170552 by gcb, olivier.bouwman: Address widget for Salesforce style...

Issue #3170552 by gcb, olivier.bouwman: Address widget for Salesforce style address field (textarea)
parent 9bfd9e75
No related branches found
No related tags found
No related merge requests found
......@@ -37,6 +37,7 @@
"ext-json": "*"
},
"require-dev": {
"drupal/address": "^1.8"
"drupal/key": "^1.14",
"firebase/php-jwt": "^5.0",
"lusitanian/oauth": "^0.8.11",
......
name: Salesforce Address
type: module
description: A custom Address Field Widget for Salesforce compatibility.
core_version_requirement: ^8.7.7 || ^9
package: Salesforce
dependencies:
- address:address
<?php
/**
* @file
* Contains salesforce_address.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function salesforce_address_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.salesforce_address':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Salesforce Address provides a tweaked version
of the Address Field widget from the Address module, which is compatible
with Salesforce address formatting, which uses a single, multi-line
field for the street address rather than multiple lines. If you are
syncing Address fields with Saleforce addresses, you can save a lot of
sync trouble by enabling this widget on your Form configurations for
your Address fields.') . '</p>';
return $output;
default:
}
}
<?php
namespace Drupal\salesforce_address\Element;
use Drupal\address\Element\Address;
/**
* Replaces the address line(s) on an address form element with a textarea.
*
* Salesforce has a textarea for the Street field, this matches that in Drupal
* so we can sync easier.
*
* @FormElement("address_street_as_textarea")
*/
class AddressStreetAsTextArea extends Address {
/**
* {@inheritdoc}
*/
protected static function addressElements(array $element, array $value) {
$element = Address::addressElements($element, $value);
$element["address_line1"]["#type"] = "textarea";
$element["address_line1"]["#rows"] = "2";
$element["address_line2"]["#access"] = FALSE;
return $element;
}
}
<?php
namespace Drupal\salesforce_address\Plugin\Field\FieldWidget;
use Drupal\address\Plugin\Field\FieldWidget\AddressDefaultWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
/**
* Changes the 'address_default' widget so it uses a different type.
*
* @FieldWidget(
* id = "salesforce_ready_address",
* label = @Translation("Salesforce-ready Address"),
* field_types = {
* "address"
* },
* )
*/
class AddressDefaultWidgetStreetAsTextArea extends AddressDefaultWidget {
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = parent::formElement($items, $delta, $element, $form, $form_state);
$element['address']['#type'] = 'address_street_as_textarea';
return $element;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment