What happens is that when you save a feature / export of a let's say a Page Manager variant that has a context to a taxonomy term. The export itself will reference the entity_id and not the uuid. This is troublesome when dealing with a deployment scenario.

The image of a feature export below further highlights the issue:

Features Export

Additionally it would be nice if there was an option for UUID contexts in the CTools selection screen(s):

CTools Export

Essentially what I did was ported the ctools/entity.inc context plugin to provide UUID support.

Also important to note the subsequent patch also provides an alternative for the autocomplete lookup to return a uuid.

Most definitely will need testing but seems to feature export / revert properly for me and would be awesome if UUID provided this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sylus’s picture

Issue summary: View changes
sylus’s picture

Status: Active » Needs review
FileSize
13.63 KB

Attaching the patch for review.

sylus’s picture

Issue summary: View changes
sylus’s picture

Title: CTools Contexts are missing UUID support when UUID module is enabled. » CTools Contexts are missing UUID support.
jsacksick’s picture

I applied your patch and got EntityMalformedException: Missing bundle property on entity of type taxonomy_term. in entity_extract_ids() (line 7734 of /projects/cellfish/www/includes/common.inc)., it seems that $context->argument should receive the entity id instead of the uuid, after I made the modification, everything worked as expected.

sylus’s picture

Status: Needs review » Fixed

Confirmed thanks for the fix! Thinking it is ok to set to RTBC now :)

sylus’s picture

Status: Fixed » Reviewed & tested by the community

joseph.olstad’s picture

RTBC++ , please commit

we're using uuid revision a7bf2db with this patch (and several others)

kyvour’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
13.7 KB

I was find few errors in patch #5.
For example, submission of settings form has an error, because function "entity_uuid_load" returns array keyed by ID? not by UUID.

function uuid_context_entity_uuid_settings_form_submit($form, &$form_state) {
  if ($form_state['values']['set_identifier']) {
    $entity_info = entity_get_info($form_state['values']['entity_type']);
    $entity = entity_uuid_load($form_state['values']['entity_type'], array($form_state['values']['uuid']));
    $entity = $entity[$form_state['values']['uuid']];
    $form_state['values']['identifier'] = $entity->{$entity_info['entity keys']['label']};
  }

  // This will either be the value set previously or a value set by the
  // validator.
  $form_state['conf']['uuid'] = $form_state['values']['uuid'];
}

In a function "uuid_context_create_entity_uuid" I also find errors. For example

  elseif (is_object($data)) {
    $uuids = entity_extract_ids($entity_type, $data);
    $uuid = $uuids[0];
  }

So, I have reviewed and fixed patch #5

joseph.olstad’s picture

Hi kyvour thanks for your new patch. See the next comment by Sylus

sylus’s picture

I took a look and all of the fixes seem more then reasonable. Before we RBTC again would be nice to get confirmation that doesn't have any regressions but looks great to me upon first glance. I especially like that the checks are more explicit and use uuid_is_valid and UUID_PATTERN throughout.

Thanks @kyvour.

joel_osc’s picture

I think there is an issue with this latest patch. We just updated a site to the latest wetkit distro which has this latest version of this patch and now there are errors:

Warning: array_flip(): Can only flip STRING and INTEGER values! in entity_uuid_id_cache() (line 460 of /var/www/html/dev3.openplus.ca/profiles/wetkit/modules/contrib/uuid/uuid.entity.inc).

What we found was that in the create context code $data looks like:

identifier (String, 20 characters ) Taxonomy term (UUID)
keyword (String, 13 characters ) taxonomy_term
name (String, 25 characters ) entity_uuid:taxonomy_term
uuid (String, 36 characters ) 66fcf83c-3e49-43b0-9c21-98d796895fbe
id (Integer) 1

Now the code looks like:

     68   // Attempt to retain compatibility with broken uuid:
     69   if (is_array($data) && !isset($data['entity_id']) && isset($data['id'])) {
     70     $id = $data['id'];
     71     $uuids = entity_get_uuid_by_id($entity_type, array($data['id']));
     72     $uuid = !empty($uuids[$id]) ? $uuids[$id] : FALSE;
     73   } 
     74   elseif (is_array($data) && isset($data['uuid'])) {
     75     $uuid = $data['uuid'];
     76   }

I believe since we already have the uuid, we should land in the code lines 74-76, however, we seem to go into the code at 69-73 and try to load a uuid for id=1. Maybe, @kyvour can explain what the purpose of this code is... if I change the code to be like this my site works fine:

     68   // Attempt to retain compatibility with broken uuid:
     69   if (is_array($data) && isset($data['uuid'])) {
     70     $uuid = $data['uuid'];
     71   } 
     72   elseif (is_array($data) && !isset($data['entity_id']) && isset($data['id'])) {
     73     $id = $data['id'];
     74     $uuids = entity_get_uuid_by_id($entity_type, array($data['id']));
     75     $uuid = !empty($uuids[$id]) ? $uuids[$id] : FALSE;
     76   } 
sylus’s picture

Hey @joel_osc can you push a new patch with this change? I can take a closer look but at first glance definitely looks like you are correct as we already have the UUID.

joseph.olstad’s picture

For what it's worth, I noticed a warning: array_flip... recently using the same/similar code base as Joel_osc. Not sure if it's related but it could be; in my case it seemed to disappear after I had backed off a core patch that has to do with caching and performance, once I backed that one off I did a "rr --fire-bazooka". then after the fire-bazooka I reapplied the reversed patch and didn't seem to see this warning come up however I'd have to really do lots more testing/debugging to actually confirm this and test Joel_osc's code change. Early next week I'll try out what is suggested in #13 as it would be nice to confirm that this is the solution. I'll be watching this queue closely either way.

joel_osc’s picture

Here is the patch with my change. Cheers.

skwashd’s picture

Project: Universally Unique IDentifier » Context UUID
Status: Needs review » Needs work

This patch appears to duplicate a lot of the functionality already in the Context UUID module. I am moving this to that project and the patch can be rerolled to implement any of the functionality that is missing from the existing module.

joel_osc’s picture

Project: Context UUID » Universally Unique IDentifier

I would disagree with that, the context module framework is a parallel framework to panels/ctools. If you use panels you would not use the context module. I am going to move this back so the issue does not get lost and let some of the others chime in here...thx.

sylus’s picture

Status: Needs work » Needs review

I agree with joel_osc as this isn't functionality for just the context module but ctools. I think this makes sense more for the UUID module to handle so Panels can have support for this as well.

skwashd’s picture

Status: Needs review » Needs work

Sorry for the misunderstanding earlier.

I looked over the patch, the doxygen docs are missing, incomplete or misleading. Please review the docs and fix them as needed.

joseph.olstad’s picture

@joel_osc , tested your patch and we no longer get array_flip notices in watchdog. haven't noticed any regressions. Looks good and thanks!

joseph.olstad’s picture

It looks like the following functions require doxygen docs.
function uuid_context_entity_uuid_get_child
function uuid_context_entity_uuid_get_children
function uuid_context_entity_uuid_settings_form
function uuid_context_entity_uuid_settings_form_submit
function uuid_context_entity_uuid_convert

and I believe the others that do have docs in the patch could be improved with a description of the function parameters and return value.

Here's the notes on coding-standards for docs.
https://www.drupal.org/coding-standards/docs#general

shadysamir’s picture

I applied the patch but I still can't see term uuid option in contexts in selection rule for the term_view page.

joel_osc’s picture

Did you add an 'entity uuid' context to your variant first? This will bring in your term as a context and then you can use any of the existing selection rules.

gnucifer’s picture

It would be nice also to be able to autocomplete on the uuid itself, for example for a site with A LOT of content and duplicate title it may be difficult to find the right one. I included an or query that also makes the autocomplete match on the uuid value.

(Based on patch in #16)

gnucifer’s picture

FileSize
615 bytes

Forgot to add interdiff.

kyvour’s picture

Status: Needs work » Needs review

Guys, it's important feature as for me. Why it doesn't committed to module? Is there a problem only in docblocks for the functions or something else?