Add token for administrative_area name

Created on 10 February 2020, almost 5 years ago
Updated 5 February 2024, 10 months ago

There is currently no token support for administrative_area name e.g. "Colorado" vs. "CO". There have been various requests around this and an attempt to add additional tokens here: https://www.drupal.org/project/address/issues/2812659 → but is there any official work being done around this? The use case would be for example to create SEO optimized url path aliases, better keywords in Titles, etc...

Remaining tasks

  1. Break TokenReplacer->replaceTokens() into pieces so that it's actually readable, or do this in a follow-up issue.
✨ Feature request
Status

Needs review

Version

2.0

Component

Code

Created by

🇺🇸United States apmsooner

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • @emilymathew opened merge request.
  • 🇮🇳India emilymathew

    Hi,

    Thanks to @edisch. I love this feature of adding administrative area name token. It is really useful. The patch #9 worked for me only after adding additional brackets on the if condition. So I created a merge request based the on the patch in #9 with the tweak in if condition.

    <       if (
    <           $subdivision_code = $field_item->administrative_area
    <           && $country_code = $field_item->country_code
    <       ) {
    ---
    >       if (
    >           ($subdivision_code = $field_item->administrative_area)
    >           && ($country_code = $field_item->country_code)
    >       ) {

    See https://git.drupalcode.org/project/address/-/merge_requests/24.patch.

    I hope this will be useful for anyone who require the same feature.

    Thank you.

  • 🇮🇳India emilymathew

    Hi,

    For some countries administrative area(state/province) is a text field, not a select list (eg: American Samoa). In that case, fetching administrative area name from subdivision code will not work.

    I am uploading a patch to handle this case in addition to the fix mentioned in #14.

    Please ignore the above merge request 24 and use this patch instead.

    Thanks

  • 🇨🇦Canada colan Toronto 🇨🇦

    #15 works, but leaving as Needs Work because the code requires refactoring. That function is already unreadable (too long and too much nesting), and this patch makes that worse. Here's what I'd recommend:

    1. Create a new service.
    2. Jump into a service call directly from the hook implementation (to get out of procedural coding).
    3. Break it up into various protected methods so that they're short with descriptive names so that we have readable clean code with little or no nesting.
  • 🇨🇦Canada colan Toronto 🇨🇦

    That updates the MR with the patch in #15.

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    Patch Failed to Apply
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    Patch Failed to Apply
  • 🇨🇦Canada colan Toronto 🇨🇦

    I'm going to stop here for now. It might make sense to merge this, and then break up the method in a follow-up issue. Thoughts?

    Added remaining tasks to IS.

    If you're using 8.x-1.11 and not HEAD, you'll need the patch in #15 (until the next release).

  • 🇨🇦Canada colan Toronto 🇨🇦
  • 🇨🇦Canada colan Toronto 🇨🇦
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 5.7
    last update over 1 year ago
    Patch Failed to Apply
  • 🇨🇦Canada colan Toronto 🇨🇦

    Here's a more recent patch for Composer, which comes from the MR.

  • 🇨🇦Canada colan Toronto 🇨🇦

    Switching to new branch.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    30 pass
  • @colan opened merge request.
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    Patch Failed to Apply
  • 🇨🇦Canada colan Toronto 🇨🇦

    New MR & patch for 2.0.x branch.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    30 pass
  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update over 1 year ago
    30 pass
  • 🇨🇦Canada colan Toronto 🇨🇦

    Sorry, #24 was a bad patch.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.0 & MySQL 5.7
    last update 11 months ago
    41 pass
  • 🇦🇷Argentina tguerineau

    Hi,

    I'm providing an updated patch. This update is necessary due to the evolution of the 2.0.x branch since the last patch submission.

    Context and Rationale:

    The previous patch address-token_for_administrative_area-3112487-25.patch and the associated Merge Request were based on an older state of the 2.0.x branch. As a result, they could not be applied to the current branch due to significant changes that have occurred since then.
    To address this, I manually applied the changes from the old patch to the latest version of the 2.0.x branch and created a new patch reflecting these updates.

    Manual Testing:

    • Conducted thorough testing of the new administrative_area_name token. This included:
      Integrating the token [node:field_address:administrative_area_name] into the default meta tags for content descriptions.
    • Verifying token functionality on a node page with an address field.
    • Confirming the token's presence and correct description in the token list at /admin/help/token.
  • 🇧🇷Brazil rcsilvadev São Paulo, Brazil

    Same as above, except this is a patch for version 2.0.0.

  • 🇧🇷Brazil rcsilvadev São Paulo, Brazil

    Please disregard my comment above. Patch #26 works fine with version 2.0.0.

Production build 0.71.5 2024