There are several problems with documentation of options on API pages such as:
https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Url.php/f...
a) The attributes element in $options is available, but not documented.
$url = Url::fromUri('http://google.com', array('attributes' => array('target' => '_blank')));
dpm($url);
$link = Link::fromTextAndUrl(t('Nutzungsbedinungen'), $url);
dpm($link->toString());
b) $options is a parameter in several from* methods on the Url object, and they say basically to see the fromUri() method for details. But the links are not getting made on api.drupal.org. To fix this, we need where it says
see static::fromUri() for details.
for it instead to say
see \Drupal\Core\Url::fromUri() for details.
c) The $options member variable and the get/set option/options methods on this class have no details about what the options are. They should also say "See \Drupal\Core\Url::fromUri() for details on the options."
d) We are documenting the $options parameter on several methods (3) but not all of them. We should either document it everywhere or do the "see ... for details" everywhere. Probably "see ... for details" is easier to maintain. So let's just leave it in one place and remove it from the others.
| Comment | File | Size | Author |
|---|---|---|---|
| #22 | problems_with-2700415-22.patch | 6.17 KB | dimaro |
| #22 | interdiff-2700415-18-22.txt | 407 bytes | dimaro |
| #18 | interdiff-2700415-16-18.txt | 473 bytes | rashid_786 |
| #18 | 2700415-18.patch | 6.18 KB | rashid_786 |
| #16 | interdiff-2700415-16.txt | 457 bytes | pushpinderchauhan |
Comments
Comment #2
skdrupal88Comment #3
skdrupal88Added documentation in patch.
Comment #4
jhodgdonWow. That is truly stupid. It looks like the main/only way to set attributes on a link is that you have to put them on the URL object. ?!? There is apparently no way to set them on the Link class, even though the Url class itself doesn't use them in any way, and the attributes are definitely part of the link.
Yeah, we should definitely document this. Thanks for filing this issue and making a patch!
So I think maybe we should mention that the options are used on the anchor tag if you use the \Drupal\Core\Link object to make the link. Someone could conceivably use a Url object without using a Link object and they wouldn't get any attributes on their anchor tag. So, could you fix that?
Also, I checked all the methods on the Url object that deal with $options, and I noticed that on api.drupal.org, not all of them are making the links. Could you fix this, as long as we're fixing this class doc up? We need where it says:
for it instead to say
And one more thing: it seems like the $options variable and the get/set option/options methods on this class should also say "See \Drupal\Core\Url::fromUri() for details on the options."
And... I don't think we need to be documenting the $options in 3 places. Let's have them all say to see the fromUrl() method for details. Or else we should add the documentation to the other methods that currently say to see the fromUrl() method for details.
Adding this to the issue summary.
Comment #5
skdrupal88I've asked similar question on Drupal answers today(see comments), and @mradcliffe provided very interested opinion about it, I hope he will join the discussion here.
Comment #7
nicolas.rafaelli commentedI hope this helps you.
Comment #8
jhodgdonThanks for the new patch! It's pretty close. Just needs a small fix in a few places, plus a few substantive fixes... it doesn't look like my comments in #4 were taken into account?:
The thing is, the Url object doesn't have an anchor tag. So here we need to make it clear that these attributes will be added to the anchor tag if you use the \Drupal\Core\Link object to make the link. I suggested this in #4. Please take care of it (in all of the places it is mentioned). Thanks!
An @see tag cannot have extra text, just the name of a function, class, method, etc. See https://www.drupal.org/node/1354#see for details.
So this should just use the word "See" not @see. And it needs to be moved up above the @var.
See above note about @see vs. See. Needs to be above the @return here.
See above.
See above.
See above.
Comment #9
nicolas.rafaelli commentedOh, sorry.
Before i send a new patch i need to ask.
Is this right?
You said above the @return, but i don't know if above the @param too.
Comment #10
jhodgdonYes, above @param and @return is correct.
However, for functions that have a $options parameter, the note should be with that parameter docs. So something like this:
Similarly, if the return value is the options, we should have something like this:
Thanks!
Comment #11
jhodgdonNote: I didn't check the word wrapping in #10. Documentation lines should be less than 80 characters long.
Comment #12
nicolas.rafaelli commentedThank you for your answers.
Sorry if i stole a little bit of your time.
Here's the new patch.
Comment #13
jhodgdonNot at all! Reviewing patches for API documentation in Drupal is what I do. A lot. I don't mind.
Anyway, this is looking better! A few small suggestions, and I think we'll be done in one more patch:
Let's take out the word "the" here. And in the other methods that have the same wording.
Hah. I think you took my exact wording. And when I look at it now, I think maybe instead of "object" near the end of this line, it should say "class"?
I think we don't need both of these additional lines. Let's take out the top one.
Same here, don't need both additional lines. Let's get rid of the top one.
Comment #14
David Hernández commentedNew patch provided fixing suggestions from comment #13
Comment #15
jhodgdonThis line still needs to be removed (the information is there a few lines down in the @param or @return).
So... the only other thing that kind of jarred me was that the wording about "see..." was a bit different in some places than others. But it is very clear everywhere, so I guess I won't worry about it. Let's just delete that one line and we'll be done. Thanks!
Comment #16
pushpinderchauhan commentedJust incorporated the above said change.
Comment #17
jhodgdonOh sorry, I guess there were two places that needed the same fix. Here's the other one:
In this documentation block, we also do not need both of the lines saying "see whatever for details".
The top one needs to go away.
The one in @param needs to stay. Thanks!
Comment #18
rashid_786 commentedUpdated patch with suggested changes.
Comment #19
rashid_786 commentedComment #20
dimaro commented@jhodgdon Maybe we need keep "Sets the URL options" ??
Comment #21
jhodgdonYes, we need "Sets the URL options". This tells us what the function does, and all functions need a one-line description. We just don't want two copies of "See .... for details". See #17. And #15.
Comment #22
dimaro commentedThis fix the comment mentioned above on #20.
Comment #23
dimaro commented@jhodgdon Looking a little in Url class I think that we could do a slightly better job of wrapping.
For example, the comments in the "fromRoute" function.
This would be within the scope of this task?
Comment #24
jhodgdonRE #23, I don't think that is within the scope of this issue. I would only say to rewrap lines that are related to the options (which is what this issue is about).
In which case, this patch looks fine. Thanks!
Comment #25
dimaro commentedTagging this issue.
Comment #26
alexpottCommitted 5be833e and pushed to 8.1.x and 8.2.x. Thanks!