PHPackages                             arsthanea/page-actions-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. arsthanea/page-actions-bundle

ActiveLibrary

arsthanea/page-actions-bundle
=============================

1.1.2(5y ago)010.2k1MITPHP

Since Apr 26Pushed 5y ago3 watchersCompare

[ Source](https://github.com/syzygypl/page-actions-bundle)[ Packagist](https://packagist.org/packages/arsthanea/page-actions-bundle)[ RSS](/packages/arsthanea-page-actions-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Page subactions
===============

[](#page-subactions)

This bundle enables to mount controllers (or any other routing for that matter) under any [Kunstmaan CMS](https://bundles.kunstmaan.be) page. In effect, given a `/foo/bar` page and a `/thank-you` route, you can access `/foo/bar/thank-you` and have `$page` and `$nodeTranslation` of `/foo/bar` provided.

Installation
------------

[](#installation)

1. `composer require arsthanea/page-actions-bundle`
2. Add `PageActionsBundle` to your Kernel
3. Update your db schema / create migration
4. Import the `page_actions` routing in your main `routing.yml`:

```
# app/config/routing.yml

_page_actions:
    type: page_actions
    resource: .

```

Usage
-----

[](#usage)

### Configure available resources

[](#configure-available-resources)

First, you need to configure available routes / controllers. Since this routing is highly dynamic, not any route will match any page, so we need to have some hints. List your resources in configuration:

```
# app/config/config.yml or such

page_actions:
    resources:
        landing_page:
            resource: @LandingPageBundle/Controller/LandingPageActionsController.php
            type: annotation
```

This is either an `annotation` and a controller, or a `yaml` / `xml` etc with routes, same as you’d use in `routing.yml`. You cannot however use other configuration options such as `prefix`, `defaults`, etc. The key name is important, it will be used later.

### Create controller

[](#create-controller)

Let’s now define the controller. You can automatically use `$page` and `$nodeTranslation` in your actions. Besides that, it’s just a standard controller. For example:

```
class LandingPageActionsController extends Controller {

    /**
     * @Route(name="landing_page_submit", path="submit", methods = {"POST"})
     *
     * @param Request         $request
     * @param NodeTranslation $nodeTranslation
     *
     * @return RedirectResponse
     */
    public function submitAction(Request $request, NodeTranslation $nodeTranslation) {
       //
       // handle some form data
       //
       return $this->redirectToRoute('landing_page_thank_you', ["url" => $nodeTranslation->getUrl()]);
    }

    /**
     * @Route(name="landing_page_thank_you", path="thank-you")
     *
     * @param HasNodeInterface $page
     *
     * @return Response
     */
    public function submitAction(HasNodeInterface $page) {
       //
       // notice that $page is referencing to current page
       //
       return $this->render('@LandingPageBundle/Pages/ThankYou.html.twig, ["page" => $page]);
    }

}
```

### Configure the page

[](#configure-the-page)

The last piece is configuring the page entity to handle specified actions. Do this by implementing the `PageActionsInterface`:

```
# Entity\LandingPage.php

class LandingPage extends AbstractEntity implements PageActionsInterface {

// …
    public function getPageActions() {
        return ['landing_page'];
    }
// …

}
```

Notice, that the values returned by this method need to match the keys defined in configuration earlier.

### Save the page

[](#save-the-page)

Nothing works yet. Now you need to save the page, for the custom page routes to be created.

### Use the actions

[](#use-the-actions)

For example, in your default view:

```
