Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Postcode.php
Go to the documentation of this file.
1 <?php
7 
10 use Magento\Directory\Helper\Data as DirectoryHelper;
12 use Psr\Log\LoggerInterface as PsrLogger;
14 
18 class Postcode extends AbstractData
19 {
23  protected $directoryHelper;
24 
35  public function __construct(
36  MagentoTimezone $localeDate,
37  PsrLogger $logger,
39  ResolverInterface $localeResolver,
40  $value,
42  $isAjax,
43  DirectoryHelper $directoryHelper
44  ) {
45  $this->directoryHelper = $directoryHelper;
46  parent::__construct(
47  $localeDate,
48  $logger,
49  $attribute,
50  $localeResolver,
51  $value,
53  $isAjax
54  );
55  }
56 
64  public function validateValue($value)
65  {
66  $attribute = $this->getAttribute();
67  $label = __($attribute->getStoreLabel());
68 
69  $countryId = $this->getExtractedData('country_id');
70  if ($this->directoryHelper->isZipCodeOptional($countryId)) {
71  return true;
72  }
73 
74  $errors = [];
75  if (empty($value) && $value !== '0') {
76  $errors[] = __('"%1" is a required value.', $label);
77  }
78  if (count($errors) == 0) {
79  return true;
80  }
81  return $errors;
82  }
83 
87  public function extractValue(\Magento\Framework\App\RequestInterface $request)
88  {
89  return $this->_applyInputFilter($this->_getRequestValue($request));
90  }
91 
95  public function compactValue($value)
96  {
97  return $value;
98  }
99 
103  public function restoreValue($value)
104  {
105  return $this->compactValue($value);
106  }
107 
112  {
113  return $this->_applyOutputFilter($this->_value);
114  }
115 }
__construct(MagentoTimezone $localeDate, PsrLogger $logger, AttributeMetadataInterface $attribute, ResolverInterface $localeResolver, $value, $entityTypeCode, $isAjax, DirectoryHelper $directoryHelper)
Definition: Postcode.php:35
__()
Definition: __.php:13
$logger
_getRequestValue(\Magento\Framework\App\RequestInterface $request)
$label
Definition: details.phtml:21
$value
Definition: gender.phtml:16
$format
Definition: list.phtml:12
outputValue($format=ElementFactory::OUTPUT_FORMAT_TEXT)
Definition: Postcode.php:111
$errors
Definition: overview.phtml:9
extractValue(\Magento\Framework\App\RequestInterface $request)
Definition: Postcode.php:87