Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
single_content_sync
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
single_content_sync
Commits
fedd76c0
Commit
fedd76c0
authored
1 year ago
by
Vadym Abramchuk
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3404115
: Support address_zone field type
parent
81ef4852
No related branches found
No related tags found
1 merge request
!100
Issue #3404115: Support address_zone field type
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Plugin/SingleContentSyncFieldProcessor/AddressZone.php
+70
-0
70 additions, 0 deletions
src/Plugin/SingleContentSyncFieldProcessor/AddressZone.php
with
70 additions
and
0 deletions
src/Plugin/SingleContentSyncFieldProcessor/AddressZone.php
0 → 100644
+
70
−
0
View file @
fedd76c0
<?php
namespace
Drupal\single_content_sync\Plugin\SingleContentSyncFieldProcessor
;
use
CommerceGuys\Addressing\Zone\Zone
;
use
CommerceGuys\Addressing\Zone\ZoneTerritory
;
use
Drupal\address\Plugin\Field\FieldType\ZoneItemList
;
use
Drupal\Core\Entity\FieldableEntityInterface
;
use
Drupal\Core\Field\FieldItemListInterface
;
use
Drupal\single_content_sync
\SingleContentSyncFieldProcessorPluginBase
;
/**
* Plugin implementation for metatag field processor plugin.
*
* @SingleContentSyncFieldProcessor(
* id = "address_zone",
* label = @Translation("Address Zone field processor"),
* field_type = "address_zone",
* )
*/
class
AddressZone
extends
SingleContentSyncFieldProcessorPluginBase
{
/**
* {@inheritdoc}
*/
public
function
exportFieldValue
(
FieldItemListInterface
$field
):
array
{
assert
(
$field
instanceof
ZoneItemList
);
$values
=
[];
foreach
(
$field
->
getValue
()
as
$delta
=>
$item
)
{
if
(
!
isset
(
$item
[
'value'
]))
{
continue
;
}
/** @var \CommerceGuys\Addressing\Zone\Zone $zone */
$zone
=
$item
[
'value'
];
$values
[
$delta
]
=
[
'id'
=>
$zone
->
getId
(),
'label'
=>
$zone
->
getLabel
(),
// Serialize ZoneTerritory objects to arrays.
'territories'
=>
array_map
(
function
(
ZoneTerritory
$territory
)
{
return
[
'country_code'
=>
$territory
->
getCountryCode
(),
'administrative_area'
=>
$territory
->
getAdministrativeArea
(),
'locality'
=>
$territory
->
getLocality
(),
'dependent_locality'
=>
$territory
->
getDependentLocality
(),
'included_postal_codes'
=>
$territory
->
getIncludedPostalCodes
(),
'excluded_postal_codes'
=>
$territory
->
getExcludedPostalCodes
(),
];
},
$zone
->
getTerritories
()),
];
}
return
$values
;
}
/**
* {@inheritdoc}
*/
public
function
importFieldValue
(
FieldableEntityInterface
$entity
,
string
$fieldName
,
array
$value
):
void
{
// @see \Drupal\address\Plugin\Field\FieldType\ZoneItem::setValue()
if
(
!
empty
(
$value
))
{
$entity
->
set
(
$fieldName
,
array_map
(
function
(
array
$zone
)
{
return
new
Zone
(
$zone
);
},
$value
));
}
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment