Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I am trying to use hook_ctools_content_subtype_alter() to modify one particular subtype, but it's not very useful because the information passed to the hook does not provide any reliable way to identify which subtype I'm working with.
The hook should be changed to pass in the subtype ID as well.
Comment | File | Size | Author |
---|---|---|---|
#15 | ctools-n2373297-15.patch | 1.41 KB | DamienMcKenna |
#1 | ctools-content-subtype-alter-provide-id-2373297-1.patch | 2.08 KB | David_Rothstein |
Comments
Comment #1
David_Rothstein CreditAttribution: David_Rothstein commentedHere is a patch. This also modifies the hook documentation to provide a more realistic example that targets a particular subtype.
The API.txt file still lists the old hook signature. Not sure if this patch should change that (or if the API version should technically be bumped)... maybe it should.
Comment #3
joelstein CreditAttribution: joelstein commentedThis patch is SO useful and still applies cleanly. Thank you! Let's commit it.
Comment #4
plopesc+1
I'm also using this useful patch because I need to modify a specific entity_field subtype.
Thanks!
Comment #5
dawehnerIs there a particular reason why we don't just merge the sub plugin ID directly into $subtype,
so the example code would look like this:
Comment #6
dawehnerIn general though I don't feel strong about that.
Comment #7
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedRTBC + 1
Comment #8
joelstein CreditAttribution: joelstein commented@dawehner: I'm okay with either solution, as long as it gets committed. :)
Comment #9
kevinsiji CreditAttribution: kevinsiji commentedComment #10
jenlampton+1 on RTBC from me. thanks @David_Rothstein!
Comment #11
rivimeyPatch applies cleanly to 7.x-1.x.
Code looks good and is 'obvious', with one exception. Would it be sensible to put a default value on the function, thus:
so that should some custom or contrib module code call this function, the value of $subtype_id (and thus the value passed to any hooked-in code) is defined? I guess at present it will get the value NULL; is that ok?
Other than that, good to go.
Comment #12
rivimeyComment #13
rivimeyComment #14
japerrySo this function seems to me like an API change, which doesn't seem like a good idea this far into d7. I don't mind going with dawehner 's suggestion in #5 though if someone wants to code up a patch for it.
Comment #15
DamienMcKennaLike this?
Comment #16
DamienMcKennaLets try to get this into 1.12.
Comment #17
Fabianx CreditAttribution: Fabianx at Tag1 Consulting commentedRTBC to #15
Comment #18
japerryYah, thats better. Fixed!
Comment #20
joelstein CreditAttribution: joelstein commentedThanks for committing this!
However, I found a couple scenarios where the subtype_id is still not being set. I opened a follow-up issue (with patch) at #2829782: hook_ctools_content_subtype_alter() does not *always* provide reliable way to identify the subtype being altered.
Comment #21
ecsabi CreditAttribution: ecsabi commentedHi, #1 was a life saver as it allowed me to use fivestar module in panels.
The patch worked nicely until CTOOLS 7.x-1.11.
Yesterday they released 7.x-1.12 which cannot be amended by the patch.
Could this patch be updated somehow please?
Thanks.
Comment #22
joelstein CreditAttribution: joelstein commentedHi ecsabi, you need to update your code to reference
$subtype['subtype_id']
instead of$subtype_id
. Also, you'll probably want the follow-up patch at #2829782: hook_ctools_content_subtype_alter() does not *always* provide reliable way to identify the subtype being altered.Comment #23
ecsabi CreditAttribution: ecsabi commentedI downloaded patch #1 and replaced all $subtype_id with $subtype['subtype_id']. Then I applied the patch. I'm still getting the same error (see below)
Checking patch ctools.api.php...
error: while searching for:
* This hook can be used to add things like 'render last' or change icons
* or categories or to rename content on specific sites.
*/
function hook_ctools_content_subtype_alter($subtype, $plugin) {
$subtype['render last'] = TRUE;
}
/**
error: patch failed: ctools.api.php:198
error: ctools.api.php: patch does not apply
Checking patch includes/content.inc...
error: while searching for:
// retained.
foreach ($subtypes as $id => $subtype) {
// Use exact name since this is a modify by reference.
ctools_content_prepare_subtype($subtypes[$id], $plugin);
}
$cache[$plugin['name']] = $subtypes;
error: patch failed: includes/content.inc:156
error: includes/content.inc: patch does not apply
Comment #24
DamienMcKenna@escabi: Please stop trying to apply patches from this issue, the patch has already been committed so it's already in the new 1.12 release.
If you are still having problems with your custom code, please look at joelstein's comment above and please try out the patch in #2829782: hook_ctools_content_subtype_alter() does not *always* provide reliable way to identify the subtype being altered.
Comment #25
ecsabi CreditAttribution: ecsabi commentedThank you both.
I used the new patch. The error is still there:
Undefined offset: 1 in fivestar_ctools_content_subtype_alter() (line 1023 of /home/sites/mysite.co.uk/public_html/sites/all/modules/fivestar/fivestar.module)
Comment #26
rivimey@ecsabi please tell us exactly what you are doing. For example:
Comment #27
DamienMcKenna@escabi: That error is in Fivestar, not CTools. I don't see fivestar_ctools_content_subtype_alter() in the current Fivestar codebase, so that must come from a patch. Please check with the Fivestar patches you're using, see which of them adds that function and report in the corresponding issue that it needs to be updated.