The Starterkit theme should include a default JavaScript file that includes scaffolding for Drupal behaviors. We can also include examples the once() library.

We can also include some in-code documentation of what Drupal behaviors are, why they are necessary, and how to use them along with the once() library.

Issue fork drupal-3209192

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mherchel created an issue. See original summary.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

matthieuscarset made their first commit to this issue’s fork.

matthieuscarset’s picture

Status: Active » Needs review

Just added a new library to starterkit_theme to demonstrate how to implement a Drupal JS behavior:

starterkit_theme/reading-time

It shows how to use drupalSettings and once() within an attach() and detach(). I tried to keep the whole code below ~100 lines - comments included.

File changes:

themes/star‎terkit_theme‎:
|_ js/
|___ reading‎-time.js‎
|_ starterkit_them‎e.libraries.yml‎ 
|_ starterkit_‎theme.theme‎

NB: I had to update the theme generator PHP script to rename the source theme name in the *.theme file's content and in JavaScript files too. .

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new4.23 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

matthieuscarset’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Moving to NW for the open threads.

+1 for pointing to docs for once()

matthieuscarset’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Can the changes to core/lib/Drupal/Core/Command/GenerateTheme.php be reverted?

matthieuscarset’s picture

Status: Needs work » Needs review
needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new2.11 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

matthieuscarset’s picture

Status: Needs work » Needs review

Thank you mister robot.

Added the missing new line at the end of the file.

Needs review.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Thanks! Believe this is ready.

kostyashupenko made their first commit to this issue’s fork.

kostyashupenko’s picture

Rebased
I see issues with eslint on yarn lint:core-js

/var/www/html/drupal/core/themes/starterkit_theme/js/reading-time.js
   6:2  warning  Unexpected unnamed function   func-names
  30:6  warning  Use @return instead           valid-jsdoc
  65:9  warning  Unexpected console statement  no-console

Second warning is fixed, what to do with the rest warnings?

lauriii’s picture

Status: Reviewed & tested by the community » Needs review

Posted comment in the MR

smustgrave’s picture

Status: Needs review » Needs work

@matthieuscarset I think that sounds like a great idea and a good example.

matthieuscarset’s picture

Oups! sorry, this is actually already what I did! 🤦‍♂️ I forgot to re-read myself.

@lauriii's question is still relevant.

Do we want to keep console.log() or should we use something more visual, such as alert() or Drupal.message ?

smustgrave’s picture

Think console.log and maybe Drupal.message would be good examples.

Console.log for debugging
Drupal.message for themers

matthieuscarset’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Reran tests and they still fail, so think failure is related to the change.

matthieuscarset’s picture

Status: Needs work » Needs review

Just rebased on top of 11.x and rerun the whole pipeline.

The failures are not related to changes on this issue.

Not sure how to handle this situation... but unless I'm wrong, the current issue is done and can be RTBC .

smustgrave’s picture

Rerunning again but I don’t see that HEAD is broken. So if this can’t pass all the tests can’t mark it RTBC

smustgrave’s picture

Status: Needs review » Needs work

Ran here again and locally and it fails. Somehow this change is being picked up.

matthieuscarset’s picture

Status: Needs work » Needs review
StatusFileSize
new67.75 KB

I need help to understand why an unrelated test is constantly failing in this MR

I merged latest code from 11.x and run the pipeline again but it is still failing at Drupal\FunctionalJavascriptTests\Core\JsMessageTest.

If I run the test locally, it passes without errors (see screenshot below).
Running the test locally does not fail

Any help much appreciated! TY

smustgrave’s picture

Status: Needs review » Needs work

Posted a comment on the MR, hopefully that helps some.

Gauravvvv made their first commit to this issue’s fork.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.