summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBojan Zivanovic2018-05-22 13:43:11 (GMT)
committerBojan Zivanovic2018-05-22 13:44:04 (GMT)
commit345dbaa578fa03f864fc2e9599455699bd60dc89 (patch)
tree4827257aa8a9ea67099827a35f8fe2d64847a26c
parent45c2d9a84eb3d7dc1637a866aba4fd3af22276c7 (diff)
Issue #2954927 by jsacksick, bojanz: Add a display_name setting to the Subdivision views field
-rw-r--r--config/schema/address.schema.yml16
-rw-r--r--src/Plugin/views/field/CountryCode.php2
-rw-r--r--src/Plugin/views/field/Subdivision.php28
3 files changed, 42 insertions, 4 deletions
diff --git a/config/schema/address.schema.yml b/config/schema/address.schema.yml
index d5a9923..abc39d3 100644
--- a/config/schema/address.schema.yml
+++ b/config/schema/address.schema.yml
@@ -157,6 +157,22 @@ field.widget.settings.address_zone_default:
type: boolean
label: 'Show the zone label field'
+views.field.country_code:
+ type: views_field
+ label: 'Country code'
+ mapping:
+ display_name:
+ type: boolean
+ label: 'Display the country name instead of the country code'
+
+views.field.subdivision:
+ type: views_field
+ label: 'Subdivision'
+ mapping:
+ display_name:
+ type: boolean
+ label: 'Display the subdivision name instead of the subdivision code'
+
views.filter.country_code:
type: views.filter.in_operator
label: 'Country'
diff --git a/src/Plugin/views/field/CountryCode.php b/src/Plugin/views/field/CountryCode.php
index 65adb1e..2e1fd95 100644
--- a/src/Plugin/views/field/CountryCode.php
+++ b/src/Plugin/views/field/CountryCode.php
@@ -70,7 +70,7 @@ class CountryCode extends FieldPluginBase {
public function buildOptionsForm(&$form, FormStateInterface $form_state) {
$form['display_name'] = [
'#type' => 'checkbox',
- '#title' => $this->t('Display the localized country name instead of the two character country code'),
+ '#title' => $this->t('Display the country name instead of the country code'),
'#default_value' => !empty($this->options['display_name']),
];
parent::buildOptionsForm($form, $form_state);
diff --git a/src/Plugin/views/field/Subdivision.php b/src/Plugin/views/field/Subdivision.php
index 87cfaa6..503d76b 100644
--- a/src/Plugin/views/field/Subdivision.php
+++ b/src/Plugin/views/field/Subdivision.php
@@ -4,6 +4,7 @@ namespace Drupal\address\Plugin\views\field;
use CommerceGuys\Addressing\Locale;
use CommerceGuys\Addressing\Subdivision\SubdivisionRepositoryInterface;
+use Drupal\Core\Form\FormStateInterface;
use Drupal\views\Plugin\views\field\FieldPluginBase;
use Drupal\views\ResultRow;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -57,10 +58,32 @@ class Subdivision extends FieldPluginBase {
/**
* {@inheritdoc}
*/
+ protected function defineOptions() {
+ $options = parent::defineOptions();
+ $options['display_name'] = ['default' => TRUE];
+
+ return $options;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+ $form['display_name'] = [
+ '#type' => 'checkbox',
+ '#title' => $this->t('Display the subdivision name instead of the subdivision code'),
+ '#default_value' => !empty($this->options['display_name']),
+ ];
+ parent::buildOptionsForm($form, $form_state);
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function render(ResultRow $values) {
$value = $this->getValue($values);
- if (empty($value)) {
- return '';
+ if (empty($value) || empty($this->options['display_name'])) {
+ return $this->sanitizeValue($value);
}
$entity = $this->getEntity($values);
@@ -93,7 +116,6 @@ class Subdivision extends FieldPluginBase {
}
/** @var \CommerceGuys\Addressing\Subdivision\Subdivision $subdivision */
$subdivision = $this->subdivisionRepository->get($code, $parents);
- // @todo Allow a choice between subdivision code and name.
if ($subdivision) {
$use_local_name = Locale::matchCandidates($address->getLocale(), $subdivision->getLocale());
$value = $use_local_name ? $subdivision->getLocalName() : $subdivision->getName();