0
votes

Using Symfony2, Twig, and Prismic:

I have looked at the following resources, but I am still unclear how to extend certain methods in Symfony2

http://symfony.com/doc/current/cookbook/bundles/inheritance.html http://symfony.com/doc/current/cookbook/bundles/override.html

There is a prismic folder in my vendors directory, which includes the following dirs:

vendors/prismic
     php-sdk
     prismic-bundle

For my application, I duplicated the prismic-bundle directory and moved it here:

src/VAP/Bundle/PrismicBundle

then changed the AppKernal.php to include this bundle:

// new Prismic\Bundle\PrismicBundle\PrismicBundle() ..removed the connection to the vendor dir

new VAP\Bundle\PrismicBundle\PrismicBundle() ..use this custom directory

which works fine.

However, there are methods in the php-sdk directory that are called from my custom PrismicBundle, which I need to extend or override. For instance, a twig template may call

var.getStructuredText('blog.body').asHtml(ctx.linkResolver)

which is located here:

vendor/prismic/php-sdk/src/Prismic/Fragment/StructuredText.php

How/where would I create a file that would extend/overwrite the above file?

I am also confused if php-sdk is a bundle, or is it part of the original PrismicBundle from the vendor directory?

1

1 Answers

1
votes

First, you say that you duplicated the PrismicBundle in your src folder, why did you not use the bundle inheritence process ?

public function getParent()
{
    return 'PrismicBundle';
}

For you question, you have to change the behavior of the prismic php-sdk, possible reasons:

  • 1) This sdk is not well built
  • 2) You do not use it correctly
  • 3) You want a very custom behavior not supported by prismic

IMO, possible solutions are:

  • 1) Fork the sdk to add compatibility to your need
  • 2) Think about a different way to reach your need
  • 3) Create a new service in your custom PrismicBundle that call prismic api as you want.

Faor your final question, afaik prismic/php-sdk is the api implementation in raw php, and prismic/prismic-bundle is a bridge between this raw php SDK and Symfony, implementing services and all comodities provided by Symfony.