Skip to content

Commit

Permalink
Merge branch '1.x-1.x' of github.com:backdrop-contrib/metatag into 1.…
Browse files Browse the repository at this point in the history
…x-1.x
  • Loading branch information
Jen Lampton committed Jan 2, 2021
2 parents 72acdb5 + 40d1a80 commit fe767da
Show file tree
Hide file tree
Showing 16 changed files with 185 additions and 49 deletions.
88 changes: 87 additions & 1 deletion config/metatag.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,91 @@
"metatag_enable_node__post": 1,
"metatag_enable_taxonomy_term": 1,
"metatag_enable_taxonomy_term__tags": 1,
"metatag_enable_user": 1
"metatag_enable_user": 1,
"enabled_tags": {
"title": "title",
"description": "description",
"image_src": "image_src",
"canonical": "canonical",
"content-language": "content-language",
"og:site_name": "og:site_name",
"og:type": "og:type",
"og:url": "og:url",
"og:title": "og:title",
"og:description": "og:description",
"og:updated_time": "og:updated_time",
"og:image": "og:image",
"article:published_time": "article:published_time",
"article:modified_time": "article:modified_time",
"abstract": 0,
"keywords": 0,
"news_keywords": 0,
"standout": 0,
"rating": 0,
"referrer": 0,
"generator": 0,
"rights": 0,
"shortlink": 0,
"original-source": 0,
"prev": 0,
"next": 0,
"geo.position": 0,
"geo.placename": 0,
"geo.region": 0,
"icbm": 0,
"refresh": 0,
"revisit-after": 0,
"pragma": 0,
"cache-control": 0,
"expires": 0,
"robots": 0,
"og:determiner": 0,
"og:see_also": 0,
"og:image:url": 0,
"og:image:secure_url": 0,
"og:image:type": 0,
"og:image:width": 0,
"og:image:height": 0,
"og:latitude": 0,
"og:longitude": 0,
"og:street_address": 0,
"og:locality": 0,
"og:region": 0,
"og:postal_code": 0,
"og:country_name": 0,
"og:email": 0,
"og:phone_number": 0,
"og:fax_number": 0,
"og:locale": 0,
"og:locale:alternate": 0,
"article:author": 0,
"article:publisher": 0,
"article:section": 0,
"article:tag": 0,
"article:expiration_time": 0,
"profile:first_name": 0,
"profile:last_name": 0,
"profile:username": 0,
"profile:gender": 0,
"og:audio": 0,
"og:audio:secure_url": 0,
"og:audio:type": 0,
"book:author": 0,
"book:isbn": 0,
"book:release_date": 0,
"book:tag": 0,
"og:video:url": 0,
"og:video:secure_url": 0,
"og:video:width": 0,
"og:video:height": 0,
"og:video:type": 0,
"video:actor": 0,
"video:actor:role": 0,
"video:director": 0,
"video:writer": 0,
"video:duration": 0,
"video:release_date": 0,
"video:tag": 0,
"video:series": 0
}
}
36 changes: 30 additions & 6 deletions metatag.admin.inc
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ function metatag_bulk_revert_form() {
'#default_value' => array(),
);

$metatags = metatag_get_info();
$metatags = metatag_get_info(NULL, NULL, TRUE);
$options = array();
foreach ($metatags['tags'] as $tag_name => $tag) {
$options[$tag_name] = t('@group_label: @tag_label', array(
Expand Down Expand Up @@ -713,6 +713,29 @@ function metatag_admin_settings_form() {
);
}

$form['enable'] = array(
'#type' => 'fieldset',
'#title' => t('Enable Meta tags'),
'#description' => t("Enable the specific meta tags that will be used/relevant for this site."),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$metatags = metatag_get_info(NULL, NULL, TRUE);
$options = array();
foreach ($metatags['tags'] as $tag) {
$options[$tag['name']] = t('@group_label: @tag_label', array(
'@group_label' => $metatags['groups'][$tag['group']]['label'],
'@tag_label' => $tag['label'],
));
}
$default = $settings->get('enabled_tags');
$form['enable']['enabled_tags'] = array(
'#type' => 'checkboxes',
'#title' => t('Meta tags to enable'),
'#options' => $options,
'#default_value' => isset($default) ? $default : array(),
);

$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced settings'),
Expand Down Expand Up @@ -749,16 +772,17 @@ function metatag_admin_settings_form() {
'#description' => t('When disabled, meta tags will only be output on public-facing pages.'),
'#default_value' => $settings->get('tag_admin_pages'),
);
$form['advanced']['token_sanitize'] = array(
'#type' => 'checkbox',
'#title' => t('Sanitize token data to ensure meta tag text is safe'),
'#description' => t('When disabled, token replacements may return raw, unfiltered values.'),
'#default_value' => $settings->get('token_sanitize'),
);
$form['advanced']['extended_permissions'] = array(
'#type' => 'checkbox',
'#title' => t('Provide a permission for each individual meta tag'),
'#default_value' => $settings->get('extended_permissions'),
);
$form['advanced']['token_sanitize'] = array(
'#type' => 'checkbox',
'#title' => t('Sanitize meta tag text during token replacement'),
'#default_value' => $settings->get('token_sanitize'),
);
$form['advanced']['pager_string'] = array(
'#title' => t('Replace the token [current-page:pager] with the following custom pager string:'),
'#type' => 'textfield',
Expand Down
3 changes: 2 additions & 1 deletion metatag.inc
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,11 @@ class BackdropDefaultMetaTag implements BackdropMetaTagInterface {
}

// Combine the base configuration for this meta tag with the value.
$attribute = 'name';
$element = $base_element + array(
'#tag' => 'meta',
'#attributes' => array(
'name' => $this->info['name'],
$attribute => $this->info['name'],
'content' => $value,
),
'#weight' => $this->getWeight(),
Expand Down
12 changes: 12 additions & 0 deletions metatag.install
Original file line number Diff line number Diff line change
Expand Up @@ -532,3 +532,15 @@ function metatag_update_1003() {
}
}
}

/**
* Enable all metatags for existing sites.
*/
function metatag_update_1004() {
$enabled_tags = array();
$metatags = metatag_get_info(NULL, NULL, TRUE);
foreach ($metatags['tags'] as $tag_name => $tag) {
$enabled_tags[$tag_name] = $tag_name;
}
config_set('metatag.settings', 'enabled_tags', $enabled_tags);
}
2 changes: 1 addition & 1 deletion metatag.metatag.inc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function metatag_metatag_config_instance_info() {
if (metatag_entity_supports_metatags($entity_type)) {
$info[$entity_type] = array('label' => $entity_info['label']);
foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
if (count($entity_info['bundles'] == 1) && $bundle == $entity_type) {
if (count($entity_info['bundles']) == 1 && $bundle == $entity_type) {
// Skip default bundles (entities that do not really have bundles).
continue;
}
Expand Down
15 changes: 8 additions & 7 deletions metatag.module
Original file line number Diff line number Diff line change
Expand Up @@ -1979,12 +1979,8 @@ function metatag_form_alter(&$form, $form_state, $form_id) {

/**
* Get the meta tag information array of a meta tag.
*
* @param $metatag
* The meta tag name, e.g. description, for which the info shall be returned,
* or NULL to return an array with info about all meta tags.
*/
function metatag_get_info($type = NULL, $name = NULL) {
function metatag_get_info($type = NULL, $name = NULL, $include_disabled = FALSE) {
// Use the advanced backdrop_static() pattern, since this is called very often.
static $backdrop_static_fast;
if (!isset($backdrop_static_fast)) {
Expand All @@ -2007,13 +2003,18 @@ function metatag_get_info($type = NULL, $name = NULL) {
$info = module_invoke_all('metatag_info');
$info += array('tags' => array(), 'groups' => array());

// Merge in default values.
$enabled = config_get('metatag.settings', 'enabled_tags');
foreach ($info['tags'] as $key => $data) {
// Merge in default values.
$info['tags'][$key] += array(
// Merge in default values.
'name' => $key,
'class' => 'BackdropTextMetaTag',
);

// Only show enabled tags.
if (empty($enabled[$key]) && !$include_disabled) {
unset($info['tags'][$key]);
}
}

// Let other modules alter the entity info using
Expand Down
9 changes: 2 additions & 7 deletions metatag_favicons/metatag_favicons.module
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,9 @@ function theme_metatag_shortcut_icon($variables) {
* The absolute URL to the favicon, empty string if not found.
*/
function metatag_favicons_get_theme_favicon() {
$favicon_url = '';
$favicon = backdrop_get_favicon();

// Is the favicon enabled?
if (theme_get_setting('toggle_favicon')) {
$favicon_url = theme_get_setting('favicon');
}

return $favicon_url;
return url($favicon['path'], array('absolute' => TRUE));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion metatag_views/metatag_views.i18n.inc
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function metatag_views_i18n_list_displays() {
if (!empty($display->display_options['metatags'][LANGUAGE_NONE])) {
// Need to rig i18n_string's ability to find the record.
$display->view_id = $view_id;
$displays[$display->view_id . METATAG_VIEWS_CONTEXT_SEPARATOR . $display->id] = $display;
$displays[$display->view_id . '__' . $display->id] = $display;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion metatag_views/metatag_views.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (class_exists('i18n_string_object_wrapper')) {
// This will result in a context like
// 'metatag_views:view_name__page:description' for the 'description' tag
// on the 'page' display of the 'view_name' view.
return array('metatag_views', $this->object->view_id . METATAG_VIEWS_CONTEXT_SEPARATOR . $this->object->id);
return array('metatag_views', $this->object->view_id . '__' . $this->object->id);
}

}
Expand Down
5 changes: 1 addition & 4 deletions metatag_views/metatag_views.info
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
;marking as hidden until ported.
hidden = true

type = module
name = Metatag: Views
description = Provides Metatag integration within the Views interface.
package = SEO
core = 7.x
backdrop = 1.x

dependencies[] = metatag
dependencies[] = views
Expand Down
40 changes: 29 additions & 11 deletions metatag_views/metatag_views.module
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* Provides native meta tag integration with Views.
*/

// This is used to join the view name and the display name when building the
// context string.
define('METATAG_VIEWS_CONTEXT_SEPARATOR', '__');
function metatag_views_autoload_info() {
return array(
'metatag_views_plugin_display_extender_metatags' => 'metatag_views_plugin_display_extender_metatags.inc',
);
}

/**
* Implements hook_views_api().
Expand All @@ -15,6 +17,19 @@ function metatag_views_views_api() {
return array('api' => 3.0);
}

function metatag_views_views_plugins() {
$plugins = array();
$plugins['display_extender']['metatags'] = array(
'title' => t('Meta tags'),
'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;
}

/**
* Implements hook_view_preview_info_alter().
*/
Expand All @@ -32,9 +47,9 @@ function metatag_views_views_preview_info_alter(&$rows, $view) {

// Set the page title to be the previewed views title before fetching meta
// tag values.
$title = drupal_set_title();
$title = backdrop_set_title();
if ($view_title = $view->get_title()) {
drupal_set_title($view_title);
backdrop_set_title($view_title);
}

$instance = 'view:' . $view->name;
Expand All @@ -52,13 +67,13 @@ function metatag_views_views_preview_info_alter(&$rows, $view) {
}

// Restore the page title.
drupal_set_title($title);
backdrop_set_title($title);
}

/**
* Implements hook_page_alter().
* Implements hook_preprocess_HOOK().
*/
function metatag_views_page_alter(&$page) {
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)) {
Expand All @@ -78,7 +93,7 @@ function metatag_views_page_alter(&$page) {
}

// Prevent Views settings from overwriting global:frontpage.
if (drupal_is_front_page() && metatag_config_is_enabled('global:frontpage')) {
if (backdrop_is_front_page() && metatag_config_is_enabled('global:frontpage')) {
return;
}

Expand All @@ -104,15 +119,18 @@ function metatag_views_page_alter(&$page) {

// Translate all of the meta tags using i18n, but don't update the
// strings.
metatag_translate_metatags($metatags[LANGUAGE_NONE], 'metatag_views:' . $view->name . METATAG_VIEWS_CONTEXT_SEPARATOR . $view->current_display, NULL, FALSE);
metatag_translate_metatags($metatags[LANGUAGE_NONE], 'metatag_views:' . $view->name . '__' . $view->current_display, NULL, FALSE);

// Build options for meta tag rendering.
$options = array();
$options['token data']['view'] = $view;
$options['language'] = $language->language;

// Add the metatags.
// @todo
$processed_metatags = metatag_metatags_view($instance, $metatags, $options);
foreach ($processed_metatags as $name => $data) {
backdrop_add_html_head($data, $name);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ class metatag_views_plugin_display_extender_metatags extends views_plugin_displa

// Leave some possibility for future versions to support translation.
foreach ($metatags as $langcode => $values) {
if (!empty($form['metatags'][$langcode]['#metatag_defaults'])) {
metatag_filter_values_from_defaults($form_state['values']['metatags'][$langcode], $form['metatags'][$langcode]['#metatag_defaults']);
$defaults['metatag'] = $form['options']['metatags'][$langcode]['#metatag_defaults']['config'];

if (!empty($defaults)) {
metatag_filter_values_from_defaults($metatags[$langcode], $defaults);
}
}

Expand Down
2 changes: 1 addition & 1 deletion metatag_views/tests/metatag_views.i18n.test
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class MetatagViewsI18nTest extends MetatagTestHelper {
// Plan out the different translation string tests.
$string_en = 'Testing Metatag:Views.';
$string_fr = 'French page description.';
$config_name = 'metatag_views:metatag_views_test' . METATAG_VIEWS_CONTEXT_SEPARATOR . 'page:description';
$config_name = 'metatag_views:metatag_views_test__page:description';
$path = 'metatag-views-test';

// Confirm the string is present as it has been grabbed by the string-
Expand Down
Loading

0 comments on commit fe767da

Please sign in to comment.