I would like to use the, provided by this module, field type Zone in an entity, and also being able to display this field.
However I do not see any field formatter for this field. Could you please add one?
Many thanks!

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

eldrupalista created an issue. See original summary.

aheredia’s picture

Added a default formatter

aheredia’s picture

Status: Active » Needs review
aheredia’s picture

Title: Add a defaul formatter for field type Zone » Add a default formatter for field type Zone
miksha’s picture

After applying this patch I am not getting more warning messages, and field settings for allowed number of values is still set to 1 with no options to configure. But when I populate fields I can add multiple number of values, not just one. I did rebuild cache after applying the patch.

bojanz’s picture

Status: Needs review » Needs work
  *   default_widget = "address_zone_default",
+ *   default_formatter = "zone_default",

The widget is address_zone_default, the field type is address zone, the formatter can't be zone_default, needs to also be prefixed with address_

+  /**
+   * Constructs an AddressDefaultFormatter object.
+   *

Wrong class name in docblock.

+  /**
+   * Generate the output appropriate for one field item.
+   *
+   * @param \Drupal\Core\Field\FieldItemInterface $item
+   *   One field item.
+   * @param string $langcode
+   *   The language that should be used to render the field.
+   *
+   * @return array
+   *   A renderable array.
+   */
+  protected function viewValue(FieldItemInterface $item, $langcode) {

Our other formatters call this method viewElement, let's do the same here. Also, let's pass a Zone object ($item->value).

+      if (!empty($administrative_area = $territory->getAdministrativeArea())) {

You don't need the !empty.

+        $element[$key]['dlocality'] = [
+          '#type' => 'html_tag',
+          '#tag' => 'span',
+          '#attributes' => ['class' => [$address_format->getDependentLocalityType()]],
+          '#value' => $dependent_locality,
+        ];

We shouldn't abbreviate element names. "dependent_locality", not "dlocality",
Also, dependent_locality should come after locality, not before.

+          '#type' => 'html_tag',
+          '#tag' => 'span',

Let's use the "item" type and give each element an appropriate label.

Also, we're not printing the zone label.

bojanz’s picture

Here's an updated patch.

  • bojanz committed a410156 on 8.x-1.x
    Issue #2996527 by aheredia, bojanz: Add a default formatter for field...
bojanz’s picture

Status: Needs review » Fixed

Let's proceed. We can open follow-up issues for any other zone bugs.

Thanks, everyone.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.