Skip to content
Snippets Groups Projects
Commit b8da1aac authored by Ilias Dimopoulos's avatar Ilias Dimopoulos
Browse files

Merge branch 'ISAICP-7684' into 'master'

ISAICP-7684: Ensure all items in the OG menu are displayed.

See merge request !95
parents 97786ac5 23ed87c6
No related branches found
Tags v1.91.1
1 merge request!95ISAICP-7684: Ensure all items in the OG menu are displayed.
......@@ -138,9 +138,9 @@ Feature: Navigation menu for custom pages
| state | validated |
And custom_page content:
| title | body | collection |
| Molds for walls | This is a sample body. | Plaster molds |
| Molds for crafts | This is a sample body. | Plaster molds |
| Molds for pottery | This is a sample body. | Plaster molds |
| Molds for walls | This is a sample body. | Plaster molds |
# A menu with 6 items is displayed normally
When I go to the "Plaster molds" collection
Then I should see the link "Molds for pottery" in the "Navigation menu"
......@@ -150,12 +150,13 @@ Feature: Navigation menu for custom pages
Given custom_page content:
| title | body | collection |
| Vintage molds | This is a sample body. | Plaster molds |
| Plaster casting | This is a sample body. | Plaster molds |
When I go to the "Plaster molds" collection
Then I should see the text "See more" in the "Navigation menu"
But I should not see the text "Plaster casting" in the "Navigation menu"
And I press "See more"
Then I should see the text "Plaster casting" in the "Navigation menu"
But I should not see the text "Molds for walls" in the "Navigation menu"
And I should not see the text "Vintage molds" in the "Navigation menu"
Then I press "See more"
And I should see the text "Molds for walls" in the "Navigation menu"
And I should see the text "Vintage molds" in the "Navigation menu"
@javascript
Scenario Outline: The contextual links button in the navigation menu should be always visible
......
This diff is collapsed.
......@@ -8,7 +8,6 @@
declare(strict_types = 1);
use Drupal\Core\Site\Settings;
use Drupal\sparql_entity_storage\UriEncoder;
use Drupal\user\Entity\User;
/**
......@@ -93,62 +92,3 @@ function joinup_core_requirements($phase): array {
return $requirements;
}
/**
* Fix group OG menu links.
*/
function joinup_core_update_109100(?array &$sandbox = NULL): string {
$menu_link_content_storage = \Drupal::entityTypeManager()->getStorage('menu_link_content');
$uri = [
'Overview' => 'entity:rdf_entity/%s',
'About' => 'route:entity.rdf_entity.about_page;rdf_entity=%s',
'Members' => 'route:entity.rdf_entity.member_overview;rdf_entity=%s',
'Glossary' => 'route:entity.rdf_entity.glossary;letter=&rdf_entity=%s',
];
if (!isset($sandbox['ids'])) {
$query = $menu_link_content_storage->getQuery()->accessCheck(FALSE);
// The following condition is a safety net in the case when some custom
// pages are using the standard labels ('Overview', 'About', etc).
$safety_net = ($query->orConditionGroup())
->condition('link.uri', 'route:collection.glossary_page', 'STARTS_WITH')
->condition('link.uri', 'route:entity.rdf_entity.about_page', 'STARTS_WITH')
->condition('link.uri', 'route:entity.rdf_entity.member_overview', 'STARTS_WITH')
->condition('link.uri', 'route:entity.rdf_entity.canonical', 'STARTS_WITH')
->condition('link.uri', 'entity:rdf_entity/', 'STARTS_WITH');
$sandbox['ids'] = array_values($query
->condition('menu_name', 'ogmenu-', 'STARTS_WITH')
->condition('title', ['Overview', 'About', 'Members', 'Glossary'], 'IN')
->condition($safety_net)
->execute());
$sandbox['og_menu'] = \Drupal::database()->query("SELECT entity_id, og_audience_target_id FROM {ogmenu_instance__og_audience}")->fetchAllKeyed();
$sandbox['total'] = count($sandbox['ids']);
$sandbox['progress'] = 0;
$sandbox['links_to_delete'] = [];
}
$ids = array_splice($sandbox['ids'], 0, 50);
/** @var \Drupal\menu_link_content\MenuLinkContentInterface $menu_link */
foreach ($menu_link_content_storage->loadMultiple($ids) as $menu_link) {
$og_menu_instance_id = str_replace('ogmenu-', '', $menu_link->getMenuName());
$group_id = $sandbox['og_menu'][$og_menu_instance_id] ?? NULL;
if ($group_id) {
// Fix the link URI.
$menu_link->link->uri = sprintf($uri[$menu_link->getTitle()], UriEncoder::encodeUrl($group_id));
$menu_link->save();
continue;
}
// Collect orphan links to be deleted on finish.
$sandbox['links_to_delete'][] = $menu_link->id();
}
$sandbox['progress'] += count($ids);
$sandbox['#finished'] = (int) empty($sandbox['ids']);
if ($sandbox['#finished'] === 1 && $sandbox['links_to_delete']) {
$menu_link_content_storage->delete($menu_link_content_storage->loadMultiple($sandbox['links_to_delete']));
}
return "Processed {$sandbox['progress']} out of {$sandbox['total']} menu links";
}
......@@ -14,64 +14,3 @@
*/
declare(strict_types = 1);
use Drupal\contact_information\ContactInformationEmailConfirmInterface;
use Drupal\email_confirmer\EmailConfirmationInterface;
/**
* Clean up the email confirmations.
*/
function joinup_core_post_update_109100(array &$sandbox): string {
if (empty($sandbox['emails'])) {
// Select email confirmations from the email_confirmation table, that has
// the status to 1, with the same `realm` where there are more than one
// confirmed confirmations. Return the `email` column to load the
// confirmations by it.
$query = \Drupal::database()->select('email_confirmer_confirmation', 'ec')
->fields('ec', ['email'])
->condition('ec.status', 1)
->condition('ec.confirmed', 1)
->condition('ec.realm', ContactInformationEmailConfirmInterface::REALM)
->groupBy('ec.email')
->having('COUNT(ec.email) > 1');
$sandbox['emails'] = $query->execute()->fetchCol();
$sandbox['current'] = 0;
$sandbox['total'] = count($sandbox['emails']);
}
$limit = 50;
$emails = array_slice($sandbox['emails'], $sandbox['current'], $limit);
$sandbox['current'] += count($emails);
$email_confirmer = \Drupal::getContainer()->get('email_confirmer');
foreach ($emails as $email) {
$email_confirmations = $email_confirmer->getConfirmations($email, EmailConfirmationInterface::CONFIRMED, 0, ContactInformationEmailConfirmInterface::REALM);
// Failsafe check.
if (count($email_confirmations) <= 1) {
throw new \Exception('Attempt to run this on a single confirmation.');
}
// Prepare for deletion only the confirmations with IP set to '127.0.0.1'.
$email_confirmations_to_delete = array_filter($email_confirmations, function (EmailConfirmationInterface $email_confirmation): bool {
return $email_confirmation->getIp() === '127.0.0.1';
});
// If the number of confirmations to delete is the same as the initial
// confirmations, then keep the first one. Otherwise, delete all of them.
// This is to ensure that if our code created more than one confirmation
// but the user did not create one manually, then still keep one so that
// the email is confirmed.
if (count($email_confirmations_to_delete) === count($email_confirmations)) {
array_shift($email_confirmations_to_delete);
}
// Delete the confirmations.
foreach ($email_confirmations_to_delete as $email_confirmation) {
$email_confirmation->delete();
}
}
$sandbox['#finished'] = empty($sandbox['emails']) ? 1 : ($sandbox['current'] / $sandbox['total']);
return "Cleaned up {$sandbox['current']} email confirmations.";
}
......@@ -17,7 +17,7 @@
{{ item.attributes.setAttribute('title', item.title) }}
{% endset %}
{% endfor %}
{# A menu with 6 items or less is displayed normally #}
{% if items|length < 7 %}
{% set menu = pattern('navigation', {
'variant': 'tabs',
......@@ -34,9 +34,11 @@
</div>
</div>
</div>
{# A menu with more than 6 items has the first 5 displayed normally
Then the rest of items is wrapped in a dropdown #}
{% else %}
{% set items_to_show = items|slice(0, 5) %}
{% set items_to_hide = items|slice(6) %}
{% set items_to_hide = items|slice(5) %}
{% set show_more_button %}
{{ pattern('button', {
label: 'See more'|t,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment