Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.x' into update-2.x-with-2.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
imanoleguskiza committed Jul 7, 2021
2 parents 0109030 + 6e0635c commit fd21ba6
Show file tree
Hide file tree
Showing 12 changed files with 297 additions and 28 deletions.
23 changes: 22 additions & 1 deletion js/inpage_navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
*
* @prop {Drupal~behaviorAttach} attach
* Attaches the inpage navigation behaviors.
* @prop {Drupal~behaviorAttach} detach
* Detaches the inpage navigation behaviors.
*/
Drupal.behaviors.eclInPageNavigation = {
attach: function attach(context, settings) {
Expand Down Expand Up @@ -59,14 +61,26 @@
items_markup += Drupal.theme('oe_theme_inpage_navigation_item', element.getAttribute('id'), title);
});

Array.prototype.forEach.call(document.querySelectorAll('[data-ecl-inpage-navigation]'), function (block) {
// Loop through all the inpage navigation marked with our special class. The auto-initialisation is disabled on
// them, as initialisation should be run only after the items are added. Otherwise JS callbacks won't be applied
// correctly.
Array.prototype.forEach.call(document.querySelectorAll('.oe-theme-ecl-inpage-navigation'), function (block) {
if (items_markup.length === 0) {
// When there are no items, execute the callback to handle the block.
Drupal.eclInPageNavigation.handleEmptyInpageNavigation(block);
return;
}

block.querySelector('ul').innerHTML = items_markup;
var instance = new ECL.InpageNavigation(block);
instance.init();
Drupal.eclInPageNavigation.instances.push(instance);
})
},
detach: function detach(context, settings, trigger) {
Drupal.eclInPageNavigation.instances.forEach(function (instance){
instance.destroy();
});
}
};

Expand All @@ -84,6 +98,13 @@
*/
seenIds: {},

/**
* A list of initialized ECL InPageNavigation instances.
*
* @type {Array}
*/
instances: [],

/**
* Generates a unique slug from a text string.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@
*/
#}
{% block navigation %}
{# We add the extra attribute to guarantee the component is not auto initialized. #}
{% include '@ecl-twig/inpage-navigation' with {
'title': title,
'icon_path': ecl_icon_path,
'extra_classes': 'oe-theme-ecl-inpage-navigation',
'extra_attributes': [
{
'name': 'data-ecl-auto-initialized',
'value': 'true'
}
]
} %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: OpenEuropa Theme Paragraphs Contact
type: module
description: Companion module for the OE Paragraphs Contact module
package: OpenEuropa
core: 8.x
dependencies:
- oe_paragraphs:oe_paragraphs_contact
- oe_theme:oe_theme_content_entity_contact
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/**
* @file
* Install hooks for OpenEuropa Theme Paragraphs Contact module.
*/

declare(strict_types = 1);

use Drupal\Core\Entity\Entity\EntityViewDisplay;

/**
* Implements hook_install().
*
* Sets contacts rendering to use the full view mode.
*/
function oe_theme_paragraphs_contact_install($is_syncing) {
// If we are installing from config, we bail out.
if ($is_syncing) {
return;
}
$entity_view_display = EntityViewDisplay::load('paragraph.oe_contact.default');
$contacts = $entity_view_display->getComponent('field_oe_contacts');
$contacts['settings']['view_mode'] = 'full';
$entity_view_display->setComponent('field_oe_contacts', $contacts);
$entity_view_display->save();
}
9 changes: 9 additions & 0 deletions oe_theme.theme
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ function oe_theme_preprocess_input__date(array &$variables): void {
$variables['placeholder'] = $ecl_format;
}

/**
* Implements template_preprocess_input__submit().
*/
function oe_theme_preprocess_input__submit(array &$variables): void {
if (isset($variables['element']['#button_type'])) {
$variables['variant'] = $variables['element']['#button_type'];
}
}

/**
* Helper function to additionally preprocess checkbox and radio elements.
*
Expand Down
1 change: 1 addition & 0 deletions runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ drupal:
- "./vendor/bin/drush en oe_theme_content_organisation_reference -y"
- "./vendor/bin/drush en oe_theme_content_person -y"
- "./vendor/bin/drush en oe_theme_contact_forms -y"
- "./vendor/bin/drush en oe_theme_paragraphs_contact -y"
- "./vendor/bin/drush en field_ui -y"
- "./vendor/bin/drush en config_devel -y"
- "./vendor/bin/drush en toolbar -y"
Expand Down
2 changes: 1 addition & 1 deletion templates/form/input--submit.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

{% include '@ecl-twig/button' with {
label: attributes.value,
variant: 'primary',
variant: variant|default('primary'),
extra_attributes: extraAttributes
} %}
15 changes: 15 additions & 0 deletions templates/paragraphs/paragraph--oe-contact.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

{#
/**
* @file
* Theme override to display the Contact paragraph type.
*
* @see ./modules/contrib/paragraphs/templates/paragraph.html.twig
*/
#}
{% if not paragraph.field_oe_title.isEmpty() %}
<h2 class="ecl-u-type-heading-2">
{{ content.field_oe_title }}
</h2>
{% endif %}
{{ content.field_oe_contacts }}
55 changes: 31 additions & 24 deletions templates/patterns/gallery/pattern-gallery.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{% set _items = _items|merge([_item]) %}
{% endfor %}

{% include '@ecl-twig/gallery' with {
{% set _gallery = {
'overlay': {
'counter_separator': ' / ',
'close': {
Expand All @@ -32,29 +32,6 @@
'size': 's',
},
},
'previous': {
'variant': 'ghost',
'label': 'Previous'|t,
'icon': {
'path': ecl_icon_path,
'type': 'ui',
'name': 'corner-arrow',
'transform': 'rotate-270',
'size': 'l',
},
'icon_position': 'before',
},
'next': {
'variant': 'ghost',
'label': 'Next'|t,
'icon': {
'path': ecl_icon_path,
'type': 'ui',
'name': 'corner-arrow',
'transform': 'rotate-90',
'size': 'l',
},
},
'download': {
'link': {
'label': 'Download'|t,
Expand Down Expand Up @@ -86,3 +63,33 @@
'counter_label': "media items"|t,
'items': _items
} %}

{% if _items|length > 1 %}
{% set _gallery = _gallery|merge({'overlay': _gallery.overlay|merge({
'previous': {
'variant': 'ghost',
'label': 'Previous'|t,
'icon': {
'path': ecl_icon_path,
'type': 'ui',
'name': 'corner-arrow',
'transform': 'rotate-270',
'size': 'l',
},
'icon_position': 'before',
},
'next': {
'variant': 'ghost',
'label': 'Next'|t,
'icon': {
'path': ecl_icon_path,
'type': 'ui',
'name': 'corner-arrow',
'transform': 'rotate-90',
'size': 'l',
},
},
})}) %}
{% endif %}

{% include '@ecl-twig/gallery' with _gallery %}
2 changes: 1 addition & 1 deletion tests/Functional/ParagraphsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testAccordionItemParagraph(): void {
'title[0][value]' => 'Test Accordion',
'field_oe_demo_body[0][subform][field_oe_paragraphs][0][subform][field_oe_text][0][value]' => 'Accordion item title',
'field_oe_demo_body[0][subform][field_oe_paragraphs][0][subform][field_oe_text_long][0][value]' => 'Accordion item body',
'oe_content_content_owner[0][target_id]' => 'Directorate-General for Informatics',
'oe_content_content_owner[0][target_id]' => 'Committee on Agriculture and Rural Development',
];
$this->drupalPostForm(NULL, $values, 'Save');
$this->drupalGet('/node/1');
Expand Down
157 changes: 157 additions & 0 deletions tests/Kernel/Paragraphs/ContactParagraphTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
<?php

declare(strict_types = 1);

namespace Drupal\Tests\oe_theme\Kernel\Paragraphs;

use Drupal\oe_content_entity\Entity\CorporateEntityInterface;
use Drupal\oe_content_entity_contact\Entity\Contact;
use Drupal\paragraphs\Entity\Paragraph;
use Drupal\user\Entity\Role;
use Drupal\user\RoleInterface;
use Symfony\Component\DomCrawler\Crawler;

/**
* Tests the rendering of the Contact paragraph.
*
* @group batch1
*/
class ContactParagraphTest extends ParagraphsTestBase {

/**
* {@inheritdoc}
*/
public static $modules = [
'field_group',
'address',
'composite_reference',
'inline_entity_form',
'media',
'oe_media',
'file_link',
'oe_content_entity_contact',
'oe_content_featured_media_field',
'oe_content_entity',
'oe_theme_content_entity_contact',
'oe_paragraphs_contact',
'oe_theme_paragraphs_contact',
];

/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();

$this->installEntitySchema('media');
$this->installEntitySchema('oe_contact');
$this->installConfig([
'composite_reference',
'oe_content_entity_contact',
'address',
'media',
'oe_media',
'oe_content_entity',
'oe_theme_content_entity_contact',
'oe_paragraphs_contact',
]);

module_load_include('install', 'media');
media_install();
$this->container->get('module_handler')->loadInclude('oe_theme_paragraphs_contact', 'install');
oe_theme_paragraphs_contact_install(FALSE);

Role::load(RoleInterface::ANONYMOUS_ID)
->grantPermission('view published oe_contact')
->save();
}

/**
* Test contact paragraph rendering.
*
* @throws \Drupal\Core\Entity\EntityStorageException
*/
public function testContact(): void {
// Create a media entity for contact.
$file = file_save_data(file_get_contents(drupal_get_path('theme', 'oe_theme') . '/tests/fixtures/example_1.jpeg'), 'public://example_1.jpeg');
$file->setPermanent();
$file->save();
$media = $this->container->get('entity_type.manager')->getStorage('media')->create([
'bundle' => 'image',
'name' => "Test image",
'oe_media_image' => [
'target_id' => (int) $file->id(),
'alt' => "Alternative text",
],
'uid' => 0,
'status' => 1,
]);
$media->save();
// Create general contact.
$general_contact = Contact::create([
'bundle' => 'oe_general',
'name' => 'General contact',
'oe_address' => [
'country_code' => 'BE',
'locality' => 'Brussels',
'address_line1' => 'Address of General contact',
'postal_code' => '1001',
],
'oe_body' => 'General contact body text',
'oe_email' => 'general@example.com',
'oe_organisation' => 'General contact Organisation',
'oe_social_media' => [
[
'uri' => 'http://www.example.com/facebook',
'title' => 'Facebook',
'link_type' => 'facebook',
],
],
'oe_image' => [
[
'target_id' => (int) $media->id(),
'caption' => "General contact media caption",
],
],
'status' => CorporateEntityInterface::PUBLISHED,
]);
$general_contact->save();
// Create press contact.
$press_contact = Contact::create([
'bundle' => 'oe_press',
'name' => 'Press contact',
'oe_body' => 'Press contact body text',
'status' => CorporateEntityInterface::PUBLISHED,
]);
$press_contact->save();
// Create contact paragraph.
$paragraph = Paragraph::create([
'type' => 'oe_contact',
'field_oe_contacts' => [$general_contact, $press_contact],
]);
$paragraph->save();
$html = $this->renderParagraph($paragraph);
$crawler = new Crawler($html);

// Assert paragraph heading markup is not rendered if no title is set.
$this->assertCount(0, $crawler->filter('h2.ecl-u-type-heading-2'));
// Assert rendering of the first contact.
$this->assertEquals('General contact', trim($crawler->filter('div.ecl-row.ecl-u-mv-xl:nth-child(1) h3.ecl-u-type-heading-3.ecl-u-mt-none div')->html()));
$this->assertEquals('<p>General contact body text</p>', trim($crawler->filter('div.ecl-col-md-6 div.ecl-u-mb-l:nth-child(1) div.ecl-editor')->html()));
$this->assertEquals('General contact Organisation', trim($crawler->filter('dl.ecl-description-list.ecl-description-list--horizontal:nth-child(2) dd.ecl-description-list__definition:nth-child(2) div')->html()));
$this->assertEquals('general@example.com', trim($crawler->filter('dl.ecl-description-list.ecl-description-list--horizontal:nth-child(2) dd.ecl-description-list__definition:nth-child(4) div a')->html()));
$this->assertEquals('Address of General contact, 1001 Brussels, Belgium', trim($crawler->filter('dl.ecl-description-list.ecl-description-list--horizontal:nth-child(2) dd.ecl-description-list__definition:nth-child(6) div span')->html()));
$this->assertEquals('Facebook', trim($crawler->filter('dl.ecl-description-list.ecl-description-list--horizontal:nth-child(2) dd.ecl-description-list__definition:nth-child(8) div div div a span')->html()));
$this->assertContains('example_1.jpeg', $crawler->filter('div.ecl-col-md-5 figure.ecl-media-container img')->attr('src'));
// Assert rendering of the second contact.
$this->assertEquals('Press contact', trim($crawler->filter('div.ecl-row.ecl-u-mv-xl:nth-child(2) h3.ecl-u-type-heading-3.ecl-u-mt-none div')->html()));
$this->assertEquals('<p>Press contact body text</p>', trim($crawler->filter('div.ecl-col-12:nth-child(2) div.ecl-u-mb-l div.ecl-editor')->html()));

// Set paragraph title and assert rendering is updated.
$paragraph->set('field_oe_title', 'Contact paragraph Test')->save();
$html = $this->renderParagraph($paragraph);
$crawler = new Crawler($html);
$this->assertEquals('Contact paragraph Test', trim($crawler->filter('h2.ecl-u-type-heading-2')->html()));
}

}
Loading

0 comments on commit fd21ba6

Please sign in to comment.