ContentfulBundle icon indicating copy to clipboard operation
ContentfulBundle copied to clipboard

Unable to add the ContentfulBundle to my project

Open stefanzopfi opened this issue 7 years ago • 2 comments

Command: composer require contentful/contentful-bundle PHP version: 7.2.14 Symfony version: 4.2.2

I get this error in my console:

Using version ^4.0 for contentful/contentful-bundle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.2.*"
Package operations: 14 installs, 0 updates, 0 removals
  - Installing jean85/pretty-package-versions (1.2) Loading from cache
  - Installing psr/http-message (1.0.1) Loading from cache
  - Installing ralouphie/getallheaders (2.0.5) Loading from cache
  - Installing guzzlehttp/psr7 (1.5.2) Loading from cache
  - Installing guzzlehttp/promises (v1.3.1) Loading from cache
  - Installing guzzlehttp/guzzle (6.3.3) Loading from cache
  - Installing contentful/core (2.2.5) Loading from cache
  - Installing contentful/rich-text (1.2.0) Loading from cache
  - Installing cache/tag-interop (1.0.0) Loading from cache
  - Installing cache/adapter-common (1.1.0) Loading from cache
  - Installing cache/hierarchical-cache (1.0.0) Loading from cache
  - Installing cache/void-adapter (1.0.0) Loading from cache
  - Installing contentful/contentful (4.1.1) Loading from cache
  - Installing contentful/contentful-bundle (4.0.0) Loading from cache
Writing lock file
Generating autoload files
ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
Symfony operations: 1 recipe (b3f842960e25e3a6ea163ad10009dcfa)
  - Configuring contentful/contentful-bundle (>=3.0): From github.com/symfony/recipes-contrib:master
Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 255
!!
!!  Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Argument 2 passed to Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension::Contentful\ContentfulBundle\DependencyInjection\{closure}() must be of the type array, string given in C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php:138
!!  Stack trace:
!!  #0 [internal function]: Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension->Contentful\ContentfulBundle\DependencyInjection\{closure}(0, 'env_4f79913c98a...')
!!  #1 C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php(140): array_reduce(Array, Object(Closure), 0)
!!  #2 C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php(46): Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension->registerDeliveryClient(Object(Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationContainerBu in C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php on line 138
!!  PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Argument 2 passed to Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension::Contentful\ContentfulBundle\DependencyInjection\{closure}() must be of the type array, string given in C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php:138
!!  Stack trace:
!!  #0 [internal function]: Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension->Contentful\ContentfulBundle\DependencyInjection\{closure}(0, 'env_4f79913c98a...')
!!  #1 C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php(140): array_reduce(Array, Object(Closure), 0)
!!  #2 C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php(46): Contentful\ContentfulBundle\DependencyInjection\ContentfulExtension->registerDeliveryClient(Object(Symfony\Component\DependencyInjection\Compiler\MergeExtensionConfigurationContainerBu in C:\xampp\htdocs\contentful\vendor\contentful\contentful-bundle\src\DependencyInjection\ContentfulExtension.php on line 138
!!

Installation failed, reverting ./composer.json to its original content.

What can I do to get it working?

stefanzopfi avatar Feb 01 '19 10:02 stefanzopfi

From what I get trying to install the Contentful bundle, seems to be a config problem. If I change config/packages/contentful.yaml to something like:

# For the complete configuration, please visit
# https://www.contentful.com/developers/docs/php/tutorials/getting-started-with-contentful-and-symfony/
contentful:
    delivery:
        default:
            space: "%env(CONTENTFUL_SPACE_ID)%"
            token: "%env(CONTENTFUL_ACCESS_TOKEN)%"

Then the error should not happen again. So if you want to get content while someone fixes the bundle:

Add parameters to services.yaml

parameters:
    locale: 'en'
    contentful.space: "%env(CONTENTFUL_SPACE_ID)%"
    contentful.token: "%env(CONTENTFUL_ACCESS_TOKEN)%"

and then on your action:

/**
     * @Route("/content", name="content")
     *
     */
    public function fromContent()
    {
        /** @var Client $client */
        $client = new Client(
            $this->getParameter('contentful.token'),
            $this->getParameter('contentful.space')
        );

        try {
            $entry = $client->getEntry('<ENTRY_ID>');
        } catch (NotFoundException $contentfulException) {
            throw new NotFoundHttpException();
        }

        return new JsonResponse($entry);
    }

The weird part is that for now the Contentful Client seems not being injected to the container...

Weird things list:

  • [ ] Contentful config validation

  • [ ] Contentful Client service injection

  • [ ] Contentful bundle seems to only inject contentful.delivery.profiler_controller as a service

Sorry, not a big help but just a quick debug on this.

rudirocha avatar Feb 03 '19 21:02 rudirocha

Added my space id and access token to my environment variables and got it working now

stefanzopfi avatar Feb 05 '19 12:02 stefanzopfi