Problem/Motivation

The module works great to define new namespaces. We had a similar situation with the custom implementation of the storybook. It was done in a custom module in a similar situation to the https://medium.com/@askibinski/integrating-storybook-with-drupal-ddabfc6...

However, this custom module also contained different libraries in its sub-directories. I have a limited understanding of the internals of storybook, but there are a lot of libraries defined in them. It would be good if there was a way to autoload them as they seem to be dynamic and pretty tough to be included in the module's *.libraries.yml

Proposed resolution

Provide a new option to automatically detect the libraries. In the following way:

components:
  namespaces:
    myLib:
      - myLibFiles
  autodetect_libraries:
    - myLib

Remaining tasks

Patch and review.

User interface changes

None.

API changes

New option added to the yaml file.

Issue fork components-3348158

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

AjitS created an issue. See original summary.

ajits’s picture

Status: Active » Needs review
StatusFileSize
new3.55 KB

Added a patch with the functionality.

ajits’s picture

StatusFileSize
new3.6 KB
new1.05 KB

Handled an error thrown

Error: Call to a member function getPath() on null in components_library_info_alter() (line 18 of /var/www/html/docroot/modules/contrib/components/components.module).

stefanos.petrakis’s picture

Status: Needs review » Needs work

It looks good.
Maybe we can be more defensive regarding the $extension_path variable?
As in, if still an empty string, do not enter the main loop.

if (!empty($extension_path) && isset($info['components']) && isset($info['components']['autodetect_libraries']) && isset($info['components']['namespaces'])) {
alecsmrekar’s picture

StatusFileSize
new3.83 KB
new2.28 KB

Updating the patch to read from the module/theme list service, instead of reading from cache directly. I also incorporated feedback from Stefanos.

alecsmrekar’s picture

Status: Needs work » Needs review
robloach’s picture

Thanks for all the work here, everyone. How does this approach differ from https://www.drupal.org/project/components/issues/2707849 ?

mikeryan’s picture

StatusFileSize
new4.19 KB

Rerolled patch for the new README.

ajits’s picture

Created a PR as we're moving away from d.o issues. See - #3295357: Migrate drupal.org issues to GitLab issues

dpi’s picture

Status: Needs review » Closed (duplicate)
Related issues: +#2707849: Allow components to define asset libraries

Since theres no direct answer to #7, closing this so there is no wasted effort in this issue, compared to the long-lived/discussed/followed issue at #2707849: Allow components to define asset libraries.

Please open if differences can be justified.