diff --git a/modules/pca_address/src/Element/PcaAddress.php b/modules/pca_address/src/Element/AddressPcaAddress.php similarity index 98% rename from modules/pca_address/src/Element/PcaAddress.php rename to modules/pca_address/src/Element/AddressPcaAddress.php index a7ba539..78cee2d 100644 --- a/modules/pca_address/src/Element/PcaAddress.php +++ b/modules/pca_address/src/Element/AddressPcaAddress.php @@ -12,12 +12,12 @@ use Drupal\pca_address\Form\PcaAddressSettingsForm; /** - * Provides a PCA address form element. + * Provides an advanced PCA address form element. * * Usage example: * @code * $form['address'] = [ - * '#type' => 'pca_address', + * '#type' => 'pca_address_advanced', * '#pca_fields' => [ * [ * 'element' => PcaAddressElement::ADDRESS_LOOKUP, @@ -43,9 +43,9 @@ * * @see \Drupal\address\Element\Address * - * @FormElement("pca_address") + * @FormElement("pca_address_advanced") */ -class PcaAddress extends Address { +class AddressPcaAddress extends Address { /** * {@inheritdoc} diff --git a/modules/pca_address/src/Plugin/Field/FieldWidget/PcaAddressWidget.php b/modules/pca_address/src/Plugin/Field/FieldWidget/AddressPcaAddressWidget.php similarity index 93% rename from modules/pca_address/src/Plugin/Field/FieldWidget/PcaAddressWidget.php rename to modules/pca_address/src/Plugin/Field/FieldWidget/AddressPcaAddressWidget.php index d82f76a..1a49f77 100644 --- a/modules/pca_address/src/Plugin/Field/FieldWidget/PcaAddressWidget.php +++ b/modules/pca_address/src/Plugin/Field/FieldWidget/AddressPcaAddressWidget.php @@ -7,17 +7,17 @@ use Drupal\Core\Form\FormStateInterface; /** - * Plugin implementation of the 'pca_address' widget. + * Plugin implementation of the 'pca_address_advanced' widget. * * @FieldWidget( - * id = "pca_address", + * id = "pca_address_advanced", * label = @Translation("PCA Address"), * field_types = { * "address" * }, * ) */ -class PcaAddressWidget extends AddressDefaultWidget { +class AddressPcaAddressWidget extends AddressDefaultWidget { /** * {@inheritdoc} @@ -88,7 +88,7 @@ public function formElement(FieldItemListInterface $items, $delta, array $elemen $element = parent::formElement($items, $delta, $element,$form, $form_state); $widget_settings = $this->getSettings(); // Override to PCA address variant. - $element['address']['#type'] = 'pca_address'; + $element['address']['#type'] = 'pca_address_advanced'; // Set field mapping settings. $element['address']['#pca_fields'] = $widget_settings['pca_fields']; // Set options settings. diff --git a/src/Element/LoqatePcaAddress.php b/src/Element/LoqatePcaAddress.php new file mode 100644 index 0000000..394feec --- /dev/null +++ b/src/Element/LoqatePcaAddress.php @@ -0,0 +1,51 @@ + 'pca_address', + * '#pca_fields' => [ + * [ + * 'element' => PcaAddressElement::ADDRESS_LOOKUP, + * ], + * [ + * 'element' => PcaAddressElement::LINE1, + * 'field' => PcaAddressField::LINE1, + * 'mode' => PcaAddressMode::POPULATE, + * ], + * ... + * ], + * '#pca_options' => [ + * 'key' => config_key_id, // Defaults to key from config. + * 'countries' => ['codesList' => 'USA,CAN'], + * 'setCountryByIP' => false, + * ... + * ], + * '#show_address_fields' => FALSE, + * '#allow_manual_input' => TRUE, + * ... + * ]; + * @endcode + * + * @FormElement("pca_address") + */ +class LoqatePcaAddress extends FormElement { + + /** + * {@inheritdoc} + */ + public function getInfo() { + $class = get_class($this); + return [ + + ]; + } + +} diff --git a/src/Plugin/Field/FieldType/LoqatePcaAddressItem.php b/src/Plugin/Field/FieldType/LoqatePcaAddressItem.php new file mode 100644 index 0000000..dc381c7 --- /dev/null +++ b/src/Plugin/Field/FieldType/LoqatePcaAddressItem.php @@ -0,0 +1,97 @@ +setLabel(new TranslatableMarkup('Address Line 1')); + + $properties[PcaAddressElement::LINE2] = DataDefinition::create('string') + ->setLabel(new TranslatableMarkup('Address Line 2')); + + $properties[PcaAddressElement::LOCALITY] = DataDefinition::create('string') + ->setLabel(new TranslatableMarkup('City/Town')); + + $properties[PcaAddressElement::ADMINISTRATIVE_AREA] = DataDefinition::create('string') + ->setLabel(new TranslatableMarkup('State/Province')); + + $properties[PcaAddressElement::POSTAL_CODE] = DataDefinition::create('string') + ->setLabel(new TranslatableMarkup('ZIP/Postal Code')); + + $properties[PcaAddressElement::COUNTRY_CODE] = DataDefinition::create('string') + ->setLabel(new TranslatableMarkup('Country')); + + return $properties; + } + + /** + * {@inheritdoc} + */ + public static function schema(FieldStorageDefinitionInterface $field_definition) { + + $schema['columns'][PcaAddressElement::LINE1] = [ + 'type' => 'varchar', + 'length' => 255, + 'default' => NULL, + ]; + + $schema['columns'][PcaAddressElement::LINE2] = [ + 'type' => 'varchar', + 'length' => 255, + 'default' => NULL, + ]; + + $schema['columns'][PcaAddressElement::LOCALITY] = [ + 'type' => 'varchar', + 'length' => 255, + 'default' => NULL, + ]; + + $schema['columns'][PcaAddressElement::ADMINISTRATIVE_AREA] = [ + 'type' => 'varchar', + 'length' => 255, + 'default' => NULL, + ]; + + $schema['columns'][PcaAddressElement::POSTAL_CODE] = [ + 'type' => 'varchar', + 'length' => 255, + 'default' => NULL, + ]; + + $schema['columns'][PcaAddressElement::COUNTRY_CODE] = [ + 'type' => 'varchar', + 'length' => 255, + 'default' => NULL, + ]; + + return $schema; + } + +}