Original request

Diff not showing (Meta)Keywords, (Meta)Description fields while comparing revisions

Hi I have recently installed Diff module in drupal 7 site, before that I had Revisioning module working fine.
I really love what Diff actually does and beautifully compare pages contents with revisions..I wanted to know how Diff module can show other fields difference in the compare view like I cannot see (Meta)Keywords , (Meta)Description when I click on compare button, Diff only shows me body content and compare body contents only. please advise

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Alan D.’s picture

Title: Diff not showing (Meta)Keywords, (Meta)Description fields while comparing revisions » MetaTags integration with the Diff module
Project: Diff » Metatag
Version: 7.x-2.0 » 7.x-1.x-dev
Category: Support request » Feature request
Issue summary: View changes

Integration should be possible, if anyone is interested in writing this.

function hook_entity_diff($old_entity, $new_entity, $context) {
  if ($context['entity_type'] == 'node') {
    $type = node_type_get_type($new_entity);
    $result['title'] = array(
      '#name' => $type->title_label,
      '#old' => array($old_entity->title),
      '#new' => array($new_entity->title),
      '#weight' => -5,
      '#settings' => array(
        'show_header' => FALSE,
      ),
    );
  }
}

Simply loop through the metatag settings for the entity, and if enabled, load the new / old metatag records, loop through the old and new values and throw these into an array similar to this:

    $init_weight = 100;
    $result['metatag_' . $attribute_key] = array(
      '#name' => $attribute_name,
      '#old' => array($old_value),
      '#new' => array($new_value),
      '#weight' => $init_weight++,
      '#settings' => array(
        'show_header' => FALSE,
      ),
    );

Not sure about access checks here, not up to date with this modules internal code / restrictions

Alan D.’s picture

Issue tags: +Diff integration
abart83’s picture

thank you, i am not a coder, is their any easier way to implement this feature in DIFF?

Alan D.’s picture

Mmm.... the internals of MetaTags is a bit much for a quick solution from me sorry.

The stub that I started trying to give this a stab...

file: metatag.diff.inc


/**
 * @file
 * Includes the hooks defined by diff_hook_info().
 */

/**
 * Implements hook_entity_diff().
 */
function metatag_entity_diff($old_entity, $new_entity, $context) {
  $return = array();
  $entity_type = $context['entity_type'];
  if (metatag_entity_supports_metatags($entity_type)) {
    $language = metatag_entity_get_language($entity_type, $new_entity);

  }

  return $return;
}

Kuldeep K’s picture

Thanks, I wrote this :

function MODULE_NAME_entity_diff($old_entity, $new_entity, $context) {
  $entity_type = $context['entity_type'];
  if ($context['entity_type'] == 'node') {
    if (metatag_entity_supports_metatags($entity_type)) {
      $language = metatag_entity_get_language($entity_type, $new_entity);
      $init_weight = 100;
      foreach($new_entity->metatags['und'] as $key => $keyword) {
        $id = ucwords('Meta '.$key);
        $result[$id] = array(
          '#name' => $id,
          '#old' => array($old_entity->metatags['und'][$key]['value']),
          '#new' => array($new_entity->metatags['und'][$key]['value']),
          '#weight' => $init_weight++,
          '#settings' => array(
            'show_header' => TRUE,
          ),
        );
      }
    }
  }
  return $result;
}
DamienMcKenna’s picture

Status: Active » Needs review
FileSize
1.13 KB

This is kkumarz' code in patch format.

Status: Needs review » Needs work

The last submitted patch, 6: metatag-n2217549-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Kuldeep K’s picture

Updated patch. using node->language instead of und.

Kuldeep K’s picture

Status: Needs work » Needs review
Alan D.’s picture

There shouldn't be any need to just support Nodes and there were a few notices being thrown.

The code checks set $entity->metatags values that are set, figured this was the most lightweight option. If these are the defaults, this array may not exist.

Note that these are disabled by default and need to be enabled via Admin > Config > Content Authoring > Diff > Entities > ENTITY TYPE (/admin/config/content/diff/entities/). Figured this was the sane thing to do after 5 years where there was no support ;)

One todo in the patch, to insert the entity defaults rather than just a default string, but good enough without that support imho.

jacquesct’s picture

Does this patch allow us to set a proper canonical tag for the diff versions?

What's happening right now is sites use Diff and Metatags have tons of duplicate content issues as we're not able to properly set the current content node as the canonical content.

A way to properly set this would be very much appreciated.

Alan D.’s picture

This sounds unrelated albeit related to how the two modules integrate. A revision is difference to a published version, so this is likely the right default behaviour.

From workbench moderation
<link rel="canonical" href="http://DOMAIN/node/2554/revisions/7834/view" />

From Diff (running under workbench moderation)
<link rel="canonical" href="http://DOMAIN/node/2554/moderation/diff/view/7834/8052" />

I'd create a new issue describing the issue better in the metatags queue and the maintainers can assess the best path forward for dealing with it

DamienMcKenna’s picture

@jacquesct: The architecture currently isn't designed for handling entity revision pages, you might need to add hook_metatag_metatags_view_alter() to a custom module and remove all meta tags from the page.

DamienMcKenna’s picture

Status: Needs review » Needs work

The last submitted patch, 14: metatag-n2217549-14.patch, failed testing. View results

  • DamienMcKenna committed 551b437 on 8.x-1.x authored by Alan D.
    Issue #2217549 by Alan D., Kuldeep K, DamienMcKenna: Integration with...
DamienMcKenna’s picture

Status: Needs work » Needs review
Parent issue: » #2898881: Plan for Metatag 8.x-1.3 release

I ran the tests locally and they all passed. Committed. Thanks all!

DamienMcKenna’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

DamienMcKenna’s picture

Status: Closed (fixed) » Needs work
Parent issue: #2898881: Plan for Metatag 8.x-1.3 release » #3300077: Plan for Metatag 7.x-1.30

This was committed to the wrong branch. Doh!

Let's add it to the next release for D7.

DamienMcKenna’s picture

Not knowing this issue existed, Antares89 added another issue and provided a patch there, so we'll give them credit too.

DamienMcKenna’s picture

Status: Needs work » Needs review
DamienMcKenna’s picture

Title: MetaTags integration with the Diff module » MetaTags integration with the Diff module (D7)
Parent issue: #3300077: Plan for Metatag 7.x-1.30 »

I need to work out what the next release of Metatag for D7 will be and include this. Because *facepalm*.

DamienMcKenna’s picture

DamienMcKenna’s picture

Rerolled.

  • DamienMcKenna committed 8a26c3e on 7.x-1.x
    Issue #2217549 by DamienMcKenna, Alan D., Kuldeep K, Antares89:...
DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. To the *correct* branch this time :-)

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.