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

DP-35243: Add primary location to right column of location page #2705

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
41 changes: 41 additions & 0 deletions changelogs/DP-35243.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Write your changelog entry here. Every pull request must have a changelog yml file.
#
# Change types:
# #############################################################################
# You can use one of the following types:
# - Added: For new features.
# - Changed: For changes to existing functionality.
# - Deprecated: For soon-to-be removed features.
# - Removed: For removed features.
# - Fixed: For any bug fixes.
# - Security: In case of vulnerabilities.
#
# Format
# #############################################################################
# The format is crucial. Please follow the examples below. For reference, the requirements are:
# - All 3 parts are required and you must include "Type", "description" and "issue".
# - "Type" must be left aligned and followed by a colon.
# - "description" must be indented with 2 spaces followed by a colon
# - "issue" must be indented with 4 spaces followed by a colon.
# - "issue" is for the Jira ticket number only e.g. DP-1234
# - No extra spaces, indents, or blank lines are allowed.
#
# Example:
# #############################################################################
# Fixed:
# - description: Fixes scrolling on edit pages in Safari.
# issue: DP-13314
#
# You may add more than 1 description & issue for each type using the following format:
# Changed:
# - description: Automating the release branch.
# issue: DP-10166
# - description: Second change item that needs a description.
# issue: DP-19875
# - description: Third change item that needs a description along with an issue.
# issue: DP-19843
#
Added:
- description: Add primary location to right column of location page.
issue: DP-35243
30 changes: 30 additions & 0 deletions docroot/modules/custom/mayflower/src/Prepare/Organisms.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Drupal\Core\Cache\Cache;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\mass_content\Entity\Bundle\node\LocationBundle;
use Drupal\mass_content_moderation\MassModeration;
use Drupal\mayflower\Helper;
use Drupal\node\Entity\Node;
Expand Down Expand Up @@ -119,11 +120,40 @@ public static function prepareSidebarContact($entity, array $options = [], array
],
];

// In case this is a location bundle we include Primary contact as well.
if ($entity instanceof LocationBundle) {
$map['contact_info'] = ['field_ref_contact_info_1'];
}
// Determines which field names to use from the map.
$fields = Helper::getMappedFields($entity, $map);

$ref_items = Helper::getReferencedEntitiesFromField($entity, $fields['items']);

// Include Primary contact if this is a location bundle.
if (!empty($fields['contact_info'])) {
$ref_primary_contact_info = Helper::getReferencedEntitiesFromField($entity, $fields['contact_info']);

if (!empty($ref_primary_contact_info)) {
// Map of reference fields.
$reference_map = [
'address' => 'field_ref_address',
'phone' => 'field_ref_phone_number',
'online' => 'field_ref_links',
'fax' => 'field_ref_fax_number',
];

foreach ($ref_primary_contact_info as $contact_info) {
// Filter out populated fields for the current contact info.
$available_fields = array_filter($reference_map, fn($field) => Helper::isFieldPopulated($contact_info, $field));

// Merge references if more than one field is available.
if (count($available_fields) > 1) {
$ref_items = array_merge([$contact_info], $ref_items);
}
}
}
}

foreach ($ref_items as $item) {
// Get entity cache tags.
$cache_tags = array_merge($cache_tags, $item->getCacheTags());
Expand Down