Error when using components with the new components namespaces declaration

Created on 7 July 2023, over 1 year ago
Updated 18 August 2023, over 1 year ago

Problem/Motivation

The website encountered an unexpected error. Please try again later.
TypeError: is_dir(): Argument #1 ($filename) must be of type string, array given in is_dir() (line 129 of modules/contrib/graphql_twig/src/Template/Loader/Loader.php).

Steps to reproduce

PHP 8.0
Drupal 9.5.9
graphql_twig 1.0.0-beta17
components 2.4.0

Used namespace declaration in the theme.info.yml:

components:
  namespaces:
    storybook:
      - "../../../../storybook/components"
#component-libraries:
#  storybook:
#    paths:
#      - "../../../../storybook/components"

The old notation is commented out, but is deprecated and no longer supported in version 3. (see Upgrade Guide: 1.x to 2.x )

Proposed resolution

Add an is_string($componentsDirectory) validation in the if-statement on line 129 before the is_dir($componentsDirectory) validation

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇳🇱Netherlands Ronald van Belzen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @Ronald van Belzen
  • 🇳🇱Netherlands Ronald van Belzen

    The proposed solution.

  • 🇨🇭Switzerland megadesk3000

    I experience the same issue after upgrading drupal/components to version 3.0.0-beta3 and i can confirm that the patch fixes the issue.

    What i am not sure about is how the functionality implemented in \Drupal\graphql_twig\Template\Loader\Loader::findTemplate can work together with the new components definition syntax.

    If one is using components and defined some namespaces in his thems info file like:

    components:
      namespaces:
        src:
          - src
        base:
          - src/base
    

    So after this, listComponents() will never be called in the findTemplate function, since $info['components'] will always be an array.
    We are not using the "components" functionality from graphql_twig and i am not sure, what exactly it does.
    For our case it fixes the issue, but if one has defined "components" in graphql_twig context in his themes info.yml then it will not work togethter with the new syntax from components.

  • 🇳🇱Netherlands Ronald van Belzen

    I have not dug in very deep, but from what I can tell: it does not work together. The current bug just disrupts the process by causing an error. But I might be wrong.

Production build 0.71.5 2024