Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cvd to the settings > address fields layout #16446

Merged
merged 4 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-WIP.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
- Added the “Palette” setting to Color fields, which replaces “Presets”. ([#16249](https://github.com/craftcms/cms/pull/16249))
- Added the “Allow custom colors” setting to Color fields. ([#16249](https://github.com/craftcms/cms/pull/16249))
- Added the “Field” entry condition rule, which replaces “Matrix field”, includes a “has a value” operator. ([#16270](https://github.com/craftcms/cms/discussions/16270))
- Added a card view designer for addresses. ([#16446](https://github.com/craftcms/cms/pull/16446))
- It’s now possible to view (but not edit) system and plugin settings on environments where `allowAdminChanges` is disabled. ([#16265](https://github.com/craftcms/cms/pull/16265))
- Section condition rules now have a “has a value” operator. ([#16270](https://github.com/craftcms/cms/discussions/16270))
- Added “Copy plugin handle” and “Copy package name” options to plugins’ action menus on the Plugins index page. ([#16281](https://github.com/craftcms/cms/discussions/16281))
Expand Down
30 changes: 30 additions & 0 deletions src/fieldlayoutelements/addresses/AddressField.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ protected function showLabel(): bool
return false;
}

/**
* @inheritdoc
*/
protected function defaultLabel(?ElementInterface $element = null, bool $static = false): ?string
{
// we need it for the card view designer
return Craft::t('app', 'Address');
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -196,4 +205,25 @@ protected function inputHtml(?ElementInterface $element = null, bool $static = f
// Not actually needed since we're overriding formHtml()
return null;
}

/**
* @inheritdoc
*/
public function previewPlaceholderHtml(mixed $value, ?ElementInterface $element): string
{
if ($element instanceof Address) {
return $this->previewHtml($element);
} else {
$address = new Address([
'countryCode' => 'US',
'administrativeArea' => 'AK',
'addressLine1' => 'Address Line 1',
'locality' => 'Some City',
'postalCode' => '12345',
]);
return Html::tag('div', Craft::$app->getAddresses()->formatAddress($address), [
'class' => 'no-truncate',
]);
}
}
}
18 changes: 18 additions & 0 deletions src/fieldlayoutelements/addresses/CountryCodeField.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace craft\fieldlayoutelements\addresses;

use CommerceGuys\Addressing\Country\Country;
use Craft;
use craft\base\ElementInterface;
use craft\elements\Address;
Expand Down Expand Up @@ -113,4 +114,21 @@ protected function inputHtml(?ElementInterface $element = null, bool $static = f
]) .
Html::endTag('div');
}

/**
* @inheritdoc
*/
public function previewPlaceholderHtml(mixed $value, ?ElementInterface $element): string
{
if (!$value) {
$countries = Craft::$app->getAddresses()->getCountryRepository()->getList(Craft::$app->language);
$value = $countries['US'];
} else {
if ($value instanceof Country) {
$value = $value->getName();
}
}

return $value;
}
}
21 changes: 21 additions & 0 deletions src/fieldlayoutelements/addresses/LatLongField.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ protected function showLabel(): bool
return false;
}

/**
* @inheritdoc
*/
protected function defaultLabel(?ElementInterface $element = null, bool $static = false): ?string
{
// we need it for the card view designer
return Craft::t('app', 'Latitude/Longitude');
}

/**
* @inheritdoc
*/
Expand Down Expand Up @@ -150,4 +159,16 @@ protected function errors(?ElementInterface $element = null): array
}
return array_merge($element->getErrors('latitude'), $element->getErrors('longitude'));
}

/**
* @inheritdoc
*/
public function previewPlaceholderHtml(mixed $value, ?ElementInterface $element): string
{
if ($element) {
return $this->previewHtml($element);
}

return '61.108, -149.779';
}
}
1 change: 1 addition & 0 deletions src/templates/settings/addresses/_fields.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
{{ forms.fieldLayoutDesignerField({
first: true,
fieldLayout: fieldLayout ?? craft.app.addresses.getFieldLayout(),
withCardViewDesigner: true,
}) }}

<div class="buttons">
Expand Down