Follow-up to #2555825: Remove SafeMarkup::set call from TranslationManager::translate, where @catch said:

[Replacing a call to SafeMarkup::set() with SafeMarkup::setMultiple()] is an obvious hack but I think removing SafeMarkup::set() is more important than removing SafeMarkup::setMultiple() - the very difficulty getting it to work is at least some discouragement to use it - although I think we could add a follow-up to mark SafeMarkup::setMultiple() @internal - really no contrib or custom code should ever be using that.

Problem/Motivation

No contrib/custom module should use SafeMarkup::setMultiple().

Proposed resolution

Mark as @internal to translate(), the batch API and the form cache

Remaining tasks

Decide on internal notice & patch.

User interface changes

N/A

API changes

N/A

Beta evaluation

Documentation is unfrozen.

Comments

stefan.r created an issue. See original summary.

cilefen’s picture

Issue tags: +Novice
star-szr’s picture

Issue tags: +SafeMarkup
ianthomas_uk’s picture

cilefen’s picture

Issue summary: View changes
Issue tags: +Documentation
luklambrechts’s picture

I will bey trying this today at core mentoring

cilefen’s picture

I suggest something like:

   * @internal Called by \Drupal\Core\Form\FormCache,
   *    \Drupal\Core\StringTranslation, and the Batch API.
   *    Should not be used in user code.
luklambrechts’s picture

patch which marks the Safemarkup:setMultiple() @internal

cilefen’s picture

Status: Active » Needs work

@luklambrechts Great job on your first patch!

  1. +++ b/core/lib/Drupal/Component/Utility/SafeMarkup.php
    @@ -29,6 +29,7 @@
      * @see twig_render_template()
      * @see sanitization
      * @see theme_render
    + * ¶
      */
    

    This is an unrelated change. Please remove it.

  2. +++ b/core/lib/Drupal/Component/Utility/SafeMarkup.php
    @@ -108,6 +109,9 @@ public static function isSafe($string, $strategy = 'html') {
    +   * ¶
    +   * @internal should only be called by translate(), the batch api and the form cache
    +   * ¶
    

    There are spaces at the end of the lines above and below that must be removed.

    One line comments must start with a capital letter, so "Should", not "should", and they must end with a period. Also, they must not exceed 80 characters. Refer to https://www.drupal.org/coding-standards/docs on that.

Finally, and this is my opinion, I think we need something more specific like I mentioned in #7. Our only example of that is in \Drupal\Core\TypedData\Validation\ExecutionContext:

   *
   * @internal Called by \Drupal\Core\TypedData\Validation\ExecutionContextFactory.
   *    Should not be used in user code.
   */

Be sure to mark the issue status "Needs review" when you post the next patch.

sdstyles’s picture

Status: Needs work » Needs review
StatusFileSize
new634 bytes
new767 bytes
stefan.r’s picture

Status: Needs review » Needs work

Let's put in the internal notice from #7?

sdstyles’s picture

Status: Needs work » Needs review
StatusFileSize
new741 bytes
new621 bytes

Changed.

stefan.r’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 12: 2557893-12.patch, failed testing.

stefan.r’s picture

Status: Needs work » Reviewed & tested by the community

Setting back to RTBC assuming this was an unrelated test fail:

PHPUnit.Drupal\Tests\Component\DrupalComponentTest
✗
testNoCoreInComponent

fail: [Other] Line 23 of core/tests/Drupal/Tests/Component/DrupalComponentTest.php:
Failed asserting that an array is empty.

stefan.r queued 12: 2557893-12.patch for re-testing.

cilefen’s picture

Status: Reviewed & tested by the community » Needs work

Actually "Should not be used in user code." is not firm enough. It should not be used by anything except the listed things.

stefan.r’s picture

so, s/Should not be used in user code/Should not be used anywhere else/?

The last submitted patch, 12: 2557893-12.patch, failed testing.

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new753 bytes

Yes, and even though the example did not use complete sentences, we should.

Status: Needs review » Needs work

The last submitted patch, 20: mark-2557893-20.patch, failed testing.

Status: Needs work » Needs review
ianthomas_uk’s picture

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

Tweaked text looks good, patch should pass, it's just a docs change, so back to RTBC.

Added the original comment that prompted this issue.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 20: mark-2557893-20.patch, failed testing.

Status: Needs work » Needs review

cilefen queued 20: mark-2557893-20.patch for re-testing.

ianthomas_uk’s picture

StatusFileSize
new713 bytes

Hmm, a bit of an ideological failure that. The test asserts that the string "Drupal\Core" does not appear anywhere in the Component directory. Technically Components should have no knowledge of Core, so shouldn't be documenting where Core is using the method, but I think it sends a good message for there to be an explicit list of files that are allowed to call the function.

This just removes the qualification from the class names, as a hack to get around the test.

cilefen’s picture

Oh, I didn't even look at the test failure! I thought it was one of those random things. I'm glad somebody checks.

cilefen’s picture

StatusFileSize
new712 bytes

The line can wrap tighter.

The last submitted patch, 20: mark-2557893-20.patch, failed testing.

The last submitted patch, 26: mark-2557893-25.patch, failed testing.

stefan.r’s picture

Status: Needs review » Reviewed & tested by the community

Back to RTBC

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 749466c and pushed to 8.0.x. Thanks!

  • alexpott committed 749466c on 8.0.x
    Issue #2557893 by sdstyles, cilefen, ianthomas_uk, luklambrechts, stefan...

Status: Fixed » Closed (fixed)

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