Context error during installation

Created on 9 January 2025, 4 months ago

Problem/Motivation

After commenting out some core code to not be blocked by #3497683-6: [2.0.0-rc2] Field formatter does not check empty field , I have another fatal error when reinstalling.

See attached file.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇫🇷France Grimreaper France 🇫🇷

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

Comments & Activities

  • Issue created by @Grimreaper
  • 🇫🇷France Grimreaper France 🇫🇷
  • 🇫🇷France Grimreaper France 🇫🇷

    After commenting out in Context.php:

    //      elseif ($definition->isRequired()) {
    //        $type = $definition->getDataType();
    //        debug_print_backtrace();
    //
    //        throw new ContextException("The '$type' context is required and not present.");
    //      }
    

    Now it is a new fatal in attachment...

  • 🇩🇪Germany Christian.wiedemann

    Hi @grimreaper, I can't reproduce this bug. I tried to install sobki_profile_dsfr but was not sucessful.
    Can you give me a hint to install it.

      Problem 1
        - Root composer.json requires drupal/sobki_profile_dsfr ^10@alpha -> satisfiable by drupal/sobki_profile_dsfr[10.0.0-alpha1, 10.0.0-alpha2].
        - drupal/sobki_profile_dsfr 10.0.0-alpha1 requires npm-asset/gouvfr--dsfr 1.10.2 -> could not be found in any version, there may be a typo in the package name.
        - drupal/sobki_profile_dsfr 10.0.0-alpha2 requires npm-asset/gouvfr--dsfr 1.11.2 -> could not be found in any version, there may be a typo in the package name.
    
    
  • 🇫🇷France Grimreaper France 🇫🇷

    It is on the sobki_profile_bootstrap that there is a problem.

    And more precisely on the MR on [10.1.x] Upgrade to UIP2 Active .

  • 🇫🇷France Grimreaper France 🇫🇷
  • 🇫🇷France Grimreaper France 🇫🇷

    Hello,

    I made some dichotomy to isolate the problematic configuration. by deleting all core.entity_view_display.* config and then reputting it one by one until failure during installation.

    So when I list problematic config, it is when one of this config is present I have the bug.

    With the following config:

    • config/install/core.entity_view_display.block_content.accordion.default.yml
    • config/install/core.entity_view_display.block_content.carousel.default.yml
    • config/install/core.entity_view_display.block_content.list_group.default.yml
    • config/install/core.entity_view_display.block_content.news_carousel.default.yml
    • config/install/core.entity_view_display.block_content.progress_bar.default.yml
    • config/install/core.entity_view_display.block_content.reference.default.yml
    • config/install/core.entity_view_display.block_content.references.default.yml
    • config/install/core.entity_view_display.block_content.references_media.default.yml
    • config/install/core.entity_view_display.media.document.default.yml
    • config/install/core.entity_view_display.media.link.default.yml

    Failure after install_import_translations during install_configure_form:

    [error] InvalidArgumentException: Field user_picture is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 616 of /project/app/core/lib/Drupal/Core/Entity/ContentEntityBase.php).

    With the following config:

    • config/install/core.entity_view_display.block_content.blockquote.left.yml

    Failure after install_profile_themes during install_install_profile:

    The 'entity:block_content' context is required and not present.

    With the following config:

    • config/install/core.entity_view_display.node.blog_post.teaser.yml
    • config/install/core.entity_view_display.node.job_offer.teaser.yml
    • config/install/core.entity_view_display.node.page.teaser.yml
    • config/install/core.entity_view_display.node.product.teaser.yml

    Failure after install_profile_themes during install_install_profile:

    [error]  TypeError: Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source\FieldFormatterSource::createInstanceFormatter(): Argument #2 ($field_definition) must be of type Drupal\Core\Field\FieldDefinitionInterface, null given, called in /project/app/modules/contrib/ui_patterns/modules/ui_patterns_field_formatters/src/Plugin/UiPatterns/Source/FieldFormatterSource.php on line 450 in Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source\FieldFormatterSource->createInstanceFormatter() (line 328 of /project/app/modules/contrib/ui_patterns/modules/ui_patterns_field_formatters/src/Plugin/UiPatterns/Source/FieldFormatterSource.php) #0 /project/app/modules/contrib/ui_patterns/modules/ui_patterns_field_formatters/src/Plugin/UiPatterns/Source/FieldFormatterSource.php(450): Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source\FieldFormatterSource->createInstanceFormatter('text_default', NULL)
    #1 /project/app/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php(71): Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source\FieldFormatterSource->calculateDependencies()
    #2 /project/app/modules/contrib/ui_patterns/src/Plugin/UiPatterns/Source/DerivableContextSourceBase.php(472): Drupal\ui_patterns\SourcePluginBase->getPluginDependencies(Object(Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source\FieldFormatterSource))
    #3 /project/app/modules/contrib/ui_patterns/src/Element/ComponentElementBuilder.php(278): Drupal\ui_patterns\Plugin\UiPatterns\Source\DerivableContextSourceBase->calculateDependencies()
    #4 /project/app/modules/contrib/ui_patterns/src/Element/ComponentElementBuilder.php(224): Drupal\ui_patterns\Element\ComponentElementBuilder->calculateComponentDependenciesSlots(Object(Drupal\Core\Plugin\Component), Array, Array)
    #5 /project/app/modules/contrib/ui_patterns/src/Form/ComponentFormBuilderTrait.php(234): Drupal\ui_patterns\Element\ComponentElementBuilder->calculateComponentDependencies('ui_suite_bootst...', Array, Array)
    #6 /project/app/modules/contrib/ui_patterns/modules/ui_patterns_blocks/src/Plugin/Block/ComponentBlock.php(91): Drupal\ui_patterns_blocks\Plugin\Block\ComponentBlock->calculateComponentDependencies('ui_suite_bootst...', Array)
    #7 /project/app/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php(71): Drupal\ui_patterns_blocks\Plugin\Block\ComponentBlock->calculateDependencies()
    #8 /project/app/core/lib/Drupal/Core/Plugin/PluginDependencyTrait.php(89): Drupal\Core\Config\Entity\ConfigEntityBase->getPluginDependencies(Object(Drupal\ui_patterns_blocks\Plugin\Block\EntityComponentBlock))
    #9 /project/app/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php(380): Drupal\Core\Config\Entity\ConfigEntityBase->calculatePluginDependencies(Object(Drupal\ui_patterns_blocks\Plugin\Block\EntityComponentBlock))
    #10 /project/app/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(328): Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->calculateDependencies()
    #11 /project/app/core/lib/Drupal/Core/Entity/EntityDisplayBase.php(272): Drupal\Core\Config\Entity\ConfigEntityBase->preSave(Object(Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage))
    #12 /project/app/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php(140): Drupal\Core\Entity\EntityDisplayBase->preSave(Object(Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage))
    #13 /project/app/core/lib/Drupal/Core/Entity/EntityStorageBase.php(528): Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->preSave(Object(Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplayStorage))
    #14 /project/app/core/lib/Drupal/Core/Entity/EntityStorageBase.php(483): Drupal\Core\Entity\EntityStorageBase->doPreSave(Object(Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay))
    #15 /project/app/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(257): Drupal\Core\Entity\EntityStorageBase->save(Object(Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay))
    #16 /project/app/core/lib/Drupal/Core/Entity/EntityBase.php(354): Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object(Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay))
    #17 /project/app/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(617): Drupal\Core\Entity\EntityBase->save()
    #18 /project/app/core/modules/layout_builder/src/Entity/LayoutBuilderEntityViewDisplay.php(166): Drupal\Core\Config\Entity\ConfigEntityBase->save()
    #19 /project/app/core/lib/Drupal/Core/Config/ConfigInstaller.php(389): Drupal\layout_builder\Entity\LayoutBuilderEntityViewDisplay->save()
    #20 /project/app/core/lib/Drupal/Core/Config/ConfigInstaller.php(149): Drupal\Core\Config\ConfigInstaller->createConfiguration('', Array)
    #21 /project/app/core/lib/Drupal/Core/ProxyClass/Config/ConfigInstaller.php(75): Drupal\Core\Config\ConfigInstaller->installDefaultConfig('module', 'sobki_profile_b...')
    #22 /project/app/core/lib/Drupal/Core/Extension/ModuleInstaller.php(326): Drupal\Core\ProxyClass\Config\ConfigInstaller->installDefaultConfig('module', 'sobki_profile_b...')
    #23 /project/app/core/lib/Drupal/Core/ProxyClass/Extension/ModuleInstaller.php(83): Drupal\Core\Extension\ModuleInstaller->install(Array, false)
    #24 /project/app/core/includes/install.core.inc(1677): Drupal\Core\ProxyClass\Extension\ModuleInstaller->install(Array, false)
    #25 /project/app/core/includes/install.core.inc(695): install_install_profile(Array)
    #26 /project/app/core/includes/install.core.inc(572): install_run_task(Array, Array)
    #27 /project/app/core/includes/install.core.inc(121): install_run_tasks(Array, Array)
    #28 /project/vendor/drush/drush/includes/drush.inc(69): install_drupal(Object(Composer\Autoload\ClassLoader), Array, Array)
    #29 /project/vendor/drush/drush/includes/drush.inc(53): drush_call_user_func_array('install_drupal', Array)
    #30 /project/vendor/drush/drush/src/Commands/core/SiteInstallCommands.php(170): drush_op('install_drupal', Object(Composer\Autoload\ClassLoader), Array, Array)
    #31 [internal function]: Drush\Commands\core\SiteInstallCommands->install('sobki_profile_b...', Array)
    #32 /project/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)
    #33 /project/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))
    #34 /project/vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
    #35 /project/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(387): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))
    #36 /project/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #37 /project/vendor/symfony/console/Application.php(1096): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #38 /project/vendor/symfony/console/Application.php(324): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #39 /project/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #40 /project/vendor/drush/drush/src/Runtime/Runtime.php(110): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
    #41 /project/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))
    #42 /project/vendor/drush/drush/drush.php(140): Drush\Runtime\Runtime->run(Array)
    #43 /project/vendor/bin/drush.php(119): include('/project/vendor...')
    #44 {main}.

    Without all those problematic config, during installation even if installation is successful I have the following warnings:

    ...
    [notice] Performed install task: install_profile_themes
    [warning] The "field_block:block_content:text_media:body" block plugin was not found
    [warning] The "field_block:block_content:text_media:field_media" block plugin was not found
    [warning] The "field_block:block_content:text_media:body" block plugin was not found
    [warning] The "field_block:block_content:text_media:field_media" block plugin was not found
    [warning] The "field_block:block_content:key_number:field_number" block plugin was not found
    [warning] The "field_block:block_content:key_number:field_suffix" block plugin was not found
    [warning] The "field_block:block_content:key_number:body" block plugin was not found
    [warning] The "field_block:block_content:key_number:field_number" block plugin was not found
    [warning] The "field_block:block_content:key_number:field_suffix" block plugin was not found
    [warning] The "field_block:block_content:key_number:body" block plugin was not found
    [warning] The "field_block:block_content:featuring:field_media" block plugin was not found
    [warning] The "field_block:block_content:featuring:field_heading" block plugin was not found
    [warning] The "field_block:block_content:featuring:body" block plugin was not found
    [warning] The "field_block:block_content:featuring:field_cta" block plugin was not found
    [warning] The "field_block:block_content:featuring:field_media" block plugin was not found
    [warning] The "field_block:block_content:featuring:field_heading" block plugin was not found
    [warning] The "field_block:block_content:featuring:body" block plugin was not found
    [warning] The "field_block:block_content:featuring:field_cta" block plugin was not found
    [warning] The "block_content:d7b0e3ca-31a5-4697-84bc-95600bb2067a" block plugin was not found
    [warning] The "field_block:taxonomy_term:tags:name" block plugin was not found
    [warning] The "field_block:taxonomy_term:tags:name" block plugin was not found
    [warning] The "field_block:paragraph:progress_bar:field_title" block plugin was not found
    [warning] The "field_block:paragraph:progress_bar:field_title" block plugin was not found
    [warning] The "field_block:paragraph:list_group_item:field_content" block plugin was not found
    [warning] The "field_block:paragraph:list_group_item:field_content" block plugin was not found
    [warning] The "field_block:paragraph:carousel_item:field_media" block plugin was not found
    [warning] The "field_block:paragraph:carousel_item:field_caption" block plugin was not found
    [warning] The "field_block:paragraph:carousel_item:field_media" block plugin was not found
    [warning] The "field_block:paragraph:carousel_item:field_caption" block plugin was not found
    [warning] The "field_block:paragraph:accordion_item:field_title" block plugin was not found
    [warning] The "field_block:paragraph:accordion_item:field_text" block plugin was not found
    [warning] The "field_block:paragraph:accordion_item:field_title" block plugin was not found
    [warning] The "field_block:paragraph:accordion_item:field_text" block plugin was not found
    [warning] The "field_block:block_content:blockquote:field_media" block plugin was not found
    [warning] The "field_block:block_content:blockquote:field_quote" block plugin was not found
    [warning] The "field_block:block_content:blockquote:field_footer" block plugin was not found
    [warning] The "field_block:block_content:blockquote:field_media" block plugin was not found
    [warning] The "field_block:block_content:blockquote:field_quote" block plugin was not found
    [warning] The "field_block:block_content:blockquote:field_footer" block plugin was not found
    [warning] The "field_block:block_content:alert:field_heading" block plugin was not found
    [warning] The "field_block:block_content:alert:field_message" block plugin was not found
    [warning] The "field_block:block_content:alert:field_heading" block plugin was not found
    [warning] The "field_block:block_content:alert:field_message" block plugin was not found
    [warning] The "field_block:node:product:title" block plugin was not found
    [warning] The "field_block:node:product:body" block plugin was not found
    [warning] The "field_block:node:product:field_media" block plugin was not found
    [warning] The "field_block:node:product:field_featurings" block plugin was not found
    [warning] The "field_block:node:product:field_related_content" block plugin was not found
    [warning] The "field_block:node:product:title" block plugin was not found
    [warning] The "field_block:node:product:body" block plugin was not found
    [warning] The "field_block:node:product:field_media" block plugin was not found
    [warning] The "field_block:node:product:field_featurings" block plugin was not found
    [warning] The "field_block:node:product:field_related_content" block plugin was not found
    [warning] The "field_block:node:news:field_teaser_media" block plugin was not found
    [warning] The "field_block:node:news:title" block plugin was not found
    [warning] The "field_block:node:news:field_teaser_text" block plugin was not found
    [warning] The "field_block:node:news:created" block plugin was not found
    [warning] The "field_block:node:news:field_teaser_media" block plugin was not found
    [warning] The "field_block:node:news:title" block plugin was not found
    [warning] The "field_block:node:news:field_teaser_text" block plugin was not found
    [warning] The "field_block:node:news:created" block plugin was not found
    [warning] The "field_block:node:job_offer:field_teaser_media" block plugin was not found
    [warning] The "field_block:node:job_offer:title" block plugin was not found
    [warning] The "field_block:node:job_offer:field_teaser_text" block plugin was not found
    [warning] The "field_block:node:job_offer:created" block plugin was not found
    [warning] The "field_block:node:job_offer:field_teaser_media" block plugin was not found
    [warning] The "field_block:node:job_offer:title" block plugin was not found
    [warning] The "field_block:node:job_offer:field_teaser_text" block plugin was not found
    [warning] The "field_block:node:job_offer:created" block plugin was not found
    [warning] The "field_block:node:blog_post:field_teaser_media" block plugin was not found
    [warning] The "field_block:node:blog_post:title" block plugin was not found
    [warning] The "field_block:node:blog_post:field_teaser_text" block plugin was not found
    [warning] The "field_block:node:blog_post:field_tags" block plugin was not found
    [warning] The "field_block:node:blog_post:created" block plugin was not found
    [warning] The "field_block:node:blog_post:field_teaser_media" block plugin was not found
    [warning] The "field_block:node:blog_post:title" block plugin was not found
    [warning] The "field_block:node:blog_post:field_teaser_text" block plugin was not found
    [warning] The "field_block:node:blog_post:field_tags" block plugin was not found
    [warning] The "field_block:node:blog_post:created" block plugin was not found
    [notice] Performed install task: install_install_profile
    ...
    

    Also before encountering config bugs, I had to edit app/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php:

      public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
        return [];
    

    Otherwise there was a fatal with the array_rand in this method.

    I hope that all those elements will help the debugging.

    Maybe we can figure out common points with those configs.

  • 🇫🇷France pdureau Paris

    Fixed in 🐛 PHP warnings with Metatag module Active according to https://www.drupal.org/project/ui_patterns/issues/3498456#comment-15951405 🐛 PHP warnings with Metatag module Active

  • 🇫🇷France Grimreaper France 🇫🇷

    With current MR, I no more have the following errors:
    - The 'entity:block_content' context is required and not present.
    - [error] TypeError: Drupal\ui_patterns_field_formatters\Plugin\UiPatterns\Source\FieldFormatterSource::createInstanceFormatter(): Argument #2 ($field_definition) must be of type Drupal\Core\Field\FieldDefinitionInterface, null given,

    Without editing app/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php, I no more have the associated fatal.

    Warnings about block plugins not found remains but not a blocker and already there with UIP1 (not exactly the same but you guessed the point).

    So remains:

    [error]  InvalidArgumentException: Field user_picture is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 616 of /project/app/core/lib/Drupal/Core/Entity/ContentEntityBase.php).
    

    I will check my translatability configs.

    Thanks! Huge step forward!

  • 🇫🇷France Grimreaper France 🇫🇷

    Celebrated too early.

    I still got:

    [error]  ValueError: array_rand(): Argument #1 ($array) cannot be empty in array_rand() (line 358 of /project/app/core/modules/image/src/Plugin/Field/FieldType/ImageItem.php)
    
  • 🇩🇪Germany Christian.wiedemann

    I checked that also, but I thought it is not UI Patterns related.
    But "Maybe" this happens because we call createInstance during calculateDependencies and the field is not setup correctly during that. Will check it.

  • 🇫🇷France Grimreaper France 🇫🇷

    For Field user_picture is unknown, Currently I am removing the user_picture field from Sobki. I think this problem is core because I saw similar issues on other projects but no issue on core.

    Currently MR is too big.

    So when merged in another issue I will re-add user_picture and demonstrate it is problematic.

    But array_rand error remains.

  • 🇫🇷France Grimreaper France 🇫🇷

    I fixed errors with default content that I changed manually.

    Now only remains array_rand

  • First commit to issue fork.
  • 🇩🇪Germany Christian.wiedemann

    We found the problem behind the ImageRand bug. The Image SVG Module generates an SVG sample value while saving a layout. This sample generated entity leads to this bug. See issue https://www.drupal.org/project/svg_image/issues/3170319 🐛 SVG-only image fields cause error with Layout Builder Active

    I tested the workaround mentioned in the issue:

    I add to

    field.field.media.image_svg.field_media_image.yml 
    
    file_extensions: 'png svg'
    
  • 🇫🇷France Grimreaper France 🇫🇷

    Thanks! I confirm the workaround is working.

    Updating Sobki MR.

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

Production build 0.71.5 2024