Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Autotables Bundle Laravel Package

20steps/autotables-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require 20steps/autotables-bundle
    

    Add to config/bundles.php:

    return [
        // ...
        Twentysteps\AutoTablesBundle\TwentystepsAutoTablesBundle::class => ['all' => true],
    ];
    
  2. Basic Configuration Create a YAML config file (e.g., config/packages/twentysteps_autotables.yaml):

    twentysteps_autotables:
        default:
            theme: bootstrap3
            editable: true
    
  3. First Use Case: Auto-Generated Table for an Entity Annotate your entity (e.g., src/Entity/User.php):

    use Twentysteps\AutoTablesBundle\Annotation\AutoTable;
    use Doctrine\ORM\Mapping as ORM;
    
    /**
     * @ORM\Entity
     * @AutoTable()
     */
    class User
    {
        // ...
    }
    
  4. Render the Table in a Controller

    use Twentysteps\AutoTablesBundle\TwentystepsAutoTablesBundle;
    use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
    
    class UserController extends AbstractController
    {
        /**
         * @Route("/users", name="user_list")
         */
        public function listAction()
        {
            return $this->render('user/list.html.twig', [
                'entity' => new User(),
            ]);
        }
    }
    
  5. Display in Twig

    {{ autotable(entity) }}
    

Implementation Patterns

Workflows

  1. Standard CRUD Workflow

    • List: Use {{ autotable(entity) }} in Twig.
    • Edit: Enable editable: true in config and annotate columns:
      /**
       * @AutoTable\Column(editable=true)
       */
      private $name;
      
    • Custom Actions: Use actions in annotations:
      /**
       * @AutoTable\Action(type="delete", label="Delete")
       */
      
  2. Integration with Doctrine Repositories

    • Pass a repository to the autotable Twig function:
      {{ autotable(repository.findAll(), entity) }}
      
  3. Custom CRUD Services

    • Implement Twentysteps\AutoTablesBundle\Service\CrudServiceInterface and configure in services.yaml:
      services:
          App\Service\CustomUserCrudService:
              tags: ['twentysteps_autotables.crud_service']
      
  4. Theming and Styling

    • Override templates in templates/bundles/twentystepsautotables/.
    • Customize via YAML config:
      twentysteps_autotables:
          default:
              theme: jqueryui
              table_options:
                  paging: true
                  searching: true
      
  5. Dynamic Column Configuration

    • Use AutoTable\Column annotations for per-property control:
      /**
       * @AutoTable\Column(label="Full Name", width="200px", sortable=false)
       */
      private $fullName;
      
  6. ManyToOne Relationships

    • Auto-initialize with AutoTable\ManyToOne:
      /**
       * @AutoTable\ManyToOne(targetEntity="App\Entity\Role", property="name")
       */
      private $role;
      

Integration Tips

  1. Leverage Events

    • Listen to twentysteps_autotables.pre_build to modify table configuration dynamically:
      use Twentysteps\AutoTablesBundle\Event\PreBuildEvent;
      
      $eventDispatcher->addListener('twentysteps_autotables.pre_build', function (PreBuildEvent $event) {
          $event->getTable()->addColumn('custom_column', 'Custom Value');
      });
      
  2. Custom Validation

    • Use Symfony’s validation constraints alongside AutoTable\Column:
      /**
       * @AutoTable\Column(editable=true)
       * @Assert\NotBlank()
       */
      private $email;
      
  3. AJAX Handling

    • Configure routes for AJAX calls in routing.yaml:
      twentysteps_autotables:
          resource: "@TwentystepsAutoTablesBundle/Resources/config/routing.xml"
          prefix: /api
      
  4. Localization

    • Translate labels and messages via Symfony’s translation system:
      {{ autotable(entity, {'labels': {'name': 'app.user.name'}}) }}
      

Gotchas and Tips

Pitfalls

  1. Annotation Processing

    • Ensure doctrine/annotations is installed and cached:
      php bin/console doctrine:cache:clear-metadata
      
    • Fix: Clear cache after adding new annotations.
  2. JavaScript Conflicts

    • DataTables and jQuery-UI/Bootstrap may conflict with other JS libraries.
    • Fix: Load AutoTables JS last or use dataTablesOptions to isolate:
      twentysteps_autotables:
          default:
              dataTablesOptions:
                  ajax: { url: '/api/users' }
      
  3. Editable Fields and CSRF

    • Editable fields may fail due to missing CSRF tokens.
    • Fix: Ensure csrf_token is included in your form templates or use editable_options:
      twentysteps_autotables:
          default:
              editable_options:
                  csrf: true
      
  4. ManyToOne Auto-Initialization

    • Auto-initialization may not work if the target entity lacks a name or id property.
    • Fix: Explicitly define property in AutoTable\ManyToOne:
      /**
       * @AutoTable\ManyToOne(targetEntity="App\Entity\Role", property="title")
       */
      private $role;
      
  5. Performance with Large Datasets

    • AutoTables loads all data by default, which can be slow.
    • Fix: Use server-side processing via dataTablesOptions:
      twentysteps_autotables:
          default:
              dataTablesOptions:
                  serverSide: true
                  processing: true
      

Debugging

  1. Check Generated HTML/JS

    • Inspect the rendered table in browser dev tools to verify DataTables initialization.
  2. Enable Debug Mode

    • Set debug: true in config to log table generation:
      twentysteps_autotables:
          debug: true
      
  3. Validate Annotations

    • Use php bin/console debug:container Twentysteps\AutoTablesBundle\Annotation\AutoTable to check if annotations are processed.

Extension Points

  1. Custom Column Types

    • Extend Twentysteps\AutoTablesBundle\Column\AbstractColumn to create custom columns (e.g., for dates or JSON).
  2. Override Templates

    • Copy templates/bundles/twentystepsautotables/table.html.twig to your project and modify as needed.
  3. Add Custom Actions

    • Implement Twentysteps\AutoTablesBundle\Action\ActionInterface and register via services:
      services:
          App\Action\CustomAction:
              tags: ['twentysteps_autotables.action']
      
  4. Modify Table Configuration

    • Use the twentysteps_autotables.post_build event to alter the table after generation:
      $eventDispatcher->addListener('twentysteps_autotables.post_build', function (PostBuildEvent $event) {
          $event->getTable()->setOption('order', [[0, 'desc']]);
      });
      
  5. Integrate with Forms

    • Use AutoTable\Form\Type\AutoTableType to generate forms dynamically:
      {{ form_start(form) }}
          {{ form_widget(form) }}
      {{ form_end(form) }}
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views