Hi. I have my own entity which has no use for metatag module but metatag auto-injects itself into it's edit form. How to disable metatag for my entity? In metatag_entity_load there should be some setting for this. I don' want to create hook_entity_load just to unset metatag.

Comments

charlie-s’s picture

Ditto to this request. It's very cool that it auto-attaches itself to entities, but there are many entities that are not used in a standalone page format (field_collections being one, although they certainly can be displayed as a standalone page).

charlie-s’s picture

I don't know all of the procedures for doing this the right way. I imagined that the UI for this could provide an 'edit' button for the field settings on any fieldable entity's "manage fields" form, e.g. admin/structure/field-collections/field-name/fields, and that the 'edit' page would provide a checkbox to disable metatags for the field_collection (among other possible settings). But this approach kind of then requires that metatag's field settings would apply globally for an entity and not per bundle, right? Then that would be a bit funny since it doesn't appear to be working with bundles ATM.

If anyone reads this and knows where to start with changing the field options I'd love to hear it, I've been wanting to get a richer understanding of how fields infos are setup.

Anyways, in the mean time, here's what I'm doing to hide metatags from my field_collections:

<?php
hook_form_field_collection_item_form_alter(&$form, &$form_state) {
  $form['metatags']['#type'] = 'hidden';
}
?>
Anonymous’s picture

Issue tags: +memory, +entity, +entities

I'd also like to see this feature added to a settings page where you can select which entity types metatag should attach itself to. On our current project we have several extra entity types, but none of them needs metatags added, only nodes do. Disabling metatag frees up about 5MB of memory per pageload, which really is a lot and not acceptable.

kevinquillen’s picture

I tried this in a form alter:

if (!preg_match('/_node_form/', $form_id)) {
    $form['metatags']['#type'] = 'hidden';
    $form['redirect']['#type'] = 'hidden';
  }

My form fields updated to hidden, yet were still visible on the form. I also tried unset(), which took them out of the form array, but it still displayed on the add/edit form of custom entities where I do not need it. How can you effectively hide or get rid of this for forms?

longwave’s picture

Category: bug » support
Status: Active » Fixed

In hook_entity_info() you can set 'metatags' => FALSE, or similarly via hook_entity_info_alter():

/**
 * Implements hook_entity_info_alter().
 */
function MODULE_entity_info_alter(&$info) {
  $info['ENTITY_TYPE']['metatags'] = FALSE;
}
Anonymous’s picture

Status: Fixed » Closed (works as designed)

It works. Thanks. Maybe update a documentation or project page regarding this.

socialnicheguru’s picture

#5 worked for me

kenorb’s picture

Category: support » bug
Status: Closed (works as designed) » Active

I've custom form done in ctools (when calling ctools_wizard_multistep_form) and Metatag thing appears without reason and by default, so I don't see any reason that it should be there.
Following function:

function metatag_form_alter(&$form, $form_state, $form_id) {
  if (!empty($form['#metatags']) && !isset($form['metatags'])) {
    extract($form['#metatags']);
    metatag_metatags_form($form, $instance, $metatags, $options);
    unset($form['#metatags']);
  }
}

add metatag stuff to any possible form, which is very bad approach.
It cause serious problems with the theming.
I've tried #5, but it doesn't work.
In my opinion this needs to be fixed.

Workflow is as follow:

my_form(), ctools_wizard_multistep_form(), drupal_build_form(), drupal_prepare_form(), drupal_alter(), metatag_form_alter(), metatag_metatags_form(), metatag_get_info()

Related issue:
#1371968: Show/Hide Meta tags fieldset per content type

Workaround:

  $form = ctools_wizard_multistep_form($form_info, $step, $form_state);
  if(module_exists('metatag')){
    unset($form['metatags']);
  }
miaoulafrite’s picture

for field collection it would be:

$info['field_collection_item']['metatags'] = FALSE; 
murz’s picture

This way is only hides metatags from entity edit form, but not disable loading and other operations with metatags. So better is to create option in metatag module for disable metatags in custom entity.

murz’s picture

#5 solves the problem thanks.
But can I disable metatag by default for all entities and enable only for selected?
And will be good to see this feature configurable in metatag settings page, instead of php in custom module.

damienmckenna’s picture

StatusFileSize
new2.64 KB

A question for @davereid: should the module instead explicitly define (via hook_entity_info_alter()) which of the entity types support meta tag and not automatically assume everything does? Try this patch for size.

On an aside, I need to delve further into it to see if this really stops the API from trying to load.

damienmckenna’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, metatag-n1429100-12.patch, failed testing.

longwave’s picture

Agreeing with Damien here, many entities, custom or otherwise, do not need or use metatags, so providing them should be opt-in not opt-out.

kenorb’s picture

Yes, I agree, by default it shouldn't break the things (theme, etc.) after just enabling it.
See as well: #1644554: Wizard shows other module fieldsets on every step #4

Bensbury’s picture

I used the Module Hook solution to disable Meta Tags on field collections, but I also would like to decide which content types / entities use meta-tags.
For quite a lot of things I use it is unnecessary and I only hope to use meta-tags on my parent Node/Object.
eg. Node-blocks, content types which only appear as teasers or as a slideshow don't need them, comments, field collects and so on.

I think this is important because there doesn't appear to be any alternative to Meta Tags for D7.
Please share if I am wrong.

JvE’s picture

StatusFileSize
new6.18 KB

I've attached a quick little module I whipped up for this.

Install it and navigate to admin/config/search/metatags/optional to decide for yourself which things you want to disable metatags on.

damienmckenna’s picture

Tag.

dave reid’s picture

Status: Needs work » Closed (duplicate)

This will be solved with #1281770: Disable metatags by default on all entitity types, enable it only on needed and popular types - nodes, terms rather than forcing it to be defined in hook_entity_info(). Easier solution is to check if the entity type or bundle actually has configuration or not. This makes them opt-in rather than opt-out.

dave reid’s picture

Issue summary: View changes

added info