I find this module useful (even more than Nodewords) because my simple need in the mean time is meta keaywords and description. I am missing, however, a possibility to be able to set the meta tags based on a path. A simple use would be for a contact module, for single views or panels ...

I might be able to work it out. I just need to make sure such approach is desirable at all.

Comments

valthebald’s picture

Title: Mate tags based on path » Meta tags based on path

Not sure I understand your idea. At which admin screen do you want to place these path-based meta tags?

john.oltman’s picture

I think he means a new admin screen. I have a module that is mostly done (metatags_extra) that does most of it. I'll post it soon, have some of my own site-specific code i need to isolate out first.

valthebald’s picture

completely new module? or you want to integrate?

john.oltman’s picture

Issue tags: +Meta tags, +drupal 7
StatusFileSize
new2.49 KB

Here's the module, it supports global default meta tags for non-node paths, global keywords for nodes, the option to default node description to the node teaser it it exists as a separate summary and there isn't already a meta description, and path-specific keywords and description for non-node paths. It would be nice to have it be a separate module inside the quick folder, so that it downloads with quick, but you can choose not to enable it, similar to the ways Views and Views UI works etc. That way if you only require the node tags that quick provides, you don't add overhead to your site.

Two things need to happen from here:

* Right now you have to hand code SQL to insert rows into the metatags_extra table, one for each non-node path for which you want override tags. I only have a few such paths on the site that I needed overrides for, so coding a few SQL statements was cake, but someone should code up a Drupal admin screen similar to String Overrides so you can use an interface instead.

* Ideally, the admin screens for this module are somehow combined with quick (not the module, just the links to the extra settings pages) so that there aren't separate links within the Structure page, one for quick, and one for extra. There should probably just be a single link on the Structure page named Meta Tags that brings up a page that links to both or has field sets for both.

If people like this direction, then I may have some time to do this within the next few days, or if someone else wants to have at it, go for it. Just let me know so we aren't duplicating efforts.

valthebald’s picture

Thanks John,
I will look at the code later tonight

valthebald’s picture

Hi john,
I have reviewed your code.
In general, I think it's a good idea to provide optional meta management for pages that do not represent single entities (like views, node etc.)
Your code supports only keywords and description meta tags, because these are hard coded fields in metatags_extra table. Probably it's better to take field list from field instances, and store meta data in rows like field_id = field_value

john.oltman’s picture

Yes, supporting any meta fields would be better. I'll see about generalizing it, in the meantime, the module could get someone by in a pinch. Also, anything node related should probably be moved into quick, so that extra is just for non-node tags.

valthebald’s picture

What about the following schema (metatags_extra.install)

  $schema['metatags_extra'] = array(
    'description' => 'Stores information about meta tag fields for non-entity pages.',
    'fields' => array(
      'pid'  => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Foreign key: pid from url_alias',
      ),
      'fid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'description' => 'Foreign key: id from field_config',
      ),
      'value' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'description' => 'Field value',
      ),
    ),
    'primary key' => array('pid', 'fid'),
    'foreign keys' => array(
      'url_alias' => array(
        'table' => 'url_alias',
        'columns' => array('pid' => 'pid'),
        ),
      'field_config' => array(
        'table' => 'field_config',
        'columns' => array('id' => 'fid'),
        ),
    );

?
With such schema, you can handle all installed meta fields.
In edit screen, you can jusr retrieve all fields handled by metatags_quick module.

dave reid’s picture

Treading more and more towards metatags.module functionality...

valthebald’s picture

Show me the code, Dave :)

dave reid’s picture

@john.oltman: You may be interested in subscribing to #1151926: Allow meta tags to be assigned to custom paths which is the planned feature in the Meta tags module. This is possibly out of scope for the metatags_quick module. I'm also wondering what you use case is for custom paths that integration with Views or Panels wouldn't solve - in which case you also may want to track the following Meta tags issues: #1151936: Ensure Metatag works OOTB using Views to display Drupal core's entities and #1151938: Panels integration - meta discussion.

john.oltman’s picture

Thanks Dave, I will subscribe to those issues. Apart from entities, views and panels, I see the following use cases for meta tags:
* Front page - many sites have a custom front page that isn't a node
* Custom module pages - many sites use custom modules that expose pages - these require tags
* Global default keywords (ideally, could be different for each of entities, views, panels, custom paths)
* Ability to default node meta description to the node teaser

I am launching a D7 site this week (D5-to-D7 conversion) that requires all of these, therefore I cannot wait for the real meta tags module. Also, while some "legacy" custom modules can be discarded in favor of views and panels, in other cases it is more straightforward and therefore less risky to simply update the module code to the new D7 APIs. The need for "custom path" meta tags is very real and very important for these types of sites. I definitely understand why you would focus on the 80% case, so there may yet be a need for a supplemental module to cover the 20%.

valthebald’s picture

Version: 7.x-1.6 » 7.x-1.x-dev

Hi John,
do you still plan to implement metatags_extra module? What is its status?

john.oltman’s picture

@valthebald, I was waiting to see how things were shaking out with metatags_quick and some of the other issues. Would you still consider it worthwhile if I do the following:

* Move the node features of "extra" into "quick" (global node keywords, optionally use summary as meta description)
* In "extra", implement non-node path tags for meta keywords and description only, with global defaults (using my hard coded table structure), including an admin screen.

Your comments in #8 make sense, but I don't think I have the time for that, and it may be duplicative of what the real meta tags module will eventually provide.

If you want to move forward, let me know if you want this as a Git patch, or want to make me a co-maintainer. Whatever you prefer. Thanks again for your work on this module, very much appreciated by all.

valthebald’s picture

@john.oltman thanks for warm words!
I needed some time to think about your suggestion, thus a delay...
I think that there is a need in path-based meta tags.
However, I am not sure how they would coexist with entity-based meta tags.
I think that correct and consistent way is to link paths or path aliases with existing fields.
Thus it's possible to solve several problems:

  • No restriction to only keywords and description, expandable
  • i18n support (missing in suggested schema)
  • Same output processing as in entity-based meta tags, easier maintenance

Hard-coding 2 possible meta tag types may solve this moment's need, but I think that with (not huge) additional effort we can get much better solution. Keep in mind that in any case metatags_extra code needs some work to accomplish. In fact, without that change metatags_extra is more of another solution to the meta tags problem, not an addition to metatags_quick (which is absolutely fine, by the way).
Are you ready to make that effort?

rovo’s picture

I agree, this is definitely a much needed feature addition for those very reasons:

* Front page - many sites have a custom front page that isn't a node
* Custom module pages - many sites use custom modules that expose pages - these require tags
* Global default keywords (ideally, could be different for each of entities, views, panels, custom paths)
* Ability to default node meta description to the node teaser

john.oltman’s picture

Sorry for the delay - yes @val, I'll try your approach, perhaps it will be easier than I am thinking. I'll start on it within the next couple of days and hope to have something to you by June 1.

valthebald’s picture

Great, @john.oltman!
If you want to discuss details or other help from me - let's meet in IRC

JohnnyX’s picture

I'm searching for a possibility to add keywords and description also to views. It seems metatags_extra is the solution for me? :)

valthebald’s picture

#19: yes, definitely.

john.oltman’s picture

Ok @valthebald, here you go. The patch adds defaults for node pages to meta quick; the node defaults are specific to description and keywords. These have to be hard-coded for those meta names because the functionality only applies to those tags (similar to how you hard code the basic meta tag fields if none exist). The revised metatags_extra module handles the meta tags definition and defaulting of non-entity paths for all meta tags defined in the installation; all the node related functionality is moved into the meta quick patch. I adopted some elements of your generic field schema, although I had to retain a serial number to make the editing work. I removed the foreign key to the url_alias table, as the non-entity paths do not generally appear in that table.

There is a new admin screen that allows administrators to inputs paths and the meta tags for those paths. The paths are checked to ensure they are existing internal non-entity paths. The display is similar to the URL alias admin screen.

valthebald’s picture

Cool. Got homework to do :)
Thanks!

valthebald’s picture

Just rolled out 7.x-1.8 to fix project state before adding new features.
Git rocks!

john.oltman’s picture

@valthebald, fyi, the most recent metatags_extra module in #21 has this warning:

PHP Warning: Call-time pass-by-reference has been deprecated in /var/www/html/sites/all/modules/metatags_quick/metatags_extra/metatags_extra.module on line 25

You'll need to remove the unnecessary ampersand from that line of code.

valthebald’s picture

Version: 7.x-1.x-dev » 7.x-2.x-dev
Assigned: Unassigned » valthebald
Issue tags: +Path based meta tags

Hey guys,
I'm glad to announce that path-based meta tags are working.
I have taken original code of john.oltman from #21 and added it (with modifications) to the main module tree.
Due to the large number of changes, I think it's worth starting new series.
So please welcome first working release of 7.x-2.x branch.

Matter of change: hook_page_build checks either we build (fieldable) entity page (node, user etc.), or not
If fieldable entity detected, regular Fields API is used.
If not (default front page, views page etc.), module retrieves path-based tags

john.oltman’s picture

Getting this on a view when submitting a keyword and description, I'll see if I can dig into it more later and come up with a fix, but wanted to put this out there:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'archive%2F201104-en' for key 1: INSERT INTO {metatags_quick_path_based} (lang, path, fid, value) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3); Array ( [:db_insert_placeholder_0] => en [:db_insert_placeholder_1] => archive%2F201104 [:db_insert_placeholder_2] => 8 [:db_insert_placeholder_3] => more desc ) in metatags_quick_admin_path_submit() (line 170 of /var/www/html/sites/all/modules/metatags_quick/metatags_quick.admin.inc).

valthebald’s picture

I guess you've downloaded it from releases link? It takes some time for d.o. to put latest commits into tarballs.
You can get latest version via git

michèle’s picture

Hi valthebald

Many thanks!
Unfortunately I get the following error, when I try to update to version 7.x-2.x-dev:

PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table '24362_drupal7.metatags_quick_path_based' doesn't exist: SELECT pv.fid AS fid, pv.value AS value FROM {metatags_quick_path_based} pv WHERE (lang = :db_condition_placeholder_0) AND (path = :db_condition_placeholder_1) ; Array ( [:db_condition_placeholder_0] => de [:db_condition_placeholder_1] => admin/modules ) in metatags_quick_page_build() (line 196 sites/all/modules/metatags_quick/metatags_quick.module).

I did not unistall the version 1.8 before, because I am not shure, if my meta tag fields are remaining in the database...

I'm looking forward to use the new path-feature! :-)

Regards, Michèle

valthebald’s picture

Upgrade from 7.x-1.x to 7.x-2.x should be smooth.
metatags_quick_path_based table should be created by database update script, did you run update.php?

michèle’s picture

@valthebald
you're right - all works fine after running update.php. sorry for this... i think i had a too short night yesterday... ;-)
best regards, michèle

michèle’s picture

Sorry to bother you again, Valery...

In the meantime, I successfully have installed the alpha1 version of your module.
I can see the path to the meta tags quick configuration page (/admin/config/search/metatags_quick), but I can't see any message about the path dependent meta tags.
After scanning your module code, I realized that the correct URL to insert the path dependent meta tags is i.e. /admin/config/search/metatags_quick/path/news for a view which creates a page with the path /news. After filling out the little form, the entered values are stored in the table metatags_quick_path_based, but instead of the path "news", the word "path" is saved inside of the path field... If I change "path" to "news", all works like a charm.

Am I missing something, or is the admin backend for path dependent meta tags not yet supported by the alpha version of the 2.x branch? (which certainly would not be any problem - I'm really happy that it works even if I have to hardcode it inside of the database table! :-)

Many thanks again
Michèle

JohnnyX’s picture

I installed the alpha. There seems no admin backend buut you should see a "Edit meta tags" link if you display the page (frontend) in the tabs. Here you can set description and keywords

michèle’s picture

Thanks JonnyX. Your're right! I've searched through the whole admin backend, but in the end, the solution is so obvious... ;-)

valthebald’s picture

Really nice to see other people helping to each other! Keep that way!

JohnnyX’s picture

Mh, I set keywords and description at a view. Values saved and there but I don't can find the meta keywords and descriptions in source code... Maybe a bug? Cache cleared some times. Caching at views configuration was disabled.

valthebald’s picture

Status: Active » Fixed

Works much better in alpha4 - tested for views, nodes, taxonomy terms and front page + multilingual support

Status: Fixed » Closed (fixed)

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

tomsherlock’s picture

Looking at the UI, it is not clear to me how I associate a meta tag with a path.

Under configuration, I've already selected Description and Keywords for path based meta tags. I see the tab for managing fields and I know when I look at content types I can add meta tags. Also when I edit a particular tag I can see the keywords field and description field. What am I missing?

BTW, you might want to consider changing the default labels to something like meta keywords and meta description to avoid name clashing.

Thanks for your efforts. This module is much appreciated.

tomsherlock’s picture

How do you test for Views?
I only see:
Comment
Path-based meta tags
Node
Taxonomy term
User

listed on the config page.

Under manage display I see: "Use custom display settings for the following view modes". Should I be seeing a list of Views below that sentence?

BTW, you might consider adding a config link from the modules page as well.

valthebald’s picture

First, please open new issue in separate issue (sorry for truism) - this thread is closed
Second, if you enable path-based meta tags, you will see 'Edit meta tags' link on the views page (important - not in the views edit screen!). Probably this should be addressed in documentation, but I'd like to finish functionality first

drupalpal’s picture

The most important thing is to remember to create and attach path based meta tags first from /admin/config/search/metatags_quick, just in case someone is struggling to get this working.