Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joachim’s picture

marcingy’s picture

Status: Needs review » Reviewed & tested by the community

This makes complete sense.

My only thought is would it make sense that a $form array could be an optional parameter to allow for options list to also be generated contextually on form parameters? (and this of course is a seperate issue and needs tweaks 'upstream' in code).

joachim’s picture

I'm not sure that would be doable without major changes -- certainly while working on Reference Option Limit module I discovered that hook_field_widget_form_alter() doesn't have a complete $form array to work with.

Thanks for the review :)

catch’s picture

Title: pass all the parameters of hook_options_list() to options_list_callback » Change notification for: pass all the parameters of hook_options_list() to options_list_callback
Category: feature » task
Priority: Normal » Critical
Status: Reviewed & tested by the community » Active

Makes sense to me, committed/pushed. Will need a change notification.

tim.plunkett’s picture

Status: Active » Needs review
Issue tags: +Needs backport to D7

So, in #1541792: Enable dynamic allowed list values function with additional context, list_allowed_values() was converted pass all parameters, in both D7 and D8.
Is this getting backported as well? Adding the tag for now.

Added a change record.

Also, just pointing out #1548004: Allowed values functions are undocumented.

We'd also need to convert list_test_allowed_values_callback().

effulgentsia’s picture

Title: Change notification for: pass all the parameters of hook_options_list() to options_list_callback » Pass all the parameters of hook_options_list() to options_list_callback
Version: 8.x-dev » 7.x-dev
Category: task » feature
Priority: Critical » Normal
Status: Needs review » Patch (to be ported)
Issue tags: -Needs backport to D7

As I understand it, API additions are backportable, so updating issue accordingly, now that we have the change record.

effulgentsia’s picture

Version: 7.x-dev » 8.x-dev
Status: Patch (to be ported) » Needs work
Issue tags: +Novice

We'd also need to convert list_test_allowed_values_callback().

Sorry. Missed that part. Yes.

dsdeiz’s picture

FileSize
539 bytes

Hi, wondering if this is the only change?

dsdeiz’s picture

Status: Needs work » Needs review
effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community

Thanks.

cweagans’s picture

tim.plunkett’s picture

Category: feature » task
FileSize
569 bytes

List is now Options.

catch’s picture

Version: 8.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed/pushed to 8.x, moving to 7.x for backport again.

oriol_e9g’s picture

Status: Patch (to be ported) » Needs review
FileSize
1.99 KB
Anonymous’s picture

I've tested out the patch - looks good to me. Is there any chance this can get some attention again and make it into 7 core?

joachim’s picture

Issue tags: -Novice, -Needs backport to D7

#14: 1621356-14.patch queued for re-testing.

  • catch committed f70b54e on 8.3.x
    Issue #1621356 by joachim: Added pass all the parameters of...
  • catch committed f1cd0a5 on 8.3.x
    Issue #1621356 by joachim, dsdeiz, tim.plunkett: Pass all the parameters...

  • catch committed f70b54e on 8.3.x
    Issue #1621356 by joachim: Added pass all the parameters of...
  • catch committed f1cd0a5 on 8.3.x
    Issue #1621356 by joachim, dsdeiz, tim.plunkett: Pass all the parameters...
geru’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Is it safe to say that this has been reviewed and tested by the community after it's been three years and it's been ported to D8?

Seems to work fine. Can someone push this to core of D7?

oriol_e9g’s picture

Maybe we need to retest 3 years later, re-uploaded the patch for testing.

stefan.r’s picture

Issue tags: +Pending Drupal 7 commit

Looks good, I think if we publish a change notice this can go into a bugfix release

  • catch committed f70b54e on 8.4.x
    Issue #1621356 by joachim: Added pass all the parameters of...
  • catch committed f1cd0a5 on 8.4.x
    Issue #1621356 by joachim, dsdeiz, tim.plunkett: Pass all the parameters...

  • catch committed f70b54e on 8.4.x
    Issue #1621356 by joachim: Added pass all the parameters of...
  • catch committed f1cd0a5 on 8.4.x
    Issue #1621356 by joachim, dsdeiz, tim.plunkett: Pass all the parameters...
stefan.r’s picture

Issue tags: +Drupal bugfix target
stefan.r’s picture

Issue tags: +Needs change record
stefan.r’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Committed and pushed to 7.x, thanks!

  • stefan.r committed ffe9f91 on 7.x
    Issue #1621356 by oriol_e9g, joachim, tim.plunkett, dsdeiz: Pass all the...
MegaChriz’s picture

Status: Fixed » Needs review

This change broke the Feeds module. See https://www.drupal.org/pift-ci-job/586774
Is taxonomy_allowed_values() not supposed to be called directly by contrib? If so, I think that the function docs should mention that.

If taxonomy_allowed_values() isn't expected to be called directly, please notify when the next Drupal core release is being made so I can create a new Feeds release on the same day.

MegaChriz’s picture

Status: Needs review » Needs work
geru’s picture

Status: Needs work » Needs review
FileSize
1.49 KB

I think this is easily resolved by just setting default values in taxonomy_allowed values.

MegaChriz’s picture

The added parameters aren't used at all in taxonomy_allowed_values(), so I'm wondering why they needed to be added. PHP allows us to pass extra parameters to a function even if not defined in the function signature. Is it only for consistency? If so, is that worth an API break?

MegaChriz’s picture

@geru
Note that your patch will fail to apply, as it isn't made against the latest dev. Most of the changes in your patch are already committed.

Status: Needs review » Needs work

The last submitted patch, 30: defaultvaluesnull.patch, failed testing.

geru’s picture

OK. So, the answer options are:

  • either remove the parameters from taxonomy_allowed_values()
  • or put them in and set their defaults to NULL.

Which is the best?

joachim’s picture

> If taxonomy_allowed_values() isn't expected to be called directly, please notify when the next Drupal core release is being made so I can create a new Feeds release on the same day.

It's an implementation of a callback, so just as hook implementations shouldn't be called directly, I'd say callback implementations are the same. At least, that should be the case. Is there an API to get a field's allowed values?

David_Rothstein’s picture

Based on the above, I rolled this back for now. taxonomy_allowed_values() is a public API function (and documented as such) and I think it's used other places in contrib and custom code too, so this definitely does look like a problem.

The change record for this issue (https://www.drupal.org/node/1638360) is a little confusing in that it mixes a couple things together... but it's also 4 years old (and partially associated with a different issue that was fixed 4 years ago) so I didn't bother pushing it back to draft state. It will need some edits and/or a new change record when this gets committed again, to clarify which types of callbacks the API addition actually applies to.

  • David_Rothstein committed 13ece45 on 7.x
    Revert "Issue #1621356 by oriol_e9g, joachim, tim.plunkett, dsdeiz: Pass...
geru’s picture

Then, can we not just put the default NULL values for the added parameters and call it a day?

David_Rothstein’s picture

Personally I don't see the point in adding new optional parameters to a function when the function doesn't actually use them :) So I would vote for not changing taxonomy_allowed_values() at all.

Some of the documentation that was added here could be used in #1548004: Allowed values functions are undocumented instead. I'll mark that issue for Drupal 7 backport now.

geru’s picture

The reason is to make the default taxonomy_allowed_values() function compatible with the new callback having multiple parameters.

The reason that I am here on this list is because I want to implement my own allowed_values_callback that takes into account the extra parameters in order to provide instance-specific allowed values instead of field-specific allowed values.

Furthermore, there is a module called content_taxonomy with more than 21,000 sites that promises to provide instance-level functionality, but can not because the instance information is lost.

If we go ahead and put the added parameters defaulted to NULL in the default taxonomy_allowed_values() function, then we should be able to make this work for everyone.

geru’s picture

Status: Needs work » Needs review
FileSize
1.49 KB

Here is a patch against core 7.53 with NULL defaults in added parameters of taxonomy_allowed_values()

oriol_e9g’s picture

Added spaces for coding standards.

geru’s picture

@MegaChriz
Did patch #42 resolve the issue in #28?

MegaChriz’s picture

As proposed by David_Rothstein in #39, taxonomy_allowed_values() is better to leave untouched:

Personally I don't see the point in adding new optional parameters to a function when the function doesn't actually use them :) So I would vote for not changing taxonomy_allowed_values() at all.

As documented on https://www.drupal.org/docs/develop/coding-standards/api-documentation-a... the parameters of a callback function should be documented in a *.api.php file. As the taxonomy module is invoking the callback here, the callback should be documented in taxonomy.api.php.

New patch attached.

Status: Needs review » Needs work

The last submitted patch, 44: drupal-pass-all-parameters-1621356-44.patch, failed testing.

geru’s picture

The patch looks good to me and applies cleanly. Does anyone have a line on what testing it failed in #45?

MegaChriz’s picture

Status: Needs work » Needs review

It looked like a random test failure. Tests are passing now, so setting back to "Needs review".

geru’s picture

I have tested this and confirm that it works as expected on my installation. Would it be reasonable to mark it as reviewed and tested by the community?

kristiaanvandeneynde’s picture

Status: Needs review » Reviewed & tested by the community

Yes it would. Code looks good, several people tested it.

geru’s picture

So, to migrate this into core, should the status be changed to Patch to be ported, or Fixed?

MegaChriz’s picture

@geru
No, the status "Fixed" would mean that - in this case - the patch was committed. The status "Patch (to be ported)" would mean that the patch was committed as well but the changes are needed for an other major version of the project as well. See https://www.drupal.org/node/156119 for more information about what each status means.

The next step for getting this change in is that a core maintainer reviews the patch and then eventually commits it if he/she has no concerns about it. What could help though is if more people would review the patch: that indicates that there are more people in favor of this change and if the reviews are thorough it would give the core maintainer more trust that the patch doesn't introduce unwanted side effects.

geru’s picture

@MegaChris, Thank you for the link about status settings.

@kristiaanvandeneynde reports that several people tested it.

I just wanted to make sure that it was not forgotten.

joachim’s picture

Status: Reviewed & tested by the community » Needs work

Looks good.

Just one nitpick:

+++ b/modules/taxonomy/taxonomy.module
@@ -1644,10 +1644,16 @@ function taxonomy_field_formatter_view($entity_type, $entity, $field, $instance,
 /**
  * Returns the set of valid terms for a taxonomy field.
  *
- * @param $field
+ * Also used as a callback for taxonomy_options_list().

Docs should start with 'Implements callback_foo().'

We should also add an issue to document allowed_values_function in list module.

MegaChriz’s picture

@joachim
What if a function is used both as a "general" function and as a callback? The thing is that this function is also used now in a non-callback context. I think giving this function the "callback" status now would indicate that it should no longer be called directly? My concern is that future changes may break contrib code: because if the consensus is that a callback shouldn't be called directly, its signature may be freely changed. What's your opinion about this? Do you think it is a valid concern?

joachim’s picture

I think it's definitely a valid concern, but it's also incorrect use of the code, the same that calling a hook implementation directly is wrong. Unfortunately, core's unclear documentation, which predates the more formal notion of a documented callback is responsible here, not the developers who have done this in their code.

One possible way forward would be to this:

- say that taxonomy_allowed_values() is an API function, available to be called by any code. People already calling this are unaffected.
- add a new callback function for taxonomy_options_list(), implementing callback_taxonomy_options_list(), say taxonomy_options_list_default(). This is a callback implementation and therefore not meant to be called. This should wrap taxonomy_allowed_values(), but then we are free to change its parameters because it's internal.
- change taxonomy_options_list to call this new callback.

Would that mean that we don't break anything?

geru’s picture

@Joachim, So, is this held up because of the documentation in the header of the taxonomy_allowed_values() function?

If so, I would like to get it properly documented so we can move forward.

However, I am unclear on what it should look like. It already looks reasonably documented to me.

Your comment and quoted diff in comment #53 don't make sense to me.

The name of the callback is 'options_list_callback'. It is not 'callback_options_list' as suggested in your comment and it is not 'taxonomy_options_list()' as currently listed in the doc block.

If you might be able to write the doc block properly or educate me on how to write it properly, then, we should be able to get this patch of a single line of actual code incorporated into core.

joachim’s picture

@geru my comment #53 has been superseded by my proposal in #56...

But what I meant, for the record, is that callbacks in the abstract have to be named 'callback_foo()', the same way a hook is named 'hook_foo()'. Then an implementation of the callback, such as taxonomy_allowed_values(), should have as the first line of its docs: 'Implements callback_foo()'.

carsonblack’s picture

@joachim OK, So wouldn't the additions of documentation on line 1648 and 1657 from #44 above satisfy the requirements you state in #57? As for the proposal in #55 not sure what would be broken by the change on line 1497 of #44.

joachim’s picture

> So wouldn't the additions of documentation on line 1648 and 1657 from #44 above satisfy the requirements you state in #57?

No, because it's not the first line of the docblock and it's not correctly phrased. A callback implementation must have the first line of documentation in the format: 'Implements callback_foo()'.

> As for the proposal in #55 not sure what would be broken by the change on line 1497 of #44.

The patch in 44 doesn't cause the problem mentioned in #28, but it's not ideal, because it leaves us with a callback implementation that doesn't correctly implement the callback as it's missing parameters.

MegaChriz’s picture

Status: Needs work » Needs review
FileSize
2.98 KB
1.51 KB

I agree with joachim that functions that are used as callback function should be documented in a standard way. So ideally, a function shouldn't be both API and callback as that can cause limitations in the future: with my patch in #44 the implementation of the default callback for taxonomy_options_list() cannot be easily changed as adding more parameters would break the API.

I was still trying to figure out how to document in a standard way that a function may be used as API function. I could just add a line "Is an API function." in the function docs of taxonomy_allowed_values(), but somehow that looked a bit silly to me. I think a function that doesn't start with the word "Implements", should assumed to be usable as an API function. I did came across #983274: Mark API functions with @public in Doxygen as an example how a function can be explicitly marked as API function, but it doesn't look like that became a coding standard in Drupal, so would probably be awkward to use right now.

Anyway, here is a patch that follows the suggestions that were made in #55:

  • A function called taxonomy_options_list_default() is added that includes all parameters passed that are passed to the callback. The function is documented as a callback function following the standards at https://www.drupal.org/docs/develop/coding-standards/api-documentation-a....
  • Instead of taxonomy_allowed_values(), taxonomy_options_list_default() is now the default callback for taxonomy_options_list().
  • taxonomy_options_list_default() simply calls taxonomy_allowed_values().

  • catch committed f70b54e on 9.1.x
    Issue #1621356 by joachim: Added pass all the parameters of...
  • catch committed f1cd0a5 on 9.1.x
    Issue #1621356 by joachim, dsdeiz, tim.plunkett: Pass all the parameters...
anrikun’s picture

This is much needed. Could a maintainer review this?