Skip to content

Commit

Permalink
Issue backdrop-contrib#1: Port the favicons submodule.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jen Lampton committed Dec 27, 2017
1 parent dcac96c commit 9c7ccfb
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 130 deletions.
14 changes: 2 additions & 12 deletions metatag_favicons/metatag_favicons.info
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
;marking as hidden until ported.
hidden = true

type = module
name = Metatag: favicons
description = "Provides support for many different favicons."
description = Provides support for many different favicons.
package = SEO
core = 7.x
backdrop = 1.x
dependencies[] = metatag

; Custom class for mask-icon.
files[] = metatag_favicons.mask-icon.class.inc

; Tests.
files[] = tests/metatag_favicons.test
files[] = tests/metatag_favicons.tags.test
26 changes: 9 additions & 17 deletions metatag_favicons/metatag_favicons.mask-icon.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BackdropMaskIconMetaTag extends BackdropTextMetaTag {
'#title' => t('Icon: SVG color'),
'#default_value' => isset($this->data['color']) ? $this->data['color'] : '',
'#description' => t('Provides a color for the SVG icon. Per <a href="@specs_url">Apple\'s specifications</a>, it may be a hexadecimal value (e.g. "#990000"), an RGB value (e.g. "rgb(153, 0, 0)"), or a recognized color-keyword (e.g. "red", "lime", "navy", etc). Will only be output if the SVG icon meta tag has a value.', array('@specs_url' => 'https://developer.apple.com/library/mac/releasenotes/General/WhatsNewInSafari/Articles/Safari_9_0.html#//apple_ref/doc/uid/TP40014305-CH9-SW20')),
'#maxlength' => 10,
'#maxlength' => 20,
'#weight' => $form['value']['#weight'] + 0.01,
);

Expand Down Expand Up @@ -79,26 +79,18 @@ class BackdropMaskIconMetaTag extends BackdropTextMetaTag {

// Combine the base configuration for this meta tag with the value.
$element = $base_element + array(
'#theme' => 'metatag',
'#tag' => 'link',
'#id' => 'metatag_' . $this->info['name'] . '_' . 1,
'#rel' => $this->info['name'],
'#name' => $this->info['name'],
'#value' => $value,
'#color' => $color,
'#attributes' => array(
'id' => 'metatag_' . $this->info['name'] . '_' . 1,
'name' => $this->info['name'],
'rel' => $this->info['name'],
'href' => $value,
'color' => $color,
),
'#weight' => $this->getWeight(),
);

// Add header information if desired.
if (!empty($this->info['header'])) {
$element['#attached']['backdrop_add_http_header'][] = array($this->info['header'], $value);
}

$elements[] = array($element, $element['#id']);

return array(
'#attached' => array('backdrop_add_html_head' => $elements),
);
return $element;
}

}
13 changes: 0 additions & 13 deletions metatag_favicons/metatag_favicons.metatag.inc
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,6 @@
* Metatag integration for the Metatag:favicons module.
*/

/**
* Implements hook_metatag_bundled_config_alter().
*/
function metatag_favicons_metatag_bundled_config_alter(&$config) {
$favicon = metatag_favicons_get_theme_favicon();
if (!empty($favicon)) {
$config['global']['config']['shortcut icon'] = array('value' => $favicon);
}
}

/**
* Implements hook_metatag_info().
*/
Expand Down Expand Up @@ -52,9 +42,6 @@ function metatag_favicons_metatag_info() {
'label' => t('Icon: SVG'),
'description' => t('A grayscale scalable vector graphic (SVG) file.'),
'weight' => ++$weight,
'element' => array(
'#theme' => 'metatag_mask_icon',
),
'class' => 'BackdropMaskIconMetaTag',
'replaces' => array('icon_any'),
) + $favicon_defaults;
Expand Down
71 changes: 34 additions & 37 deletions metatag_favicons/metatag_favicons.module
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,26 @@
*/

/**
* Implements hook_theme().
* Implements hook_autoload_info().
*/
function metatag_favicons_theme() {
$info['metatag_favicon'] = array(
'render element' => 'element',
);

$info['metatag_mask_icon'] = array(
'render element' => 'element',
function metatag_favicons_autoload_info() {
return array(
'BackdropMaskIconMetaTag' => 'metatag_favicons.mask-icon.class.inc',
);
}

$info['metatag_shortcut_icon'] = array(
'render element' => 'element',
/**
* Implements hook_theme().
*/
function metatag_favicons_theme() {
return array(
'metatag_favicon' => array(
'render element' => 'element',
),
'metatag_shortcut_icon' => array(
'render element' => 'element',
),
);
return $info;
}

/**
Expand All @@ -29,35 +34,17 @@ function metatag_favicons_theme() {
* <link rel="[rel]" href="[value]" sizes="[sizes]" />
*/
function theme_metatag_favicon($variables) {
$variables['#tag'] = 'link';
$element = &$variables['element'];
$args = array(
$attributes = array(
'#rel' => 'rel',
'#value' => 'href',
'#sizes' => 'sizes',
'#mask' => 'mask',
);
element_set_attributes($element, $args);
element_set_attributes($element, $attributes);
unset($element['#value']);
return theme('html_tag', $variables);
}

/**
* Theme callback for the mask-icon meta tag.
*
* The format is:
* <link rel="mask-icon" href="[value]" sizes="[sizes]" />
*/
function theme_metatag_mask_icon($variables) {
$element = &$variables['element'];

$args = array(
'#rel' => 'rel',
'#value' => 'href',
'#color' => 'color',
);
element_set_attributes($element, $args);
unset($element['#value']);
return theme('html_tag', $variables);
return theme('head_tag', $variables);
}

/**
Expand All @@ -67,19 +54,19 @@ function theme_metatag_mask_icon($variables) {
* <link rel="[rel]" href="[value]" type="[type]" />
*/
function theme_metatag_shortcut_icon($variables) {
$variables['#tag'] = 'link';
$element = &$variables['element'];

// Extract the MIME type.
$element['#type'] = metatag_favicons_get_mime_type($element['#value']);

$args = array(
$attributes = array(
'#rel' => 'rel',
'#value' => 'href',
'#type' => 'type',
);
element_set_attributes($element, $args);
element_set_attributes($element, $attributes);
unset($element['#value']);
return theme('html_tag', $variables);
return theme('head_tag', $variables);
}

/**
Expand Down Expand Up @@ -147,3 +134,13 @@ function metatag_favicons_get_mime_type($uri) {

return $type;
}

/**
* Implements hook_metatag_bundled_config_alter().
*/
function metatag_favicons_metatag_bundled_config_alter(&$config) {
$favicon = metatag_favicons_get_theme_favicon();
if (!empty($favicon)) {
$config['global']['config']['shortcut icon'] = array('value' => $favicon);
}
}
11 changes: 0 additions & 11 deletions metatag_favicons/tests/metatag_favicons.tags.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@

class MetatagFaviconsTagsTest extends MetatagTagsTestBase {

/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Metatag tags: Favicons',
'description' => 'Test the Favicons meta tags.',
'group' => 'Metatag',
);
}

/**
* {@inheritdoc}
*/
Expand Down
Loading

0 comments on commit 9c7ccfb

Please sign in to comment.