Skip to content

Commit

Permalink
Issue #98: Fix displaying metatag options on views. Port metatag_view…
Browse files Browse the repository at this point in the history
…s tests.
  • Loading branch information
quicksketch authored Nov 26, 2022
1 parent 23295ac commit f46feac
Show file tree
Hide file tree
Showing 12 changed files with 502 additions and 145 deletions.
5 changes: 4 additions & 1 deletion metatag.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,12 @@ function metatag_config_edit_form($form, &$form_state, $config) {

$contexts = explode(':', $config['instance']);
$options['context'] = $contexts[0];
$options['token types'] = array();
if ($contexts[0] != 'global') {
$info = entity_get_info($contexts[0]);
$options['token types'] = array($info['token type']);
if ($info) {
$options['token types'][] = $info['token type'];
}
// Allow the defined tokens to be modified.
backdrop_alter('metatag_token_types', $options);
}
Expand Down
7 changes: 1 addition & 6 deletions metatag.api.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ function hook_metatag_presave(&$metatags, $entity_type, $entity_id, $revision_id
* Allows modules to alter the defined list of tokens available
* for metatag patterns replacements.
*
* By default only context (for example: global, node, etc...)
* By default, only context (for example: global, node, etc...)
* related tokens are made available to metatag patterns replacements.
* This hook allows other modules to extend the default declared tokens.
*
Expand All @@ -282,11 +282,6 @@ function hook_metatag_presave(&$metatags, $entity_type, $entity_id, $revision_id
* @see metatag_field_attach_form()
*/
function hook_metatag_token_types_alter(&$options) {
// Watchout: $options['token types'] might be empty.
if (!isset($options['token types'])) {
$options['token types'] = array();
}

if ($options['context'] == 'config1') {
$options['token types'] += array('token_type1', 'token_type2');
}
Expand Down
6 changes: 3 additions & 3 deletions metatag.module
Original file line number Diff line number Diff line change
Expand Up @@ -2128,11 +2128,11 @@ function metatag_preprocess_page(&$variables) {
// Account for multi-valued tags.
if (!isset($data['#tag']) && !empty($data[0])) {
foreach($data as $delta => $subdata) {
backdrop_add_html_head($subdata, 'metatag_preprocess_page-' . $tag . '-' . $delta);
backdrop_add_html_head($subdata, $tag . '-' . $delta);
}
}
else {
backdrop_add_html_head($data, 'metatag_preprocess_page-' . $tag);
backdrop_add_html_head($data, $tag);
}
}
}
Expand Down Expand Up @@ -2165,7 +2165,7 @@ function metatag_preprocess_maintenance_page(&$variables) {
}
// ALl other tags are assumed 'meta' tags.
else {
backdrop_add_html_head($data, 'metatag_preprocess_maintenance_page');
backdrop_add_html_head($data, $tag);
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions metatag_views/metatag_views.module
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,19 @@ function metatag_views_autoload_info() {
function metatag_views_views_api() {
return array(
'api' => 3,
'path' => backdrop_get_path('module', 'metatag'),
'path' => backdrop_get_path('module', 'metatag_views'),
);
}

/**
* Implements hook_metatag_token_types_alter().
*/
function metatag_views_metatag_token_types_alter(&$options) {
if ($options['context'] == 'view') {
$options['token types'][] = 'view';
}
}

/**
* Implements hook_view_preview_info_alter().
*/
Expand Down Expand Up @@ -64,9 +73,9 @@ function metatag_views_views_preview_info_alter(&$rows, $view) {
* Implements hook_preprocess_HOOK().
*/
function metatag_views_preprocess_page(&$variables) {
// By default do not add meta tags to admin pages. To enable meta tags on
// admin pages set the 'metatag_tag_admin_pages' variable to TRUE.
if (path_is_admin(current_path()) && !variable_get('metatag_tag_admin_pages', FALSE)) {
// By default, do not add meta tags to admin pages. To enable meta tags on
// admin pages set the 'tag_admin_pages' config value to TRUE.
if (path_is_admin(current_path()) && config('metatag.settings')->get('tag_admin_pages') == FALSE) {
return;
}

Expand Down
101 changes: 0 additions & 101 deletions metatag_views/metatag_views.tokens.inc

This file was deleted.

1 change: 0 additions & 1 deletion metatag_views/metatag_views.views.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function metatag_views_views_plugins() {
'help' => t('Provides meta tags for views.'),
'handler' => 'metatag_views_plugin_display_extender_metatags',
'enabled' => TRUE,
'path' => backdrop_get_path('module', 'metatag_views'),
);

return $plugins;
Expand Down
19 changes: 4 additions & 15 deletions metatag_views/tests/metatag_views.i18n.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@
*/

class MetatagViewsI18nTest extends MetatagTestHelper {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Metatag:Views i18n tests',
'description' => 'Test Metatag integration via the Metatag:Views module.',
'group' => 'Metatag',
);
}

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -51,11 +40,11 @@ class MetatagViewsI18nTest extends MetatagTestHelper {
}

/**
* Test the Metatag:Views translations.
* Test the Metatag: Views translations.
*/
public function testExportedPage() {
// Plan out the different translation string tests.
$string_en = 'Testing Metatag:Views.';
$string_en = 'Testing Metatag: Views.';
$string_fr = 'French page description.';
$config_name = 'metatag_views:metatag_views_test__page:description';
$path = 'metatag-views-test';
Expand All @@ -72,7 +61,7 @@ class MetatagViewsI18nTest extends MetatagTestHelper {
$this->saveTranslationString($lid, $config_name, 'fr', $string_en, $string_fr);

// Load the English page again.
$this->drupalGet($path);
$this->backdropGet($path);
$this->assertResponse(200, 'Loaded the default test page again.');

// Confirm the page's description is what we set it to.
Expand All @@ -82,7 +71,7 @@ class MetatagViewsI18nTest extends MetatagTestHelper {
$this->assertNotEqual($xpath[0]['content'], $string_fr);

// Load the French page.
$this->drupalGet('fr/' . $path);
$this->backdropGet('fr/' . $path);
$this->assertResponse(200, 'Loaded the French test page.');

// Confirm the generator string was translated.
Expand Down
18 changes: 5 additions & 13 deletions metatag_views/tests/metatag_views.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,6 @@
*/

class MetatagViewsTest extends MetatagTestHelper {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Metatag:Views tests',
'description' => 'Test Metatag integration via the Metatag:Views module.',
'group' => 'Metatag',
);
}

/**
* {@inheritdoc}
*/
Expand All @@ -26,13 +15,16 @@ class MetatagViewsTest extends MetatagTestHelper {
$modules[] = 'metatag_views_tests';

parent::setUp($modules);

// Enable keywords metatag for testing.
config_set('metatag.settings', 'enabled_tags.keywords', 'keywords');
}

/**
* Test the Metatag:Views translations on an exported page.
*/
public function testExportedPage() {
$this->drupalGet('metatag-views-test');
$this->backdropGet('metatag-views-test');
$this->assertResponse(200);

// Test the page title.
Expand All @@ -41,7 +33,7 @@ class MetatagViewsTest extends MetatagTestHelper {
// Test the description meta tag.
$xpath = $this->xpath("//meta[@name='description']");
$this->assertEqual(count($xpath), 1, 'Exactly one description meta tag found.');
$this->assertEqual($xpath[0]['content'], 'Testing Metatag:Views.');
$this->assertEqual($xpath[0]['content'], 'Testing Metatag: Views.');

// Test the keywords meta tag.
$xpath = $this->xpath("//meta[@name='keywords']");
Expand Down
12 changes: 12 additions & 0 deletions metatag_views/tests/metatag_views.tests.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[MetatagViewsTest]
name = Metatag: Views tests
description = Test Metatag integration via the Metatag: Views module
group = Metatag
file = metatag_views.test

# @todo: Finish porting i18n tests to Backdrop.
# [MetatagViewsI18nTest]
# name = Metatag: Views i18n tests
# description = Test Metatag i18n integration via the Metatag: Views module.
# group = Metatag
# file = metatag_views.i18n.test
Loading

0 comments on commit f46feac

Please sign in to comment.