Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1017 from kolesnikoff/feature/dev-os25
Browse files Browse the repository at this point in the history
Google Translate block
  • Loading branch information
podarok authored May 9, 2018
2 parents e345266 + 618080b commit 43b0324
Show file tree
Hide file tree
Showing 21 changed files with 533 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
uuid: 5a698466-f499-4dda-a084-4d61c1d0e777
langcode: en
status: true
dependencies:
module:
- openy_gtranslate
theme:
- openy_lily
id: openy_lily_googletranslate
theme: openy_lily
region: secondary_menu
weight: 49
provider: null
plugin: openy_gtranslate_block
settings:
id: openy_gtranslate_block
label: 'OpenY Google Translate'
provider: openy_gtranslate
label_display: '0'
visibility: { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
uuid: 5a698466-f499-4dda-a084-4d61c1d0e902
langcode: en
status: true
dependencies:
module:
- openy_gtranslate
theme:
- openy_rose
id: openy_rose_googletranslate
theme: openy_rose
region: secondary_menu
weight: 49
provider: null
plugin: openy_gtranslate_block
settings:
id: openy_gtranslate_block
label: 'OpenY Google Translate'
provider: openy_gtranslate
label_display: '0'
visibility: { }
25 changes: 25 additions & 0 deletions modules/custom/openy_gtranslate/js/openy_gtranslate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(function ($) {

Drupal.behaviors.openy_gtranslate = {
attach: function (context, settings) {
setTimeout(function () {
var langSelect = $('.goog-te-menu-frame').first();

$('nav .navbar-nav li.language > a').on('click', function (e, context) {
e.preventDefault();
langSelect.show();
langSelect.addClass('open');
return false;
});

$('body').on('click', function (e, context) {
if (langSelect.hasClass('open')) {
langSelect.hide();
langSelect.removeClass('open');
}
});
}, 100);
}
};

})(jQuery);
6 changes: 6 additions & 0 deletions modules/custom/openy_gtranslate/openy_gtranslate.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: OpenY Google Translate
type: module
description: OpenY module for Google Translate integration.
core: 8.x
version: 8.0.1
package: OpenY
30 changes: 30 additions & 0 deletions modules/custom/openy_gtranslate/openy_gtranslate.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* @file
* Installation file for OpenY Google Translate module.
*/

use Drupal\menu_link_content\Entity\MenuLinkContent;

/**
* Implements hook_install().
*/
function openy_gtranslate_install() {
$config = \Drupal::config('system.theme');
$menuName = ($config->get('default') == 'openy_rose') ? 'account' : 'main';
$menuLink = MenuLinkContent::create([
'title' => t('Language'),
'link' => [
'uri' => 'internal:/',
'options' => [
'attributes' => [
'class' => ['language hidden-md hidden-lg'],
],
],
],
'menu_name' => $menuName,
'weight' => 50,
]);
$menuLink->save();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
translate:
version: 8.0.1
js:
js/openy_gtranslate.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
47 changes: 47 additions & 0 deletions modules/custom/openy_gtranslate/openy_gtranslate.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/**
* @file
* Defines the OpenY Google Translate module functions.
*/

/**
* Implements hook_preprocess_menu().
*
* Add class to menu navigation items.
*/
function openy_gtranslate_preprocess_menu(&$vars) {
if (isset($vars['menu_name']) && in_array($vars['menu_name'], ['main', 'account'])) {
foreach ($vars['items'] as &$item) {
/* @var \Drupal\Core\Url $url */
$url = $item['url'];
$attr = $url->getOption('attributes');
if (!empty($attr['class'])) {
/* @var \Drupal\Core\Template\Attribute $item['attributes'] */
$item['attributes']->addClass($attr['class']);
}
}
}
}

/**
* Implements hook_theme().
*/
function openy_gtranslate_theme($existing, $type, $theme, $path) {
return [
'openy_gtranslate' => [
'variables' => [],
],
];
}

/**
* Implements hook_preprocess_block().
*/
function openy_gtranslate_preprocess_block(&$variables) {
$blockType = $variables['elements']['#configuration']['provider'];

if ($blockType == 'openy_gtranslate') {
$variables['attributes']['class'][] = 'openy-gtranslate';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Drupal\openy_gtranslate\Plugin\Block;

use Drupal\Core\Block\BlockBase;

/**
* Provides a 'OpenY Google Translate' block.
*
* @Block(
* id = "openy_gtranslate_block",
* admin_label = @Translation("OpenY Google Translate"),
* category = @Translation("OpenY"),
* )
*/
class OpenYGTranslateBlock extends BlockBase {

/**
* {@inheritdoc}
*/
public function build() {
$block = [
'#theme' => 'openy_gtranslate',
'#attached' => [
'library' => ['openy_gtranslate/translate'],
],
];

return $block;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{#
/**
* @file
* Template for the OpenY Google Translate block
*/
#}

<div class="openy-google-translate" id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: drupalSettings.path.currentLanguage, layout: google.translate.TranslateElement.InlineLayout.SIMPLE}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
1 change: 1 addition & 0 deletions openy.info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ dependencies:
- openy_data_wrapper
- logger_entity
- openy_redirect
- openy_gtranslate

themes:
- bartik
Expand Down
25 changes: 24 additions & 1 deletion openy.install
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ function openy_update_8052() {
\Drupal::service('module_installer')->install(['openy_prgf_location_by_amenities']);
}

/*
/**
* Enable event module.
*/
function openy_update_8053() {
Expand All @@ -804,3 +804,26 @@ function openy_update_8053() {
$importer->import('openy_demo_event_landing');
}
}

/**
* Enable OpenY Google Translate module and blocks.
*/
function openy_update_8054() {
\Drupal::service('module_installer')->install(['openy_gtranslate']);

$themes_list = [
'openy_rose' => '5a698466-f499-4dda-a084-4d61c1d0e902',
'openy_lily' => '5a698466-f499-4dda-a084-4d61c1d0e777',
];
/** @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager */
$entityTypeManager = \Drupal::service('entity_type.manager');
foreach ($themes_list as $theme => $uuid) {
/** @var \Drupal\block_content\Entity\BlockContent $blockContent */
$blockContent = $entityTypeManager->getStorage('block_content')->create([
'type' => 'openy_gtranslate_block',
'info' => t('Google Translate Block'),
'uuid' => $uuid,
]);
$blockContent->save();
}
}
31 changes: 31 additions & 0 deletions openy.profile
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,40 @@ function openy_install_tasks() {
'type' => 'form',
'function' => UploadFontMessageForm::class,
],
'openy_gtranslate_place_blocks' => [
'type' => 'batch',
],
];
}

/**
* Create Google Translate block content.
* Block already added from OpenY Google Translate module configs.
*/
function openy_gtranslate_place_blocks(array &$install_state) {
$moduleHandler = \Drupal::service('module_handler');
if (!$moduleHandler->moduleExists('openy_gtranslate')) {
return ['operations' => []];
}

$themes_list = [
'openy_rose' => '5a698466-f499-4dda-a084-4d61c1d0e902',
'openy_lily' => '5a698466-f499-4dda-a084-4d61c1d0e777',
];
/** @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager */
$entityTypeManager = \Drupal::service('entity_type.manager');
foreach ($themes_list as $theme => $uuid) {
/** @var \Drupal\block_content\Entity\BlockContent $blockContent */
$blockContent = $entityTypeManager->getStorage('block_content')->create([
'type' => 'openy_gtranslate_block',
'info' => t('Google Translate Block'),
'uuid' => $uuid,
]);
$blockContent->save();
}
return ['operations' => []];
}

/**
* Mapping for demo content configs.
*
Expand Down
67 changes: 67 additions & 0 deletions themes/openy_themes/openy_lily/css/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions themes/openy_themes/openy_lily/css/style.css.map

Large diffs are not rendered by default.

Loading

0 comments on commit 43b0324

Please sign in to comment.