Code Monkey home page Code Monkey logo

pagebundle's Introduction

Artgris Page

Installation:

composer require artgris/page-bundle

php bin/console doctrine:schema:update --force 

Configuration:

in config/packages

configure KnpLabs/DoctrineBehaviors: https://github.com/KnpLabs/DoctrineBehaviors

  • Add locale parameter in services.yaml:
parameters:
    locale: 'en'
  • Add to AppKernel:
return [
    ...
    Knp\DoctrineBehaviors\DoctrineBehaviorsBundle::class => ['all' => true],
];
  • Add to DashboardController.php :
use Artgris\Bundle\PageBundle\Entity\ArtgrisPage;

public function configureMenuItems(): iterable
{
     ...
     yield MenuItem::linkToCrud('Page', 'fa fa-file-alt', ArtgrisPage::class);
}

add a2lix_translation_form.yaml

ex:

a2lix_translation_form:
    locale_provider: default
    locales: [fr, en]
    default_locale: fr

add artgris_page.yaml

not required, no minimal configuration

artgris_page:
    controllers: #Namespaces used to load the route selector
        - 'App\Controller\MainController::index'
        - 'App\Controller\Main\'
        - 'App\Controller\'
        - ... 
    types: # add your own types
        -   integer: 'Symfony\Component\Form\Extension\Core\Type\IntegerType'
        -   date: 'Symfony\Component\Form\Extension\Core\Type\DateType'
        -   time: 'Symfony\Component\Form\Extension\Core\Type\TimeType'
        -   custom: 'App\Form\CustomType'
        - ... 
    default_types: true #load default form types [1]
    hide_route_form: false #to hide the route selector (example of use: one page website)
    redirect_after_update: false #always redirect the user to the configuration page after new/edit action
    use_multiple_a2lix_form: false #to use multiple a2lix form

[1] Default form types list:

source: Artgris\Bundle\PageBundle\Service\TypeService

    'type.text' => ArtgrisTextType::class,  => not required TextType
    'type.textarea' => ArtgrisTextAreaType::class,  => not required TextAreaType with rows = 8 + renderType: \nl2br
    'type.section' => SectionType::class => h2 section, type hidden, to delimit "blocks"

Usage:

1 - Create a page and add blocks

2 - Edit the content of the blocks

3 - Retrieve a simple block by tag

{{ blok('title') }}

=> return "My website"

use the debugging bar to easily find all blocks by route. (click on block tag to copy/paste code)

Retrieve all blocks of the current page or not linked to a page

bloks()

ex:

{% for blok in bloks() %}
    {{ blok }} <br>
{% endfor %}

Retrieve all blocks by page tag

page('page-tag')

ex:

{% for blok in page('homepage') %}
    {{ blok }} <br>
{% endfor %}

Retrieve blocks with a regular expression

in an array

regex_array_blok('regex-expression')

ex:

{% for blok in regex_array_blok('^sidebar-*') %}
    {{ blok }} <br>
{% endfor %}

implode in a string

regex_blok('regex-expression')

ex:

{{ regex_blok('^sidebar-*') }}  

Tips:

custom block rendering

create a form type that implements PageFromInterface:

namespace App\Form;

use Artgris\Bundle\PageBundle\Form\Type\PageFromInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\OptionsResolver\OptionsResolver;

class CustomType extends AbstractType implements PageFromInterface
{

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'attr' => [
                'class' => 'custom',
            ],
            'required' => false,
        ]);
    }

    public function getParent()
    {
        return TextareaType::class;
    }


    public static function getRenderType($value)
    {
        return $value. '<hr>';
    }
}

Edit the rendering as you wish using the getRenderType method.

Commands

Export database model (no values) in a file ("/pages/model.yaml")

php bin/console artgris:page:export

/pages/model.yaml extract:

page-2:
    route: 'App\Controller\Main\MainController::index'
    name: 'page 2'
    blocks:
        blok-10:
            type: Artgris\Bundle\PageBundle\Form\Type\ArtgrisTextType
            name: 'blok 10'
            translatable: false

Import model ("/pages/model.yaml") in database

php bin/console artgris:page:import

add --remove-deviants to delete the content of types that have changed (ex: text type in yaml but integer type in bd)

php bin/console artgris:page:import --remove-deviants

add --ignore-names to ignore page and bloc names that have changed

php bin/console artgris:page:import --ignore-names

Remove extra pages/blocks (in database but not in model.yaml)

php bin/console artgris:page:remove:extra

Tutorials

Cache Infos

All blocks of the current page or not linked to a page are cached (and present in the debug bar) after calling one of these twig functions:

  • bloks()
  • blok('block-linked-to-the-current-page') => via route selector in page configuration
  • blok('block-linked-to-any-page') => route selector left empty

content added to the cache after the first call:

  • blok('block-of-another-page')

not in cache, required new db call after each call:

  • page('page-tag')
  • regex_array_blok('regex-expression')
  • regex_blok('regex-expression')

pagebundle's People

Contributors

artgris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pagebundle's Issues

Installation failed

Hi, I just made a clean installation of symfony 4, then EasyAdminBundle and finally PageBundle.
When executing the command: php bin/console doctrine: schema: update --force, I get the following error:

No identifier / primary key specified for Entity "Artgris \ Bundle \ PageBundle \ Entity \ ArtgrisBlockTranslation". Every Entity must have an identifier / primary key.

Any idea what could it be?

Configuration doesn't return routes

After i run
php bin/console doctrine:schema:update --force

I have this error: Your artgris_page.controllers configuration doesn't return routes

Tnx for help

Add slug on array key with {{ page() }}

I want to use a block page in any page of my website but if i made a dump of {{ dump(page('homepage')) }} and i have an array with keys equal 0,1,2,3 and the value.

I have for example a field slug facebook with value but in my array I don't know which one it is because they are numbers.

I would use this twig function like this : {{ page('homepage')['facebook'] }}

It's possible to make a pull request for change this in BlockExtension ?

  public function getPage(string $page)
  {
      $page = $this->pageService->getPageBySlug($page);
      $value = [];
      foreach ($page->getBlocks() as $block) {
          $value[$block->getSlug()] = $this->getBlockValue($block);
      }

      return $value;
  }

Thanks bro

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.