How to automate the import of content as config with a module install

Created on 12 July 2023, over 1 year ago
Updated 13 July 2023, over 1 year ago

Problem/Motivation

I see the content_as_config.[entity].yml are simple configuration object, so I cannot declare them a dependency of my custom module, right?
I tried manually adding

dependencies:
config:
- content_as_config
- my_module

and putting the yml in my module's config/optional but on install they are not imported, hence they don't show up at /admin/structure/content-as-config for import, let alone the content being automatically loaded into the site.

Furthermore, manually editing the config file that way breaks the content_as_config/[entity] page after a config import with error (in case of feed entities):

TypeError: Drupal\feeds_as_config\Form\FeedsImportForm::getLabel(): Return value must be of type string, null returned in Drupal\feeds_as_config\Form\FeedsImportForm->getLabel() (line 32 of /var/www/html/web/modules/contrib/content_as_config/modules/feeds_as_config/src/Form/FeedsImportExportTrait.php).

So, how would you automate the import of supported content while installing a custom module?
Thank you

💬 Support request
Status

Active

Version

1.0

Component

Miscellaneous

Created by

🇮🇹Italy kopeboy Milan

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

Comments & Activities

  • Issue created by @kopeboy
  • 🇮🇹Italy kopeboy Milan

    What I tried:

    1. install content_as_config and feeds_as_config
    2. create 1 feed
    3. export it with drush cacx feeds_feed
    4. put the content_as_config.feeds_feed.yml inside my_module/config/install
    5. re-install the site with drush site:install
    6. drush en my_module (content_as_config:feeds_as_config is a dependency)
    7. drush cex to prove content_as_config.feeds_feed.yml was in the active configuration: it was as the same file of my_module/config/install was exported
    8. drush caci feeds_feed to import the feed.. ERROR:
    9. tried going to /admin/structure/content-as-config/feeds-import and received white screen with 15 php logs
      1. Deprecated function: explode(): Passing null to parameter #2 ($string) of type string is deprecated in Drupal\Core\Extension\Dependency::createFromString() (line 132 of /var/www/html/web/core/lib/Drupal/Core/Extension/Dependency.php) debug (repeated 6 times)
      2. Deprecated function: str_contains(): Passing null to parameter #1 ($haystack) of type string is deprecated in Drupal\Core\Extension\Dependency::createFromString() (line 126 of /var/www/html/web/core/lib/Drupal/Core/Extension/Dependency.php) debug (repeated 6 times), with 1 error and 2 warnings in the middle..
      3. TypeError: Drupal\feeds_as_config\Form\FeedsImportForm::getLabel(): Return value must be of type string, null returned in Drupal\feeds_as_config\Form\FeedsImportForm->getLabel() (line 32 of /var/www/html/web/modules/contrib/content_as_config/modules/feeds_as_config/src/Form/FeedsImportExportTrait.php).
      4. Warning: Undefined array key "title" in Drupal\feeds_as_config\Form\FeedsImportForm->getLabel() (line 32 of /var/www/html/web/modules/contrib/content_as_config/modules/feeds_as_config/src/Form/FeedsImportExportTrait.php)
      5. Warning: Undefined array key "uuid" in Drupal\content_as_config\Form\ImportBase->buildForm() (line 60 of /var/www/html/web/modules/contrib/content_as_config/src/Form/ImportBase.php)

    Then I re-tried (after site reinstall) to FIRST import the single config using the module config_import_single with its command:
    drush cis modules/my/module/config/install/content_as_config.feeds_feed.yml and THEN drush caci feeds_feed and it finally worked.

    Was this the expected behaviour? Why?
    Thank you.

Production build 0.71.5 2024