Allows other modules (such as Taxonomy Redirect) to use hook_entity_info_alter to change the URI callback and thereby modify the links system-wide.

Comments

MGParisi’s picture

I've looked at this patch and am interested in what you plan to use hook_entity_info_alter for. I want to be careful with this module as it is listed as stable and I don't want people to have to alter their sites for it. But I would like it to use entity's rather then nodes and also to include functionality to plug into the module. I think I would like to see a complete change over to entities instead of nodes for a 2.0 version! I am not (in anyway) dismissing this patch, just wondering if we can do more with it!

Matthew Davidson’s picture

My immediate use case is pretty embarrassingly hacky. If a term link is displayed in a view page that accepts terms from that vocabulary as arguments, make the link to this view rather than Taxonomy module's default term page. eg. something like:

/**
 * Implements hook_entity_info_alter().
 */
function my_module_entity_info_alter(&$entity_info) {
  $entity_info['taxonomy_term']['uri callback'] = 'my_module_term_uri';
}

function my_module_term_uri($term) {
  if ($_GET['q'] == 'view/foo' && in_array($term->vocabulary_machine_name, array('vocab_1', 'vocab_2'))) {
    $options = array();
    $options['query']['field_' . $term->vocabulary_machine_name . '_tid[]'] = $term->tid;
    return array('path' => $_GET['q'], 'options' => $options);
  }
  // Fallback to taxonomy.module's default.
  return taxonomy_term_uri($term);
}

While I definitely think a totally-revamped entity-embracing 2.0 is a good idea - tag clouds of Entity references would be awesome - the above patch provides what I think most developers would consider the expected behaviour (i.e. if you change the taxonomy term URI callback it should have an effect on all Drupal-generated taxonomy term links), so it should go in the current stable version as well. If you don't have any modules that change the URI callback for taxonomy terms or nodes in hook_entity_info_alter(), of course this patch has zero practical effect. You can see the default functions taxonomy_term_uri() and node_uri() produce exactly the same paths as your existing code.

Taxonomy Term Reference Tree just committed a similar patch (#1505398: Term URI and load functions used when building field output should come from entity_get_info()), which you can consider support for my claim that the patch is pretty uncontentious.

MGParisi’s picture

Status: Needs review » Needs work

Applied patch and got this error twice:
Notice: Trying to get property of non-object in taxonomy_term_uri() (line 147 of D:\wamp\www\pictures\modules\taxonomy\taxonomy.module).

Matthew Davidson’s picture

StatusFileSize
new2.3 KB

The only reason I can think of for that behaviour would be if you had been deleted some terms, but there were still nodes that referred to them. If you load the same page without the patch applied do you have one or more links in the cloud that result in "Page not found"?

Don't have time to test it today, but this variation on the patch should eliminate the error messages and just not display links to terms that no longer exist.

MGParisi’s picture

The last patch works for me, Ill try to push it to dev for testing

MGParisi’s picture

Status: Needs work » Needs review

IF I did git right, it probably wont list under dev until tonight. Something tells me it wont publish under dev, but it is available under pending patchs.

Matthew Davidson’s picture

Thanks. By the way, I've been working like mad on this one huge project since late last year, and nothing I've done has impressed the client half as much as the ten minutes it took to enable the Tagclouds module and configure a view. My work may not be appreciated, but yours certainly is.

MGParisi’s picture

Can you test the new patch, before I publish.

Matthew Davidson’s picture

Done. Working fine as far as I can see.

MGParisi’s picture

Does it work with your code, and can we get some documentation on how to use it?
http://drupal.org/node/1317514 Would be the location of where we put tagclouds documentation...

MGParisi’s picture

Status: Needs review » Fixed

Committed

Matthew Davidson’s picture

I think the use of hook_entity_info_alter() to modify term links is to general (and advanced) to belong under the TagCloud module documentation. If anything you might just want to mention in passing that TagCloud now works with contrib or custom modules that alter entity URIs. (I just stumbled across Entity Path, which looks pretty cool.)

Status: Fixed » Closed (fixed)

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

  • Commit ef8ff7c on 7.x-1.x, 8.x-1.x by MGParisi:
    Issue #1507716 by Matthew Davidson Added entity_get_info()