Module Metatag released and working now (but alpha).
I think support migrate SEO data to Metatag fields very usefull for all.
Any patch yet?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nod_’s picture

Status: Active » Closed (duplicate)

I think it's a duplicate #1312982: Meta tags support

lancee’s picture

FileSize
513 bytes
jantoine’s picture

@lancee,

Could you provide an example of how to use this your metatag.inc file? I can't figure out how to use MigrateDestinationHandlers.

Thanks!

dsdeiz’s picture

Hi, would like to try my hands on this but was wondering if I'm correctly setting the tags. When doing a node_save(), should the property $node->metatags contain array('description' => array('value' => $description), 'keywords' => array('value' => $keywords));? Was wondering cause when I checked the table that metatags created, it contains a serialized data and when I unserialize it, I got that array. This is what I have when I tried to implement it.

/**
 * Basic support for metatags.
 */

class MigrateMetatagNodeHandler extends MigrateDestinationHandler {
  public function __construct() {
    $this->registerTypes(array('node'));
  }

  public function fields() {
    return array(
      'description' => t('Node: Metatag description.'),
      'keywords' => t('Node: Metatag keywords.'),
    );
  }

  public function prepare($entity, stdClass $row) {
    if (module_exists('metatag') && ($entity->description || $entity->keywords)) {
      $entity->metatags = array();
      if (isset($entity->description)) {
        $entity->metatags['description'] = array('value' => $entity->description);
      }
      if (isset($entity->keywords)) {
        $entity->metatags['keywords'] = array('value' => $entity->keywords);
      }
    }
  }
}
alanburke’s picture

Assigned: Unassigned » alanburke
Status: Closed (duplicate) » Needs review

Working code in this one, so reopening, and set the other as the duplicate.
Patch attached - thanks for the code.

alanburke’s picture

Patch attached

mikeryan’s picture

Project: Migrate Extras » Metatag
Version: 7.x-2.2 » 7.x-1.x-dev
Component: Migrate Extras Features » Code
Assigned: alanburke » Unassigned
Priority: Major » Normal
Status: Needs review » Needs work

This would best go into the Meta tags module itself. This patch would need the following changes:

1. Add metatag_migrate_api().
2. Rename metatag.inc to metatag.migrate.inc, so hook_migrate_api() can be found automatically.
3. Add metatag.migrate.inc to location.info.

DamienMcKenna’s picture

Thanks guys.

Leaving this as Needs Work as it also should use the APIs to identify which meta tags are available rather than hardcoding a few specific ones.

DamienMcKenna’s picture

Title: Support Metatag fields » Support Migrate module for importing data into Metatag
mjvandermeulen’s picture

@alanburke

An example is needed to understand how to use your patch #6

I'm in the same boat as AntoineSolutions:

I can't figure out how to use MigrateDestinationHandlers.

sylus’s picture

Here is an updated patch that doesn't use hardcoded values and seems to work fairly well in testing.

Only problem noticed is that can't see to set title metatag as conflicts with title field. Custom Metatags work as expected.

DamienMcKenna’s picture

Ack, the page title problem sucks. I'm somewhat tempted to rename that metatag to "page_title" internally..

Manovra76’s picture

For node all it's ok, but migrate metatag in term.....not work. no message, nothing. Any idea?

damiankloip’s picture

Status: Needs work » Needs review
FileSize
1.58 KB

I have cleaned up this patch a bit and removed some stuff we don't need.

I'm not sure what I'm missing with the title issue? This seems to be working OK for my purposes so far.

damiankloip’s picture

FileSize
1.59 KB

Oops, sorry. A working one.

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed! Good work, everyone!

Status: Fixed » Closed (fixed)

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

dsdeiz’s picture

Status: Closed (fixed) » Active

Hi! For the registerTypes bit, perhaps this can be used?

public function __construct() {
  $types = array();
  foreach (entity_get_info() as $entity_type => $entity_info) {
    if (isset($entity_info['metatags']) && $entity_info['metatags']) {
      $types[] = $entity_type;
    }
  }

  $this->registerTypes($types);
}

This way custom entities can be supported. Also I think there's a type in metatag.api.php:

* To enable Metatag support in custom entities, add 'metatags' => TRUE to the
* entity definition in hook_entity_info(), e.g.:

Oh, and I think the classes are encouraged to be explicitly registered on 2.5 so I guess metatag_migrate_api becomes:

function metatag_migrate_api() {
  $api = array(
    'api' => 2,
    'destination handlers' => array(
      'MigrateMetatagHandler',
    ),
  );

  return $api;
}
DamienMcKenna’s picture

@dsdeiz: Thanks for noticing my #facepalm-worthy typo, I've added a new issue to handle the fix: #1886170: 'metatag'=TRUE incorrect in metatag.api.php

dsdeiz’s picture

FileSize
889 bytes
dsdeiz’s picture

Status: Active » Needs review
DamienMcKenna’s picture

Status: Needs review » Fixed

Committed, thanks dsdeiz.

robbertnl’s picture

Is an example already available? Do you have to use another MigrateDestination for metatags?
For now i am just doing an dbmerge in my complete function of my import class, which uses MigrateDestinationNode. Dirty, but it works.

DamienMcKenna’s picture

Status: Fixed » Closed (fixed)

1.0-beta6 is out, so I'm closing this issue in the interest of keeping the issue queue clean.

robbertnl’s picture

@#24 Does it include an example?

dsdeiz’s picture

Hi!

You have one destination for every available metatag property (or metatag "fields" - not sure what they're called). Here's an example of available fields/properties: https://www.evernote.com/shard/s276/sh/d0865c92-86ef-4fcf-bc54-a285d54a9...

It's then just a matter of mapping them e.g.:

    $this->addFieldMapping('metatag_description', 'description');
    $this->addFieldMapping('metatag_keywords', 'keywords');
    ...
    $this->addFieldMapping('metatag_source', 'source');
DamienMcKenna’s picture

Component: Code » Documentation
Category: feature » task
Status: Closed (fixed) » Active

Lets reopen this to add some documentation about it.

dsdeiz’s picture

Hi!

Here's a basic usage assuming the module name is metatag_migrate:

metatag_migrate.inc:


class MetatagTestMigration extends DynamicMigration {

  public function __construct() {
    parent::__construct();

    $this->description = t('Migrate test.');

    $this->map = new MigrateSQLMap(
      $this->machineName,
      array(
        'id' => array(
          'type' => 'varchar',
          'not null' => TRUE,
          'length' => 254,
          'description' => 'ID of record.',
        ),
      ),
      MigrateDestinationNode::getKeySchema()
    );

    $this->source = new MigrateSourceCSV(
      drupal_get_path('module', 'metatag_migrate') . '/sample.csv',
      array(),
      array('header_rows' => TRUE)
    );

    $this->destination = new MigrateDestinationNode('article');

    $this->addFieldMapping('metatag_description', 'description');
    $this->addFieldMapping('metatag_keywords', 'keywords');
  }
}

metatag_migrate.migrate.inc:

/**
 * Implements hook_migrate_api().
 */
function metatag_migrate_migrate_api() {
  $api = array(
    'api' => 2,
    'migrations' => array(
      'MetatagTest' => array('class_name' => 'MetatagTestMigration'),
    ),
  );

  return $api;
}
DamienMcKenna’s picture

Status: Active » Needs review
FileSize
2.45 KB

This puts dsdeiz's example code into the metatag.migrate.inc file as a comment, and adds a note to the features list in README.txt to mention to look there for full details of how to use the Migrate integration.

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed. Thanks for the example code, dsdeiz!

dsdeiz’s picture

Status: Fixed » Needs work
-function metatag_migrate_api() {
+function example_migrate_api() {

I think it got overridden.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
340 bytes

#facepalm moment - string replacement unchecked.

DamienMcKenna’s picture

Status: Needs review » Fixed

Committed.

DamienMcKenna’s picture

Status: Fixed » Closed (fixed)

Now that v7.x-1.0-beta7 is out, I'm closing this in the interest of keeping the issue queue clean.