Coder Social home page Coder Social logo

sulu-backend-bundle's Introduction

SULU Backend Bundle

Inspired by doctrine crud generator.

A Sulu Bundle to make it easier to create a new Backend Bundle.

With this Bundle it should be possible to create a Backend Bundles without the knowledge of husky the sulu javascript framework.

Installation

composer require l91/sulu-backend-bundle

Add Bundle to AdminKernel

$bundles[] = new L91\Sulu\Bundle\BackendBundle\L91SuluBackendBundle();

Usage

As example we will create a API for an entity called Vehicle.

1. Create Entity

First create the doctrine entity with a .orm.xml.

2. Create Repository

Create a Repository for loading entities from the database. The BackendRepository have a default implementation for them:

  • findById
  • findAll
  • count

Create the functions in your repository or extend from the BackendRepository.

<?php

namespace YourBundle\Entity\Repository;

use L91\Sulu\Bundle\BackendBundle\Entity\Repository\BackendRepository;

class VehicleRepository extends BackendRepository
{
    // Add your custom repository functions here
}

Register Repository

services:
    your.repository.vehicle:
        class: YourBundle\Entity\VehicleRepository
        factory_service: doctrine.orm.entity_manager
        factory_method: getRepository
        arguments:
            - YourBundle\Entity\Vehicle

4. Generate Controller, Manager, Admin Navigation or Tab, JSBundle

You can easily generate them with following command:

app/console l91:sulu:backend:generate:crud YourBundle:Vehicle --route-format yml --service-format yml

Add --extended to have no requirements to this Bundle. This will generate a complete own Controller, Manager, ... when use the extended generation you could remove this bundle from your requirements after you generated your bundle.

Command List

You can also just generate a specific part with the following commands:

  • app/console l91:sulu:backend:generate:controller
  • app/console l91:sulu:backend:generate:manager
  • app/console l91:sulu:backend:generate:admin
  • app/console l91:sulu:backend:generate:js
  • app/console l91:sulu:backend:generate:navigation-provider

sulu-backend-bundle's People

Contributors

alexander-schranz avatar michelfalke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sulu-backend-bundle's Issues

Subentities Support

  1. One-To-One entities can have their own tab (own xml)
  2. One-To-Many/Many-To-Many will shown as list in own tab

New way to handle crud process

Read

Controller:cGet -> Repository:load <-> Serialize

List

Controller:cGet -> Controller:getFieldDescriptors

Create

Controller:post -> Manager:create <-> Mapper:bind <-> Manager:save <-> Serialize

Update

Controller:put -> Repository:load <-> Mapper:bind <-> Manager:save <-> Serialize

Delete

Controller:delete -> Manager:delete

Add dependency only to dev requirements

In the README it's suggested to add the package to the general requirements of a project. However most often, one just want's to add it as a dev-requirement.

500 error when datefield is nullable

Code should be this then

       $date = self::getValue($data, 'date');

       if ($date) {
            $date = new \DateTime($date);
        } else {
            $date = null;
        }

        $test->setDate($date);

Improve output of commands

It should be more obvious that something has to be done, e.g. add a sentence after the generation of the controller "Add the following to the admin routing of your bundle:".

Maybe you could even include instructions to generate an admin routing file if not already existent:

client_website_admin:
    type: rest
    resource: "@ClientWebsiteBundle/Resources/config/routing_admin.yml"
    prefix: /admin/api

Admin Navigation Class

a class with can be easy registered as service to add new items to the admin navigation

Improve documentation

  • I would add the dependency as require-dev instead of require composer require --dev l91/sulu-backend-bundle instead of composer require l91/sulu-backend-bundle
  • Bundle must be added to the AdminKernel
  • Explain the --extended option more detailed.

Locale in List missing

Use the RequestParametersTrait to get the required parameters. Also the JS locale should be app.sandbox.sulu.getDefaultContentLocale()

Provide a hint for setting "minimum-stability"

When executing the require command listed in the README composer errors with the message:

[InvalidArgumentException]
Could not find package l91/sulu-backend-bundle at any version for your mini
mum-stability (stable). Check the package spelling or your minimum-stability

Either create a stable version, or provide a hint that the composer property "minimu-stability" has to be set to "dev".

Error in GenerateAdminCommand

The following lines in L91\Sulu\Bundle\BackendBundle\Command\GenerateAdminCommand.php lead to errors ("Argument mode "sf" is not valid.") as addArgument() expects the second parameter to be the mode, not a shortcut.

->addArgument('service-format', 'sf', InputArgument::REQUIRED, 'Set the format of service registrations.')
->addArgument('route-format', 'rf', InputArgument::REQUIRED, 'Set the format of route registrations.')

Add new JS Structure

Remove the tabs.js and component.js. And link directly to form.js and list.js

Abstract Backend Manager

The abstract Backend Manager will have a default implementation for the get , getBy, countBy implementation based on a BackendRepository.

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.