Loading CHANGELOG.txt +2 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ Metatag 7.x-1.x, xxxx-xx-xx verification. #2994102 by DamienMcKenna, LaravZ: Removed extra xmlns definitions due to W3C validation errors. #3063056 by tristangraves, DamienMcKenna: Metatag has media browser token in meta description. Metatag 7.x-1.25, 2018-04-03 Loading metatag.inc +10 −0 Original line number Diff line number Diff line Loading @@ -503,6 +503,16 @@ class DrupalTextMetaTag extends DrupalDefaultMetaTag { $value = $this->data['value']; if (empty($options['raw'])) { // Make sure there is a node to work with. if (isset($options['token data']['node'])) { // Get language to use for selecting body field value. $lang = field_language('node', $options['token data']['node'], 'body'); if (!empty($options['token data']['node']->body[$lang][0]['value'])) { // Pre-tidy the node body for token_replace if it's not empty. $options['token data']['node']->body[$lang][0]['value'] = $this->tidyValue($options['token data']['node']->body[$lang][0]['value']); } } // Give other modules the opportunity to use hook_metatag_pattern_alter() // to modify defined token patterns and values before replacement. drupal_alter('metatag_pattern', $value, $options['token data'], $this->info['name']); Loading tests/metatag.with_media.test +177 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,183 @@ class MetatagCoreWithMediaTest extends MetatagTestHelper { 'body' => array( LANGUAGE_NONE => array( array( 'value' => $desc . '[[{"fid":"1","view_mode":"default","type":"media","attributes":{"height":"100","width":"100","class":"media-element file-default"}}]]', 'value' => $desc . '[[' . json_encode(array( 'fid' => 1, 'view_mode' => 'default', 'type' => 'media', 'attributes' => array( 'height' => '100', 'width' => '100', 'class' => 'media-element file-default', ), )) . ']]', 'format' => filter_default_format(), ), ), ), )); // Load the node page. $this->drupalGet('node/' . $node->nid); $this->assertResponse(200); // Check the 'description' tag to make sure the Media string was filtered. $xpath = $this->xpath("//meta[@name='description']"); $this->assertEqual($xpath[0]['content'], $desc); } /** * Make sure extremely long media tags are properly handled. */ public function testMediaFilterLongToken() { $desc = 'The description with long token.'; $node = $this->drupalCreateNode(array( 'body' => array( LANGUAGE_NONE => array( array( 'value' => $desc . '[[' . json_encode(array( 'fid' => 1, 'view_mode' => 'default', 'fields' => array( 'alt' => 'alt text field value', 'style' => 'height: auto;', 'class' => 'media-element file-default cke_widget_element', 'data-delta' => 25, 'format' => 'default', 'alignment' => 'center', 'field_image_width[und][0][value]' => '', 'field_file_image_alt_text[und][0][value]' => 'alt text field value', 'field_caption[und][0][value]' => '', 'field_file_image_title_text[und][0][value]' => FALSE, ), 'type' => 'media', 'field_deltas' => array( 25 => array( 'alt' => 'alt text field value', 'style' => 'height: auto;', 'class' => 'media-element file-default cke_widget_element', 'data-delta' => 25, 'format' => 'default', 'alignment' => 'center', 'field_image_width[und][0][value]' => '', 'field_file_image_alt_text[und][0][value]' => 'alt text field value', 'field_caption[und][0][value]' => '', 'field_file_image_title_text[und][0][value]' => FALSE, ), ), 'attributes' => array( 'alt' => 'alt text field value', 'style' => 'height:auto', 'class' => 'file-default media-element media-wysiwyg-align-center', 'data-delta' => '25', ), )) .']]', 'format' => filter_default_format(), ), ), ), )); // Load the node page. $this->drupalGet('node/' . $node->nid); $this->assertResponse(200); // Check the 'description' tag to make sure the Media string was filtered. $xpath = $this->xpath("//meta[@name='description']"); $this->assertEqual($xpath[0]['content'], $desc); } /** * Make sure body text starting with a media token is properly handled. */ public function testMediaFilterTokenAtBeginning() { $desc = 'The description with token at beginning.'; $node = $this->drupalCreateNode(array( 'body' => array( LANGUAGE_NONE => array( array( 'value' => '[[' . json_encode(array( 'fid' => '1', 'view_mode' => 'default', 'type' => 'media', 'attributes' => array( 'height' => '100', 'width' => '100', 'class' => 'media-element file-default', ), )) . ']]' . $desc, 'format' => filter_default_format(), ), ), ), )); // Load the node page. $this->drupalGet('node/' . $node->nid); $this->assertResponse(200); // Check the 'description' tag to make sure the Media string was filtered. $xpath = $this->xpath("//meta[@name='description']"); $this->assertEqual($xpath[0]['content'], $desc); } /** * Make sure body text starting with an extremely long media token is handled. */ public function testMediaFilterTokenAtBeginningLongToken() { $desc = 'The description with long token at beginning.'; $node = $this->drupalCreateNode(array( 'body' => array( LANGUAGE_NONE => array( array( 'value' => '[[' . json_encode(array( 'fid' => '1', 'view_mode' => 'default', 'fields' => array( 'alt' => 'alt text field value', 'style' => 'height: auto;', 'class' => 'media-element file-default cke_widget_element', 'data-delta' => 25, 'format' => 'default', 'alignment' => 'center', 'field_image_width[und][0][value]' => '', 'field_file_image_alt_text[und][0][value]' => 'alt text field value', 'field_caption[und][0][value]' => '', 'field_file_image_title_text[und][0][value]' => FALSE, ), 'type' => 'media', 'field_deltas' => array( 25 => array( 'alt' => 'alt text field value', 'style' => 'height: auto;', 'class' => 'media-element file-default cke_widget_element', 'data-delta' => 25, 'format' => 'default', 'alignment' => 'center', 'field_image_width[und][0][value]' => '', 'field_file_image_alt_text[und][0][value]' => 'alt text field value', 'field_caption[und][0][value]' => '', 'field_file_image_title_text[und][0][value]' => FALSE, ), ), 'attributes' => array( 'alt' => 'alt text field value', 'style' => 'height:auto', 'class' => 'file-default media-element media-wysiwyg-align-center', 'data-delta' => 25, ), )) . ']]' . $desc, 'format' => filter_default_format(), ), ), Loading Loading
CHANGELOG.txt +2 −0 Original line number Diff line number Diff line Loading @@ -30,6 +30,8 @@ Metatag 7.x-1.x, xxxx-xx-xx verification. #2994102 by DamienMcKenna, LaravZ: Removed extra xmlns definitions due to W3C validation errors. #3063056 by tristangraves, DamienMcKenna: Metatag has media browser token in meta description. Metatag 7.x-1.25, 2018-04-03 Loading
metatag.inc +10 −0 Original line number Diff line number Diff line Loading @@ -503,6 +503,16 @@ class DrupalTextMetaTag extends DrupalDefaultMetaTag { $value = $this->data['value']; if (empty($options['raw'])) { // Make sure there is a node to work with. if (isset($options['token data']['node'])) { // Get language to use for selecting body field value. $lang = field_language('node', $options['token data']['node'], 'body'); if (!empty($options['token data']['node']->body[$lang][0]['value'])) { // Pre-tidy the node body for token_replace if it's not empty. $options['token data']['node']->body[$lang][0]['value'] = $this->tidyValue($options['token data']['node']->body[$lang][0]['value']); } } // Give other modules the opportunity to use hook_metatag_pattern_alter() // to modify defined token patterns and values before replacement. drupal_alter('metatag_pattern', $value, $options['token data'], $this->info['name']); Loading
tests/metatag.with_media.test +177 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,183 @@ class MetatagCoreWithMediaTest extends MetatagTestHelper { 'body' => array( LANGUAGE_NONE => array( array( 'value' => $desc . '[[{"fid":"1","view_mode":"default","type":"media","attributes":{"height":"100","width":"100","class":"media-element file-default"}}]]', 'value' => $desc . '[[' . json_encode(array( 'fid' => 1, 'view_mode' => 'default', 'type' => 'media', 'attributes' => array( 'height' => '100', 'width' => '100', 'class' => 'media-element file-default', ), )) . ']]', 'format' => filter_default_format(), ), ), ), )); // Load the node page. $this->drupalGet('node/' . $node->nid); $this->assertResponse(200); // Check the 'description' tag to make sure the Media string was filtered. $xpath = $this->xpath("//meta[@name='description']"); $this->assertEqual($xpath[0]['content'], $desc); } /** * Make sure extremely long media tags are properly handled. */ public function testMediaFilterLongToken() { $desc = 'The description with long token.'; $node = $this->drupalCreateNode(array( 'body' => array( LANGUAGE_NONE => array( array( 'value' => $desc . '[[' . json_encode(array( 'fid' => 1, 'view_mode' => 'default', 'fields' => array( 'alt' => 'alt text field value', 'style' => 'height: auto;', 'class' => 'media-element file-default cke_widget_element', 'data-delta' => 25, 'format' => 'default', 'alignment' => 'center', 'field_image_width[und][0][value]' => '', 'field_file_image_alt_text[und][0][value]' => 'alt text field value', 'field_caption[und][0][value]' => '', 'field_file_image_title_text[und][0][value]' => FALSE, ), 'type' => 'media', 'field_deltas' => array( 25 => array( 'alt' => 'alt text field value', 'style' => 'height: auto;', 'class' => 'media-element file-default cke_widget_element', 'data-delta' => 25, 'format' => 'default', 'alignment' => 'center', 'field_image_width[und][0][value]' => '', 'field_file_image_alt_text[und][0][value]' => 'alt text field value', 'field_caption[und][0][value]' => '', 'field_file_image_title_text[und][0][value]' => FALSE, ), ), 'attributes' => array( 'alt' => 'alt text field value', 'style' => 'height:auto', 'class' => 'file-default media-element media-wysiwyg-align-center', 'data-delta' => '25', ), )) .']]', 'format' => filter_default_format(), ), ), ), )); // Load the node page. $this->drupalGet('node/' . $node->nid); $this->assertResponse(200); // Check the 'description' tag to make sure the Media string was filtered. $xpath = $this->xpath("//meta[@name='description']"); $this->assertEqual($xpath[0]['content'], $desc); } /** * Make sure body text starting with a media token is properly handled. */ public function testMediaFilterTokenAtBeginning() { $desc = 'The description with token at beginning.'; $node = $this->drupalCreateNode(array( 'body' => array( LANGUAGE_NONE => array( array( 'value' => '[[' . json_encode(array( 'fid' => '1', 'view_mode' => 'default', 'type' => 'media', 'attributes' => array( 'height' => '100', 'width' => '100', 'class' => 'media-element file-default', ), )) . ']]' . $desc, 'format' => filter_default_format(), ), ), ), )); // Load the node page. $this->drupalGet('node/' . $node->nid); $this->assertResponse(200); // Check the 'description' tag to make sure the Media string was filtered. $xpath = $this->xpath("//meta[@name='description']"); $this->assertEqual($xpath[0]['content'], $desc); } /** * Make sure body text starting with an extremely long media token is handled. */ public function testMediaFilterTokenAtBeginningLongToken() { $desc = 'The description with long token at beginning.'; $node = $this->drupalCreateNode(array( 'body' => array( LANGUAGE_NONE => array( array( 'value' => '[[' . json_encode(array( 'fid' => '1', 'view_mode' => 'default', 'fields' => array( 'alt' => 'alt text field value', 'style' => 'height: auto;', 'class' => 'media-element file-default cke_widget_element', 'data-delta' => 25, 'format' => 'default', 'alignment' => 'center', 'field_image_width[und][0][value]' => '', 'field_file_image_alt_text[und][0][value]' => 'alt text field value', 'field_caption[und][0][value]' => '', 'field_file_image_title_text[und][0][value]' => FALSE, ), 'type' => 'media', 'field_deltas' => array( 25 => array( 'alt' => 'alt text field value', 'style' => 'height: auto;', 'class' => 'media-element file-default cke_widget_element', 'data-delta' => 25, 'format' => 'default', 'alignment' => 'center', 'field_image_width[und][0][value]' => '', 'field_file_image_alt_text[und][0][value]' => 'alt text field value', 'field_caption[und][0][value]' => '', 'field_file_image_title_text[und][0][value]' => FALSE, ), ), 'attributes' => array( 'alt' => 'alt text field value', 'style' => 'height:auto', 'class' => 'file-default media-element media-wysiwyg-align-center', 'data-delta' => 25, ), )) . ']]' . $desc, 'format' => filter_default_format(), ), ), Loading