Skip to content

Commit

Permalink
Merge pull request #1 from tienvx/init-bundle
Browse files Browse the repository at this point in the history
Init bundle
  • Loading branch information
tienvx committed Sep 30, 2021
2 parents 2789220 + f42c759 commit a72b2a2
Show file tree
Hide file tree
Showing 17 changed files with 5,047 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
coverage_clover: clover.xml
json_path: coveralls-upload.json
service_name: php-coveralls
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
* text=auto

/tests export-ignore
/.gitattributes export-ignore
/.github export-ignore
/.gitignore export-ignore
/.coveralls.yml export-ignore
/.php_cs export-ignore
/phpunit.xml.dist export-ignore
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.idea/
/nbproject/
/.vscode/
/vendor/
/composer.lock
/.phpunit.result.cache
/clover.xml
/coveralls-upload.json
19 changes: 19 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__.'/src')
->in(__DIR__.'/tests')
;

$config = new PhpCsFixer\Config();

return $config
->setRules([
'@PSR12' => true,
'@Symfony' => true,
'concat_space' => ['spacing' => 'one'],
'single_line_throw' => false,
])
->setUsingCache(false)
->setFinder($finder)
;
57 changes: 56 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
# ux-collection
# UX Collection JS

UX collection JS is a Symfony bundle providing Symfony UX integration for collection form type with the help from [Symfony Collection JS](https://github.com/ruano-a/symfonyCollectionJs) library.

## Installation

UX Collection JS requires PHP 7.4+ and Symfony 4.4+.

Install this bundle using Composer and Symfony Flex:

```sh
composer require tienvx/ux-collection-js

# Don't forget to install the JavaScript dependencies as well and compile
yarn add --dev '@symfony/stimulus-bridge@^2.0.0'
yarn install --force
yarn encore dev
```

## Usage

Use the new CollectionType class defined by this bundle:

```php
// ...
use Tienvx\Bundle\UXCollection\Form\CollectionJsType;

class TaskType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
// ...
->add('tags', CollectionJsType::class, [
'entry_type' => TextType::class,
'allow_add' => true,
'allow_remove' => true,
'allow_move_up' => true,
'allow_move_down' => true,
'prototype' => true,
])
// ...
;
}

// ...
}
```

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

## License
[MIT](LICENSE)
53 changes: 53 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"name": "tienvx/ux-collection-js",
"type": "symfony-bundle",
"description": "Symfony UX integration for collection form type",
"keywords": [
"symfony-ux",
"ux-collection-js"
],
"homepage": "https://github.com/tienvx/ux-collection-js",
"license": "MIT",
"authors": [
{
"name": "Tien",
"email": "tien.xuan.vo@gmail.com"
},
{
"name": "Community contributions",
"homepage": "https://github.com/tienvx/ux-collection-js/contributors"
}
],
"autoload": {
"psr-4": {
"Tienvx\\Bundle\\UXCollectionJs\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tienvx\\Bundle\\UXCollectionJs\\Tests\\": "tests/"
}
},
"require": {
"php": "^7.4|^8.0",
"symfony/config": "^4.4|^5.0",
"symfony/dependency-injection": "^4.4|^5.0",
"symfony/form": "^4.4|^5.0",
"symfony/http-kernel": "^4.4|^5.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"branch-alias": {
"dev-main": "1.0-dev"
},
"thanks": {
"name": "symfony/ux",
"url": "https://github.com/symfony/ux"
}
}
}
32 changes: 32 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.4/phpunit.xsd"
bootstrap="vendor/autoload.php"
executionOrder="depends,defects"
forceCoversAnnotation="true"
beStrictAboutCoversAnnotation="true"
beStrictAboutOutputDuringTests="true"
beStrictAboutTodoAnnotatedTests="true"
failOnRisky="true"
failOnWarning="true"
verbose="true">
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>

<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>

<exclude>
<directory suffix=".php">src/Resources</directory>
</exclude>

<report>
<clover outputFile="clover.xml"/>
</report>
</coverage>
</phpunit>
31 changes: 31 additions & 0 deletions src/DependencyInjection/FormCollectionExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Tienvx\Bundle\UXCollectionJs\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Tienvx\Bundle\UXCollectionJs\Form\CollectionJsType;

class FormCollectionExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*/
public function prepend(ContainerBuilder $container): void
{
}

/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container): void
{
$container
->setDefinition('form.ux_collection_js', new Definition(CollectionJsType::class))
->addTag('form.type')
->setPublic(false)
;
}
}
61 changes: 61 additions & 0 deletions src/Form/CollectionJsType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Tienvx\Bundle\UXCollectionJs\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\OptionsResolver\OptionsResolver;

class CollectionJsType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function getParent(): string
{
return CollectionType::class;
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'allow_move_up' => false,
'allow_move_down' => false,
'render_expanded' => false,
]);
}

/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options): void
{
$view->vars = array_replace($view->vars, [
'allow_move_up' => $options['allow_move_up'],
'allow_move_down' => $options['allow_move_down'],
'render_expanded' => $options['render_expanded'],
]);
}

/**
* {@inheritdoc}
*/
public function getBlockPrefix(): string
{
return 'collection_js';
}
}
4 changes: 4 additions & 0 deletions src/Resources/assets/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["@babel/env"],
"plugins": ["@babel/plugin-proposal-class-properties"]
}
1 change: 1 addition & 0 deletions src/Resources/assets/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/node_modules/
74 changes: 74 additions & 0 deletions src/Resources/assets/dist/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;

var _stimulus = require("stimulus");

var _symfonyCollectionJs = _interopRequireDefault(require("symfony-collection-js"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var _default = /*#__PURE__*/function (_Controller) {
_inherits(_default, _Controller);

var _super = _createSuper(_default);

function _default() {
_classCallCheck(this, _default);

return _super.apply(this, arguments);
}

_createClass(_default, [{
key: "connect",
value: function connect() {
(0, _symfonyCollectionJs["default"])(this.element, {
call_post_add_on_init: false,
other_btn_add: this.element.querySelectorAll('.collection-js-add-btn'),
btn_add_selector: '.collection-js-elem-add',
btn_delete_selector: '.collection-js-elem-remove',
btn_up_selector: '.collection-js-elem-up',
btn_down_selector: '.collection-js-elem-down',
prototype_name: this.prototypeNameValue
});
}
}]);

return _default;
}(_stimulus.Controller);

exports["default"] = _default;

_defineProperty(_default, "values", {
prototypeName: {
type: String,
"default": '__name__'
}
});
Loading

0 comments on commit a72b2a2

Please sign in to comment.