Posted by lancee on September 20, 2011 at 7:52am
17 followers
| Project: | Metatag |
| Version: | 7.x-1.x-dev |
| Component: | Documentation |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
Module Metatag released and working now (but alpha).
I think support migrate SEO data to Metatag fields very usefull for all.
Any patch yet?
Comments
#1
I think it's a duplicate #1312982: Meta tags support
#2
#3
@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!
#4
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->metatagscontainarray('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.<?php
/**
* 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);
}
}
}
}
?>
#5
Working code in this one, so reopening, and set the other as the duplicate.
Patch attached - thanks for the code.
#6
Patch attached
#7
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.
#8
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.
#9
#10
@alanburke
An example is needed to understand how to use your patch #6
I'm in the same boat as AntoineSolutions:
#11
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.
#12
Ack, the page title problem sucks. I'm somewhat tempted to rename that metatag to "page_title" internally..
#13
For node all it's ok, but migrate metatag in term.....not work. no message, nothing. Any idea?
#14
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.
#15
Oops, sorry. A working one.
#16
Committed! Good work, everyone!
#17
Automatically closed -- issue fixed for 2 weeks with no activity.
#18
Hi! For the registerTypes bit, perhaps this can be used?
<?php
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:
Oh, and I think the classes are encouraged to be explicitly registered on 2.5 so I guess
metatag_migrate_apibecomes:<?php
function metatag_migrate_api() {
$api = array(
'api' => 2,
'destination handlers' => array(
'MigrateMetatagHandler',
),
);
return $api;
}
?>
#19
@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
#20
Patch attached for the changes for #1284756-18: Support Migrate module for importing data into Metatag.
#21
#22
Committed, thanks dsdeiz.
#23
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.
#24
1.0-beta6 is out, so I'm closing this issue in the interest of keeping the issue queue clean.
#25
@#24 Does it include an example?
#26
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.:
<?php$this->addFieldMapping('metatag_description', 'description');
$this->addFieldMapping('metatag_keywords', 'keywords');
...
$this->addFieldMapping('metatag_source', 'source');
?>
#27
Lets reopen this to add some documentation about it.
#28
Hi!
Here's a basic usage assuming the module name is
metatag_migrate:metatag_migrate.inc:
<?php
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:
<?php
/**
* Implements hook_migrate_api().
*/
function metatag_migrate_migrate_api() {
$api = array(
'api' => 2,
'migrations' => array(
'MetatagTest' => array('class_name' => 'MetatagTestMigration'),
),
);
return $api;
}
?>
#29
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.
#30
Committed. Thanks for the example code, dsdeiz!
#31
-function metatag_migrate_api() {+function example_migrate_api() {
I think it got overridden.
#32
#facepalm moment - string replacement unchecked.
#33
Committed.
#34
Now that v7.x-1.0-beta7 is out, I'm closing this in the interest of keeping the issue queue clean.